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

Add new Tracks around WooPay Save My Info checkbox #7973

Merged
merged 5 commits into from
Jan 12, 2024
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
4 changes: 4 additions & 0 deletions changelog/add-save-my-info-tracks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Add new Tracks events to WooPay Save My Info checkbox
3 changes: 1 addition & 2 deletions client/checkout/woopay/email-input-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ export const handleWooPayEmailInput = async (
} else if ( data.code !== 'rest_invalid_param' ) {
wcpayTracks.recordUserEvent(
wcpayTracks.events.WOOPAY_OFFERED,
[],
true
[]
);
}
} )
Expand Down
18 changes: 18 additions & 0 deletions client/components/woopay/save-user/checkout-page-save-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
[ isSaveDetailsChecked, phoneNumber, viewportWidth, viewportHeight ]
);

const handleCountryDropdownClick = useCallback( () => {
wcpayTracks.recordUserEvent(
wcpayTracks.events.WOOPAY_SAVE_MY_INFO_COUNTRY_CLICK
);
}, [] );

const handleCheckboxClick = ( e ) => {
const isChecked = e.target.checked;
if ( isChecked ) {
Expand All @@ -112,6 +118,15 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
);
};

useEffect( () => {
// Record Tracks event when the mobile number is entered.
if ( isPhoneValid ) {
wcpayTracks.recordUserEvent(
wcpayTracks.events.WOOPAY_SAVE_MY_INFO_MOBILE_ENTER
);
}
}, [ isPhoneValid ] );

useEffect( () => {
// Record Tracks event when user clicks on the info icon for the first time.
if ( isInfoFlyoutVisible && ! hasShownInfoFlyout ) {
Expand Down Expand Up @@ -305,6 +320,9 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
value={ phoneNumber }
onValueChange={ setPhoneNumber }
onValidationChange={ onPhoneValidationChange }
onCountryDropdownClick={
handleCountryDropdownClick
}
inputProps={ {
name:
'woopay_user_phone_field[no-country-code]',
Expand Down
22 changes: 21 additions & 1 deletion client/settings/phone-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface PhoneNumberInputProps {
value: string;
onValidationChange: ( isValid: boolean ) => void;
onValueChange: ( value: string ) => void;
onCountryDropdownClick?: () => void;
inputProps: {
label: string;
ariaLabel: string;
Expand All @@ -27,6 +28,7 @@ const PhoneNumberInput = ( {
onValueChange,
value,
onValidationChange = ( validation ) => validation,
onCountryDropdownClick,
inputProps = {
label: '',
ariaLabel: '',
Expand Down Expand Up @@ -101,6 +103,13 @@ const PhoneNumberInput = ( {
setInputInstance( iti );

currentRef.addEventListener( 'countrychange', handleCountryChange );

const countryList = currentRef
.closest( '.iti' )
?.querySelector( '.iti__flag-container' );
if ( countryList && onCountryDropdownClick ) {
countryList.addEventListener( 'click', onCountryDropdownClick );
}
}

return () => {
Expand All @@ -113,9 +122,20 @@ const PhoneNumberInput = ( {
handleCountryChange
);
}

// Cleanup for country dropdown click event
const countryList = currentRef
?.closest( '.iti' )
?.querySelector( '.iti__flag-container' );
if ( countryList && onCountryDropdownClick ) {
countryList.removeEventListener(
'click',
onCountryDropdownClick
);
}
}
};
}, [ onValueChange, onValidationChange ] );
}, [ onValueChange, onValidationChange, onCountryDropdownClick ] );

useEffect( () => {
if ( inputInstance && inputRef.current ) {
Expand Down
6 changes: 5 additions & 1 deletion client/tracks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,16 @@ const events = {
'wcpay_subscriptions_account_not_connected_product_modal_dismiss',
TRANSACTIONS_DOWNLOAD_CSV_CLICK: 'wcpay_transactions_download_csv_click',
WOOPAY_EMAIL_CHECK: 'checkout_email_address_woopay_check',
WOOPAY_OFFERED: 'woopay_offered',
WOOPAY_OFFERED: 'checkout_woopay_save_my_info_offered',
WOOPAY_AUTO_REDIRECT: 'checkout_woopay_auto_redirect',
WOOPAY_SKIPPED: 'woopay_skipped',
WOOPAY_BUTTON_LOAD: 'woopay_button_load',
WOOPAY_BUTTON_CLICK: 'woopay_button_click',
WOOPAY_SAVE_MY_INFO_COUNTRY_CLICK:
'checkout_woopay_save_my_info_country_click',
WOOPAY_SAVE_MY_INFO_CLICK: 'checkout_save_my_info_click',
WOOPAY_SAVE_MY_INFO_MOBILE_ENTER:
'checkout_woopay_save_my_info_mobile_enter',
WOOPAY_SAVE_MY_INFO_TOS_CLICK: 'checkout_save_my_info_tos_click',
WOOPAY_SAVE_MY_INFO_PRIVACY_CLICK:
'checkout_save_my_info_privacy_policy_click',
Expand Down
Loading