add: store address tour tracks (#34337)

Added tracks event for store address tour dismissal with schema:

'wcadmin_settings_store_address_tour_dismiss'
{
  source: 'done-btn' | 'close-btn',
  fields_filled: {
    address_1: boolean;
    address_2: boolean;
    city: boolean;
    postcode: boolean;
  }
}
This commit is contained in:
RJ 2022-08-18 10:10:22 +08:00 committed by GitHub
parent 26a3d0d3c1
commit e3d0558447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import { TourKit, TourKitTypes } from '@woocommerce/components';
import { __ } from '@wordpress/i18n';
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { recordEvent } from '@woocommerce/tracks';
/**
* Internal dependencies
@ -38,6 +39,11 @@ const useShowStoreLocationTour = () => {
};
};
const isFieldFilled = ( fieldSelector: string ) => {
const field = document.querySelector< HTMLInputElement >( fieldSelector );
return !! field && field.value.length > 0;
};
const StoreAddressTourOverlay = () => {
const { isLoading, show } = useShowStoreLocationTour();
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
@ -77,7 +83,19 @@ const StoreAddressTourOverlay = () => {
},
},
},
closeHandler: () => {
closeHandler: ( _steps, _currentStepIndex, source ) => {
const fields_filled = {
address_1: isFieldFilled( 'input#woocommerce_store_address' ),
address_2: isFieldFilled( 'input#woocommerce_store_address_2' ),
city: isFieldFilled( 'input#woocommerce_store_city' ),
postcode: isFieldFilled( 'input#woocommerce_store_postcode' ),
};
recordEvent( 'settings_store_address_tour_dismiss', {
source, // 'close-btn' | 'done-btn'
fields_filled,
} );
updateOptions( {
[ REVIEWED_STORE_LOCATION_SETTINGS_OPTION ]: 'yes',
} );