Skip to content

Commit

Permalink
Merge pull request #10121 from google/issue/10042-fix-cancel_update_m…
Browse files Browse the repository at this point in the history
…etrics_selection-ga-event

Issue / 10042 Fix Cancel Update Metrics Selection GA Event
  • Loading branch information
tofumatt authored Jan 28, 2025
2 parents a80a060 + 76e798f commit 020c771
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions assets/js/components/KeyMetrics/ConfirmSitePurposeChangeModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import PropTypes from 'prop-types';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useCallback, useState } from '@wordpress/element';
import { useCallback, useEffect, useState } from '@wordpress/element';
import { usePrevious } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -117,21 +118,14 @@ function ConfirmSitePurposeChangeModal( {
[ USER_INPUT_CURRENTLY_EDITING_KEY ]: undefined,
} );

// Handle internal tracking.
trackEvent(
`${ viewContext }_kmw-settings-tailored-metrics-suggestions`,
'cancel_update_metrics_selection',
'conversion_reporting'
);

handleDialog();
setIsSaving( false );
}, [
handleDialog,
savedPurpose,
resetUserInputSettings,
setValues,
setUIValues,
viewContext,
] );

const userInputPurposeConversionEvents = useSelect( ( select ) => {
Expand Down Expand Up @@ -161,25 +155,38 @@ function ConfirmSitePurposeChangeModal( {
);
await saveUserInputSettings();

setIsSaving( false );

// Handle internal tracking.
trackEvent(
`${ viewContext }_kmw-settings-tailored-metrics-suggestions`,
'confirm_update_metrics_selection',
'conversion_reporting'
);

onClose();
}, [
saveUserInputSettings,
onClose,
setIsSaving,
setUserInputSetting,
userInputPurposeConversionEvents,
viewContext,
] );

const prevDialogActive = usePrevious( dialogActive );

useEffect( () => {
if ( prevDialogActive === true && dialogActive === false ) {
if ( isSaving ) {
// Handle internal tracking when confirmation CTA is clicked.
trackEvent(
`${ viewContext }_kmw-settings-tailored-metrics-suggestions`,
'confirm_update_metrics_selection',
'conversion_reporting'
);
} else {
// Handle internal tracking when keep existing metrics CTA is clicked
// or the modal is closed via other means.
trackEvent(
`${ viewContext }_kmw-settings-tailored-metrics-suggestions`,
'cancel_update_metrics_selection',
'conversion_reporting'
);
}
}
}, [ prevDialogActive, dialogActive, isSaving, viewContext ] );

return (
<Dialog
open={ dialogActive }
Expand Down

0 comments on commit 020c771

Please sign in to comment.