From 05dd22d33c8ba7aea81b5fc5add6ea292a2dec4c Mon Sep 17 00:00:00 2001 From: Erwann Date: Tue, 17 Sep 2024 18:32:52 +0200 Subject: [PATCH] [Third parties] Google analytics Add debug mode (#63405) Co-authored-by: Jiachi Liu --- packages/third-parties/src/google/ga.tsx | 4 ++-- packages/third-parties/src/types/google.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/third-parties/src/google/ga.tsx b/packages/third-parties/src/google/ga.tsx index 42747bca7c470..40b00a685f3a0 100644 --- a/packages/third-parties/src/google/ga.tsx +++ b/packages/third-parties/src/google/ga.tsx @@ -14,7 +14,7 @@ declare global { let currDataLayerName: string | undefined = undefined export function GoogleAnalytics(props: GAParams) { - const { gaId, dataLayerName = 'dataLayer', nonce } = props + const { gaId, debugMode, dataLayerName = 'dataLayer', nonce } = props if (currDataLayerName === undefined) { currDataLayerName = dataLayerName @@ -43,7 +43,7 @@ export function GoogleAnalytics(props: GAParams) { function gtag(){window['${dataLayerName}'].push(arguments);} gtag('js', new Date()); - gtag('config', '${gaId}');`, + gtag('config', '${gaId}' ${debugMode ? ",{ 'debug_mode': true }" : ''});`, }} nonce={nonce} /> diff --git a/packages/third-parties/src/types/google.ts b/packages/third-parties/src/types/google.ts index 4e556164e16e1..68c10b2a463de 100644 --- a/packages/third-parties/src/types/google.ts +++ b/packages/third-parties/src/types/google.ts @@ -24,6 +24,7 @@ export type GTMParams = { export type GAParams = { gaId: string dataLayerName?: string + debugMode?: boolean nonce?: string }