Skip to content

Commit

Permalink
Make notification GA tracking prop stricter.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfmohit committed Oct 10, 2024
1 parent ee980e2 commit 82ef299
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import useNotificationEvents from '../../hooks/useNotificationEvents';
export default function Notification( {
id,
className,
gaTrackingEventArgs = [],
gaTrackingEventArgs,
children,
} ) {
const ref = useRef();
Expand All @@ -46,7 +46,10 @@ export default function Notification( {
// Track view once.
useEffect( () => {
if ( ! isViewedOnce && viewed ) {
trackEvents.view( ...gaTrackingEventArgs );
trackEvents.view(
gaTrackingEventArgs?.label,
gaTrackingEventArgs?.value
);
setIsViewedOnce( true );
}
}, [ viewed, trackEvents, isViewedOnce, gaTrackingEventArgs ] );
Expand All @@ -70,6 +73,9 @@ export default function Notification( {
Notification.propTypes = {
id: PropTypes.string,
className: PropTypes.string,
gaTrackingEventArgs: PropTypes.array,
gaTrackingEventArgs: PropTypes.shape( {
label: PropTypes.string,
value: PropTypes.string,
} ),
children: PropTypes.node,
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ export default function CTALinkSubtle( {
ctaLabel,
onCTAClick,
isCTALinkExternal = false,
gaTrackingEventArgs = [],
gaTrackingEventArgs,
} ) {
const trackEvents = useNotificationEvents( id );

const handleCTAClick = async ( event ) => {
await onCTAClick?.( event );

trackEvents.confirm( ...gaTrackingEventArgs );
trackEvents.confirm(
gaTrackingEventArgs?.label,
gaTrackingEventArgs?.value
);
};

return (
Expand All @@ -66,5 +69,8 @@ CTALinkSubtle.propTypes = {
ctaLabel: PropTypes.string,
onCTAClick: PropTypes.func,
isCTALinkExternal: PropTypes.bool,
gaTrackingEventArgs: PropTypes.array,
gaTrackingEventArgs: PropTypes.shape( {
label: PropTypes.string,
value: PropTypes.string,
} ),
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ export default function Dismiss( {
dismissExpires = 0,
disabled,
onDismiss = () => {},
gaTrackingEventArgs = [],
gaTrackingEventArgs,
} ) {
const trackEvents = useNotificationEvents( id );

const { dismissNotification } = useDispatch( CORE_NOTIFICATIONS );

const handleDismiss = async ( event ) => {
await onDismiss?.( event );
trackEvents.dismiss( ...gaTrackingEventArgs );
trackEvents.dismiss(
gaTrackingEventArgs?.label,
gaTrackingEventArgs?.value
);
dismissNotification( id, { expiresInSeconds: dismissExpires } );
};

Expand All @@ -69,5 +72,8 @@ Dismiss.propTypes = {
dismissExpires: PropTypes.number,
disabled: PropTypes.bool,
onDismiss: PropTypes.func,
gaTrackingEventArgs: PropTypes.array,
gaTrackingEventArgs: PropTypes.shape( {
label: PropTypes.string,
value: PropTypes.string,
} ),
};
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ export default function RRMSetupSuccessSubtleNotification( {
// Sync publication data when user re-focuses window.
useRefocus( syncPublication, 15000 );

const gaTrackingProps = {
gaTrackingEventArgs: { label: publicationOnboardingState },
};

if ( publicationOnboardingState === ONBOARDING_COMPLETE ) {
return (
<Notification
gaTrackingEventArgs={ [ publicationOnboardingState ] }
>
<Notification { ...gaTrackingProps }>
<SubtleNotification
title={ __(
'Your Reader Revenue Manager account was successfully set up!',
Expand All @@ -139,9 +141,7 @@ export default function RRMSetupSuccessSubtleNotification( {
primary={ false }
dismissLabel={ __( 'Got it', 'google-site-kit' ) }
onDismiss={ dismissNotice }
gaTrackingEventArgs={ [
publicationOnboardingState,
] }
{ ...gaTrackingProps }
/>
}
additionalCTA={
Expand All @@ -154,9 +154,7 @@ export default function RRMSetupSuccessSubtleNotification( {
ctaLink={ serviceURL }
onCTAClick={ onCTAClick }
isCTALinkExternal
gaTrackingEventArgs={ [
publicationOnboardingState,
] }
{ ...gaTrackingProps }
/>
}
/>
Expand All @@ -166,9 +164,7 @@ export default function RRMSetupSuccessSubtleNotification( {

if ( publicationOnboardingState === PENDING_VERIFICATION ) {
return (
<Notification
gaTrackingEventArgs={ [ publicationOnboardingState ] }
>
<Notification { ...gaTrackingProps }>
<SubtleNotification
title={ __(
'Your Reader Revenue Manager account was successfully set up!',
Expand All @@ -184,9 +180,7 @@ export default function RRMSetupSuccessSubtleNotification( {
primary={ false }
dismissLabel={ __( 'Got it', 'google-site-kit' ) }
onDismiss={ dismissNotice }
gaTrackingEventArgs={ [
publicationOnboardingState,
] }
{ ...gaTrackingProps }
/>
}
additionalCTA={
Expand All @@ -199,9 +193,7 @@ export default function RRMSetupSuccessSubtleNotification( {
ctaLink={ serviceURL }
onCTAClick={ onCTAClick }
isCTALinkExternal
gaTrackingEventArgs={ [
publicationOnboardingState,
] }
{ ...gaTrackingProps }
/>
}
/>
Expand All @@ -211,9 +203,7 @@ export default function RRMSetupSuccessSubtleNotification( {

if ( publicationOnboardingState === ONBOARDING_ACTION_REQUIRED ) {
return (
<Notification
gaTrackingEventArgs={ [ publicationOnboardingState ] }
>
<Notification { ...gaTrackingProps }>
<SubtleNotification
title={ __(
'Your Reader Revenue Manager account was successfully set up, but your publication still requires further setup in Reader Revenue Manager.',
Expand All @@ -225,9 +215,7 @@ export default function RRMSetupSuccessSubtleNotification( {
primary={ false }
dismissLabel={ __( 'Got it', 'google-site-kit' ) }
onDismiss={ dismissNotice }
gaTrackingEventArgs={ [
publicationOnboardingState,
] }
{ ...gaTrackingProps }
/>
}
additionalCTA={
Expand All @@ -240,9 +228,7 @@ export default function RRMSetupSuccessSubtleNotification( {
ctaLink={ serviceURL }
onCTAClick={ onCTAClick }
isCTALinkExternal
gaTrackingEventArgs={ [
publicationOnboardingState,
] }
{ ...gaTrackingProps }
/>
}
type="warning"
Expand Down

0 comments on commit 82ef299

Please sign in to comment.