11/* eslint-disable @typescript-eslint/naming-convention */
2- import Onyx from 'react-native-onyx' ;
32import Log from '@libs/Log' ;
43import CONST from '@src/CONST' ;
5- import ONYXKEYS from '@src/ONYXKEYS' ;
64import type { GoogleTagManagerEvent } from './types' ;
75import type GoogleTagManagerModule from './types' ;
86
@@ -23,51 +21,31 @@ type DataLayerPushParams = {
2321 event : GoogleTagManagerEvent ;
2422 user_id : number ;
2523 user_data : { email : string } ;
26- gclid ?: string ;
2724} ;
2825
2926declare const window : WindowWithPixels ;
3027
31- const PIXEL_EVENTS = new Set < GoogleTagManagerEvent > ( [ CONST . ANALYTICS . EVENT . SIGN_UP , CONST . ANALYTICS . EVENT . WORKSPACE_CREATED , CONST . ANALYTICS . EVENT . PAID_ADOPTION ] ) ;
32-
33- const LINKEDIN_CONVERSION_IDS : Partial < Record < GoogleTagManagerEvent , number > > = {
34- [ CONST . ANALYTICS . EVENT . SIGN_UP ] : CONST . ANALYTICS . LINKEDIN_SIGN_UP_CONVERSION_ID ,
35- [ CONST . ANALYTICS . EVENT . WORKSPACE_CREATED ] : CONST . ANALYTICS . LINKEDIN_WORKSPACE_CREATED_CONVERSION_ID ,
36- [ CONST . ANALYTICS . EVENT . PAID_ADOPTION ] : CONST . ANALYTICS . LINKEDIN_PAID_ADOPTION_CONVERSION_ID ,
37- } ;
38-
39- const REDDIT_CONVERSION_IDS : Partial < Record < GoogleTagManagerEvent , string > > = {
40- [ CONST . ANALYTICS . EVENT . SIGN_UP ] : CONST . ANALYTICS . REDDIT_SIGN_UP_CONVERSION_ID ,
41- [ CONST . ANALYTICS . EVENT . WORKSPACE_CREATED ] : CONST . ANALYTICS . REDDIT_WORKSPACE_CREATED_CONVERSION_ID ,
42- [ CONST . ANALYTICS . EVENT . PAID_ADOPTION ] : CONST . ANALYTICS . REDDIT_PAID_ADOPTION_CONVERSION_ID ,
43- } ;
44-
45- let googleClickId : string | null | undefined ;
46- Onyx . connectWithoutView ( {
47- key : ONYXKEYS . NVP_GOOGLE_CLICK_ID ,
48- callback : ( value ) => {
49- googleClickId = value ;
50- } ,
51- } ) ;
28+ const PIXEL_EVENTS = [ CONST . ANALYTICS . EVENT . SIGN_UP , CONST . ANALYTICS . EVENT . WORKSPACE_CREATED , CONST . ANALYTICS . EVENT . PAID_ADOPTION ] as const ;
5229
5330function publishEvent ( event : GoogleTagManagerEvent , accountID : number , email : string ) {
5431 if ( ! window . dataLayer ) {
5532 return ;
5633 }
5734
58- const params = { event, user_id : accountID , user_data : { email} , gclid : googleClickId ?? undefined } ;
35+ const params = { event, user_id : accountID , user_data : { email} } ;
5936
6037 // Pass a copy of params here since the dataLayer modifies the object
6138 window . dataLayer . push ( { ...params } ) ;
6239
6340 Log . info ( '[GTM] event published' , false , params ) ;
6441
65- if ( ! PIXEL_EVENTS . has ( event ) ) {
42+ const pixelEvent = PIXEL_EVENTS . find ( ( e ) => e . NAME === event ) ;
43+ if ( ! pixelEvent ) {
6644 return ;
6745 }
6846
6947 // Events in Meta & Reddit are currently being set in CamelCase from OldDot
70- const pixelEventName = ( event as string )
48+ const pixelEventName = event
7149 . split ( '_' )
7250 . map ( ( w ) => w . charAt ( 0 ) . toUpperCase ( ) + w . slice ( 1 ) )
7351 . join ( '' ) ;
@@ -80,19 +58,17 @@ function publishEvent(event: GoogleTagManagerEvent, accountID: number, email: st
8058 }
8159
8260 // Reddit
83- const redditConversionID = REDDIT_CONVERSION_IDS [ event ] ;
84- if ( typeof window . rdt === 'function' && redditConversionID ) {
85- window . rdt ( 'track' , redditConversionID , {
61+ if ( typeof window . rdt === 'function' ) {
62+ window . rdt ( 'track' , pixelEvent . REDDIT , {
8663 conversionId : eventID ,
8764 email,
8865 } ) ;
8966 }
9067
9168 // LinkedIn (uses numeric conversion IDs instead of named events)
92- const linkedInConversionID = LINKEDIN_CONVERSION_IDS [ event ] ;
93- if ( typeof window . lintrk === 'function' && linkedInConversionID ) {
69+ if ( typeof window . lintrk === 'function' ) {
9470 window . lintrk ( 'setUserData' , { email} ) ;
95- window . lintrk ( 'track' , { conversion_id : linkedInConversionID } ) ;
71+ window . lintrk ( 'track' , { conversion_id : pixelEvent . LINKEDIN , event_id : eventID } ) ;
9672 }
9773}
9874
0 commit comments