Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Publish user_id with GTM events #55434

Merged
merged 2 commits into from
Jan 21, 2025
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
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
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
Loading