From af5c27cf7c4ab086791f82fecafbb968125dad6f Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Fri, 17 Jan 2025 14:37:57 -0500 Subject: [PATCH 1/2] publish event with user_id --- src/libs/GoogleTagManager/index.native.ts | 5 +++-- src/libs/GoogleTagManager/index.ts | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libs/GoogleTagManager/index.native.ts b/src/libs/GoogleTagManager/index.native.ts index 267591d6ef40..aa10ffc4fe3c 100644 --- a/src/libs/GoogleTagManager/index.native.ts +++ b/src/libs/GoogleTagManager/index.native.ts @@ -1,11 +1,12 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import analytics from '@react-native-firebase/analytics'; import Log from '@libs/Log'; import type {GoogleTagManagerEvent} from './types'; import type GoogleTagManagerModule from './types'; function publishEvent(event: GoogleTagManagerEvent, accountID: number) { - analytics().logEvent(event, {accountID}); - Log.info('[GTM] event published', false, {event, accountID}); + analytics().logEvent(event, {user_id: accountID}); + Log.info('[GTM] event published', false, {event, user_id: accountID}); } const GoogleTagManager: GoogleTagManagerModule = { diff --git a/src/libs/GoogleTagManager/index.ts b/src/libs/GoogleTagManager/index.ts index e859da8c12e9..8701d87a6496 100644 --- a/src/libs/GoogleTagManager/index.ts +++ b/src/libs/GoogleTagManager/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import Log from '@libs/Log'; import type {GoogleTagManagerEvent} from './types'; import type GoogleTagManagerModule from './types'; @@ -14,7 +15,7 @@ type WindowWithDataLayer = Window & { type DataLayerPushParams = { event: GoogleTagManagerEvent; - accountID: number; + user_id: number; }; declare const window: WindowWithDataLayer; @@ -24,8 +25,9 @@ function publishEvent(event: GoogleTagManagerEvent, accountID: number) { return; } - window.dataLayer.push({event, accountID}); - Log.info('[GTM] event published', false, {event, accountID}); + const params = {event, user_id: accountID}; + window.dataLayer.push(params); + Log.info('[GTM] event published', false, params); } const GoogleTagManager: GoogleTagManagerModule = { From 604226022c1bc70419877adff7bb50eebba25f56 Mon Sep 17 00:00:00 2001 From: Andrew Rosiclair Date: Fri, 17 Jan 2025 15:33:32 -0500 Subject: [PATCH 2/2] use a copy of params --- src/libs/GoogleTagManager/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/GoogleTagManager/index.ts b/src/libs/GoogleTagManager/index.ts index 8701d87a6496..c02fa899c9b4 100644 --- a/src/libs/GoogleTagManager/index.ts +++ b/src/libs/GoogleTagManager/index.ts @@ -26,7 +26,10 @@ function publishEvent(event: GoogleTagManagerEvent, accountID: number) { } const params = {event, user_id: accountID}; - window.dataLayer.push(params); + + // Pass a copy of params here since the dataLayer modifies the object + window.dataLayer.push({...params}); + Log.info('[GTM] event published', false, params); }