11/* eslint-disable @typescript-eslint/naming-convention */
2+ import Onyx from 'react-native-onyx' ;
23import Log from '@libs/Log' ;
34import CONST from '@src/CONST' ;
5+ import ONYXKEYS from '@src/ONYXKEYS' ;
46import type { GoogleTagManagerEvent } from './types' ;
57import type GoogleTagManagerModule from './types' ;
68
@@ -13,14 +15,15 @@ type WindowWithPixels = Window & {
1315 push : ( params : DataLayerPushParams ) => void ;
1416 } ;
1517 fbq ?: ( method : string , eventName : string , params ?: Record < string , unknown > , options ?: Record < string , unknown > ) => void ;
16- rdt ?: ( method : string , params : Record < string , string > ) => void ;
18+ rdt ?: ( method : string , eventType : string , params ? : Record < string , string > ) => void ;
1719 lintrk ?: ( method : string , params : Record < string , unknown > ) => void ;
1820} ;
1921
2022type DataLayerPushParams = {
2123 event : GoogleTagManagerEvent ;
2224 user_id : number ;
2325 user_data : { email : string } ;
26+ gclid ?: string ;
2427} ;
2528
2629declare const window : WindowWithPixels ;
@@ -39,12 +42,20 @@ const REDDIT_CONVERSION_IDS: Partial<Record<GoogleTagManagerEvent, string>> = {
3942 [ CONST . ANALYTICS . EVENT . PAID_ADOPTION ] : CONST . ANALYTICS . REDDIT_PAID_ADOPTION_CONVERSION_ID ,
4043} ;
4144
45+ let googleClickId : string | null | undefined ;
46+ Onyx . connectWithoutView ( {
47+ key : ONYXKEYS . NVP_GOOGLE_CLICK_ID ,
48+ callback : ( value ) => {
49+ googleClickId = value ;
50+ } ,
51+ } ) ;
52+
4253function publishEvent ( event : GoogleTagManagerEvent , accountID : number , email : string ) {
4354 if ( ! window . dataLayer ) {
4455 return ;
4556 }
4657
47- const params = { event, user_id : accountID , user_data : { email} } ;
58+ const params = { event, user_id : accountID , user_data : { email} , gclid : googleClickId ?? undefined } ;
4859
4960 // Pass a copy of params here since the dataLayer modifies the object
5061 window . dataLayer . push ( { ...params } ) ;
@@ -61,16 +72,18 @@ function publishEvent(event: GoogleTagManagerEvent, accountID: number, email: st
6172 . map ( ( w ) => w . charAt ( 0 ) . toUpperCase ( ) + w . slice ( 1 ) )
6273 . join ( '' ) ;
6374
75+ const eventID = `${ accountID } -${ event } ` ;
76+
6477 // Meta
6578 if ( typeof window . fbq === 'function' ) {
66- window . fbq ( 'trackCustom' , pixelEventName ) ;
79+ window . fbq ( 'trackCustom' , pixelEventName , undefined , { eventID } ) ;
6780 }
6881
6982 // Reddit
7083 const redditConversionId = REDDIT_CONVERSION_IDS [ event ] ;
7184 if ( typeof window . rdt === 'function' && redditConversionId ) {
72- window . rdt ( 'track' , {
73- event : redditConversionId ,
85+ window . rdt ( 'track' , redditConversionId , {
86+ conversionId : eventID ,
7487 email,
7588 } ) ;
7689 }
0 commit comments