Merge pull request #21655 from ekrasnopolskaia/fixed-duplicating-ga4

Disabled `send_page_view` to get rid of events duplication in ga4 plugin
This commit is contained in:
Fredrik Adelöw
2023-12-15 20:45:29 +01:00
committed by GitHub
4 changed files with 21 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-analytics-module-ga4': patch
---
Disabled `send_page_view` to get rid of events duplication
+1
View File
@@ -87,6 +87,7 @@ Additional dimensional data can be captured using custom dimensions, like this:
attribute names will be prefixed by `a_`.
5. `allowedContexts` and `allowedAttributes` are optional, if not provided, no additional context and attributes will be sent.
6. if `allowedContexts` or `allowedAttributes` is set to '\*', all context and attributes will be sent.
7. `enableSendPageView` is used to send default events and is disabled by default.
```yaml
app:
+8
View File
@@ -54,6 +54,14 @@ export interface Config {
*/
debug?: boolean;
/**
* Whether to send default send_page_view event.
* Defaults to false.
*
* @visibility frontend
*/
enableSendPageView?: boolean;
/**
* Prevents events from actually being sent when set to true. Defaults
* to false.
@@ -47,6 +47,7 @@ export class GoogleAnalytics4 implements AnalyticsApi {
measurementId: string;
testMode: boolean;
debug: boolean;
enableSendPageView: boolean;
contentGroupBy?: string;
allowedContexts?: string[];
allowedAttributes?: string[];
@@ -58,6 +59,7 @@ export class GoogleAnalytics4 implements AnalyticsApi {
userIdTransform = 'sha-256',
testMode,
debug,
enableSendPageView,
contentGroupBy,
allowedContexts,
allowedAttributes,
@@ -70,6 +72,7 @@ export class GoogleAnalytics4 implements AnalyticsApi {
},
gtagOptions: {
debug_mode: debug,
send_page_view: enableSendPageView,
},
});
@@ -112,6 +115,9 @@ export class GoogleAnalytics4 implements AnalyticsApi {
const identity =
config.getOptionalString('app.analytics.ga4.identity') || 'disabled';
const debug = config.getOptionalBoolean('app.analytics.ga4.debug') ?? false;
const enableSendPageView =
config.getOptionalBoolean('app.analytics.ga4.enableSendPageView') ??
false;
const testMode =
config.getOptionalBoolean('app.analytics.ga4.testMode') ?? false;
@@ -138,6 +144,7 @@ export class GoogleAnalytics4 implements AnalyticsApi {
measurementId: measurementId,
testMode,
debug,
enableSendPageView,
contentGroupBy,
allowedContexts,
allowedAttributes,