Skip to content

Commit

Permalink
Ensure ECE button load events are triggered for multiple buttons on t…
Browse files Browse the repository at this point in the history
…he same page (#9845)
  • Loading branch information
rafaelzaleski authored Nov 29, 2024
1 parent b0b67af commit e0b69be
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 32 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-9795-debounce-of-ece-load-events
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Ensure ECE button load events are triggered for multiple buttons on the same page.
41 changes: 25 additions & 16 deletions client/express-checkout/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@ export const trackExpressCheckoutButtonClick = ( paymentMethod, source ) => {
recordUserEvent( event, { source } );
};

const debouncedTrackApplePayButtonLoad = debounce( ( { source } ) => {
recordUserEvent( 'applepay_button_load', { source } );
}, 1000 );

const debouncedTrackGooglePayButtonLoad = debounce( ( { source } ) => {
recordUserEvent( 'gpay_button_load', { source } );
}, 1000 );

// Track the button load event.
export const trackExpressCheckoutButtonLoad = debounce(
( { paymentMethods, source } ) => {
const expressPaymentTypeEvents = {
googlePay: 'gpay_button_load',
applePay: 'applepay_button_load',
};

for ( const paymentMethod of paymentMethods ) {
const event = expressPaymentTypeEvents[ paymentMethod ];
if ( ! event ) continue;

recordUserEvent( event, { source } );
}
},
1000
);
export const trackExpressCheckoutButtonLoad = ( {
paymentMethods,
source,
} ) => {
const expressPaymentTypeEvents = {
googlePay: debouncedTrackGooglePayButtonLoad,
applePay: debouncedTrackApplePayButtonLoad,
};

for ( const paymentMethod of paymentMethods ) {
const debouncedTrackFunction =
expressPaymentTypeEvents[ paymentMethod ];
if ( ! debouncedTrackFunction ) continue;

debouncedTrackFunction( { source } );
}
};
41 changes: 25 additions & 16 deletions client/tokenized-express-checkout/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@ export const trackExpressCheckoutButtonClick = ( paymentMethod, source ) => {
recordUserEvent( event, { source } );
};

const debouncedTrackApplePayButtonLoad = debounce( ( { source } ) => {
recordUserEvent( 'applepay_button_load', { source } );
}, 1000 );

const debouncedTrackGooglePayButtonLoad = debounce( ( { source } ) => {
recordUserEvent( 'gpay_button_load', { source } );
}, 1000 );

// Track the button load event.
export const trackExpressCheckoutButtonLoad = debounce(
( { paymentMethods, source } ) => {
const expressPaymentTypeEvents = {
googlePay: 'gpay_button_load',
applePay: 'applepay_button_load',
};

for ( const paymentMethod of paymentMethods ) {
const event = expressPaymentTypeEvents[ paymentMethod ];
if ( ! event ) continue;

recordUserEvent( event, { source } );
}
},
1000
);
export const trackExpressCheckoutButtonLoad = ( {
paymentMethods,
source,
} ) => {
const expressPaymentTypeEvents = {
googlePay: debouncedTrackGooglePayButtonLoad,
applePay: debouncedTrackApplePayButtonLoad,
};

for ( const paymentMethod of paymentMethods ) {
const debouncedTrackFunction =
expressPaymentTypeEvents[ paymentMethod ];
if ( ! debouncedTrackFunction ) continue;

debouncedTrackFunction( { source } );
}
};

0 comments on commit e0b69be

Please sign in to comment.