Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libs/GoogleTagManager/index.native.ts
Original file line number Diff line number Diff line change
@@ -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});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use snake case here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_id is the property we need to send for Google Tag Manger: https://developers.google.com/analytics/devguides/collection/ga4/user-id?client_type=gtm

Log.info('[GTM] event published', false, {event, user_id: accountID});
}

const GoogleTagManager: GoogleTagManagerModule = {
Expand Down
11 changes: 8 additions & 3 deletions src/libs/GoogleTagManager/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,7 +15,7 @@ type WindowWithDataLayer = Window & {

type DataLayerPushParams = {
event: GoogleTagManagerEvent;
accountID: number;
user_id: number;
};

declare const window: WindowWithDataLayer;
Expand All @@ -24,8 +25,12 @@ 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};

// Pass a copy of params here since the dataLayer modifies the object
window.dataLayer.push({...params});

Log.info('[GTM] event published', false, params);
}

const GoogleTagManager: GoogleTagManagerModule = {
Expand Down