@@ -18,7 +18,7 @@ declare global {
1818}
1919
2020export class EventClient {
21- private tagCalled = false ;
21+ private readonly tagCalled : boolean = false ;
2222
2323 constructor ( private options : ClientOptions ) {
2424 if ( this . options . autoPageView === undefined ) {
@@ -32,12 +32,6 @@ export class EventClient {
3232 this . pushDataLayer ( { event : 'Init' , ...options } ) ;
3333 }
3434
35- public setUId ( uId : number ) : void {
36- this . options . uId = uId ;
37-
38- this . pushDataLayer ( this . options ) ;
39- }
40-
4135 private get dataLayer ( ) {
4236 if ( ! this . tagCalled ) {
4337 window . dataLayer = window . dataLayer || [ ] ;
@@ -46,11 +40,10 @@ export class EventClient {
4640 return window . dataLayer ;
4741 }
4842
49- private pushDataLayer ( data : Record < string , any > ) : void {
50- if ( ! this . tagCalled ) {
51- console . warn ( '[@ridi/ridi-event-client] GTM is not initialized.' ) ;
52- }
53- this . dataLayer . push ( data ) ;
43+ public setUId ( uId : number ) : void {
44+ this . options . uId = uId ;
45+
46+ this . pushDataLayer ( { event : 'UIdChanged' , ...this . options } ) ;
5447 }
5548
5649 public sendEvent (
@@ -118,12 +111,8 @@ export class EventClient {
118111 this . sendEvent ( 'BeginCheckout' , { items } , ts ) ;
119112 }
120113
121- public sendAddPaymentInfo (
122- paymentType : string ,
123- purchaseInfo : PurchaseInfo ,
124- ts ?: Date ,
125- ) : void {
126- this . sendEvent ( 'AddPaymentInfo' , { paymentType, ...purchaseInfo } , ts ) ;
114+ public sendAddPaymentInfo ( purchaseInfo : PurchaseInfo , ts ?: Date ) : void {
115+ this . sendEvent ( 'AddPaymentInfo' , { ...purchaseInfo } , ts ) ;
127116 }
128117
129118 public sendEnrollPreference ( items : Item [ ] , ts ?: Date ) : void {
@@ -157,4 +146,11 @@ export class EventClient {
157146 ) : void {
158147 this . sendEvent ( 'Purchase' , { transactionId, ...purchaseInfo } , ts ) ;
159148 }
149+
150+ private pushDataLayer ( data : Record < string , any > ) : void {
151+ if ( ! this . tagCalled ) {
152+ console . warn ( '[@ridi/ridi-event-client] GTM is not initialized.' ) ;
153+ }
154+ this . dataLayer . push ( data ) ;
155+ }
160156}
0 commit comments