From af6f22797312e5d0acae84f4fd2f8b3cd0bb7302 Mon Sep 17 00:00:00 2001 From: "elena.krasnopolskaia" Date: Thu, 30 Nov 2023 15:27:50 +0100 Subject: [PATCH 1/3] Disabled `send_page_view` to get rid of events duplication in ga4 plugin Signed-off-by: elena.krasnopolskaia --- .changeset/five-bears-share.md | 5 +++++ .../apis/implementations/AnalyticsApi/GoogleAnalytics4.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/five-bears-share.md diff --git a/.changeset/five-bears-share.md b/.changeset/five-bears-share.md new file mode 100644 index 0000000000..532d9b586b --- /dev/null +++ b/.changeset/five-bears-share.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-analytics-module-ga4': patch +--- + +Disabled `send_page_view` to get rid of events duplication diff --git a/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts b/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts index 399366b804..fb5bd261da 100644 --- a/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts +++ b/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts @@ -70,6 +70,7 @@ export class GoogleAnalytics4 implements AnalyticsApi { }, gtagOptions: { debug_mode: debug, + send_page_view: false, }, }); From e3c035b7e6358375a2b46e3e21f60effb1837c35 Mon Sep 17 00:00:00 2001 From: "elena.krasnopolskaia" Date: Wed, 6 Dec 2023 15:15:03 +0100 Subject: [PATCH 2/3] send_page_view changed to configurable Signed-off-by: elena.krasnopolskaia --- plugins/analytics-module-ga4/README.md | 1 + .../apis/implementations/AnalyticsApi/GoogleAnalytics4.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/analytics-module-ga4/README.md b/plugins/analytics-module-ga4/README.md index 93138a8235..2d8c930e30 100644 --- a/plugins/analytics-module-ga4/README.md +++ b/plugins/analytics-module-ga4/README.md @@ -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: diff --git a/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts b/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts index fb5bd261da..9abf4719c6 100644 --- a/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts +++ b/plugins/analytics-module-ga4/src/apis/implementations/AnalyticsApi/GoogleAnalytics4.ts @@ -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,7 +72,7 @@ export class GoogleAnalytics4 implements AnalyticsApi { }, gtagOptions: { debug_mode: debug, - send_page_view: false, + send_page_view: enableSendPageView, }, }); @@ -113,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; @@ -139,6 +144,7 @@ export class GoogleAnalytics4 implements AnalyticsApi { measurementId: measurementId, testMode, debug, + enableSendPageView, contentGroupBy, allowedContexts, allowedAttributes, From dbf4438ea889320098c29fe64babb707ad79f14f Mon Sep 17 00:00:00 2001 From: "elena.krasnopolskaia" Date: Mon, 11 Dec 2023 15:29:29 +0100 Subject: [PATCH 3/3] defined enableSendPageView in config schema Signed-off-by: elena.krasnopolskaia --- plugins/analytics-module-ga4/config.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/analytics-module-ga4/config.d.ts b/plugins/analytics-module-ga4/config.d.ts index 4834d75f58..0a60ee5f9e 100644 --- a/plugins/analytics-module-ga4/config.d.ts +++ b/plugins/analytics-module-ga4/config.d.ts @@ -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.