Skip to content

Commit

Permalink
Refactor and simplify util and fix wrong prop.
Browse files Browse the repository at this point in the history
  • Loading branch information
zutigrm committed Dec 23, 2024
1 parent 59a2480 commit c4773b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function ConversionReportingNotificationCTAWidget( { Widget, WidgetNull } ) {
const shouldShowCalloutForLostEvents =
haveLostConversionEvents && haveLostConversionEventsAfterDismiss;

const hasUserPickedMetrics = useSelect( ( select ) =>
const userPickedMetrics = useSelect( ( select ) =>
select( CORE_USER ).getUserPickedMetrics()
);
const haveConversionEventsWithDifferentMetrics = useSelect( ( select ) =>
Expand All @@ -128,15 +128,14 @@ function ConversionReportingNotificationCTAWidget( { Widget, WidgetNull } ) {
return {
shouldShowInitialCalloutForTailoredMetrics,
shouldShowCalloutForUserPickedMetrics,
haveConversionEventsWithDifferentMetrics,
hasUserPickedMetrics,
haveLostConversionEvents,
shouldShowCalloutForNewEvents,
userPickedMetrics,
};
}, [

Check warning on line 134 in assets/js/components/KeyMetrics/ConversionReportingNotificationCTAWidget.js

View workflow job for this annotation

GitHub Actions / JS + CSS

React Hook useMemo has a missing dependency: 'shouldShowCalloutForNewEvents'. Either include it or remove the dependency array
shouldShowInitialCalloutForTailoredMetrics,
shouldShowCalloutForUserPickedMetrics,
haveConversionEventsWithDifferentMetrics,
hasUserPickedMetrics,
userPickedMetrics,
haveLostConversionEvents,
] );

Expand Down
59 changes: 17 additions & 42 deletions assets/js/components/KeyMetrics/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,42 @@ export function conversionReportingDetectedEventsTracking(
{
shouldShowInitialCalloutForTailoredMetrics,
shouldShowCalloutForUserPickedMetrics,
haveConversionEventsWithDifferentMetrics,
shouldShowCalloutForNewEvents,
userPickedMetrics,
},
viewContext,
eventName
) {
// Handle internal tracking for new events with manual KMW selection.
if (
haveConversionEventsWithDifferentMetrics &&
userPickedMetrics?.length
) {
trackEvent(
`${ viewContext }_kmw-manual-new-conversion-events-detected-notification`,
eventName,
'conversion_reporting'
);

return;
}

// Handle internal tracking for new events with tailored KMW selection.
if (
haveConversionEventsWithDifferentMetrics &&
! userPickedMetrics?.length
) {
trackEvent(
`${ viewContext }_kmw-tailored-new-conversion-events-detected-notification`,
eventName,
'conversion_reporting'
);

return;
}
let category = '';

// Handle internal tracking or the initial detection of events with tailored KMW selection.
if ( shouldShowInitialCalloutForTailoredMetrics ) {
trackEvent(
`${ viewContext }_kmw-tailored-conversion-events-detected-notification`,
eventName,
'conversion_reporting'
);

return;
category = `${ viewContext }_kmw-tailored-conversion-events-detected-notification`;
}

// Handle internal tracking or the initial detection of events with manual KMW selection.
if ( shouldShowCalloutForUserPickedMetrics ) {
trackEvent(
`${ viewContext }_kmw-manual-conversion-events-detected-notification`,
eventName,
'conversion_reporting'
);
category = `${ viewContext }_kmw-manual-conversion-events-detected-notification`;
}

// Handle internal tracking for new events with manual KMW selection.
if ( shouldShowCalloutForNewEvents && userPickedMetrics?.length ) {
category = `${ viewContext }_kmw-manual-new-conversion-events-detected-notification`;
}

// Handle internal tracking for new events with tailored KMW selection.
if ( shouldShowCalloutForNewEvents && ! userPickedMetrics?.length ) {
category = `${ viewContext }_kmw-tailored-new-conversion-events-detected-notification`;
}

trackEvent( category, eventName, 'conversion_reporting' );
}

conversionReportingDetectedEventsTracking.propTypes = {
shouldShowInitialCalloutForTailoredMetrics: propTypes.bool.isRequired,
shouldShowCalloutForUserPickedMetrics: propTypes.bool.isRequired,
haveConversionEventsWithDifferentMetrics: propTypes.bool.isRequired,
shouldShowCalloutForNewEvents: propTypes.bool.isRequired,
userPickedMetrics: propTypes.object.isRequired,
haveLostConversionEvents: propTypes.bool.isRequired,
viewContext: propTypes.string.isRequired,
eventName: propTypes.string.isRequired,
};

0 comments on commit c4773b2

Please sign in to comment.