Skip to content

Commit

Permalink
chore(analytics): add fromDialogType to NavigateDialog events (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Aug 8, 2024
1 parent 1875a80 commit f967fc4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const AnalyticsEvents = unionize(
}>(),
NavigateDialog: ofType<{
type: DialogTypesTypes;
fromDialogType?: DialogTypesTypes;
}>(),
NavigateDialogClose: ofType<{
type: DialogTypesTypes;
Expand Down
32 changes: 21 additions & 11 deletions src/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,27 @@ export const useAnalytics = () => {
DialogTypesTypes | undefined
>();

useEffect(() => {
if (activeDialog?.type) {
track(AnalyticsEvents.NavigateDialog({ type: activeDialog.type }));
}

if (previousActiveDialogType) {
track(AnalyticsEvents.NavigateDialogClose({ type: previousActiveDialogType }));
}

setPreviousActiveDialogType(activeDialog?.type);
}, [activeDialog]);
useEffect(
() => {
if (activeDialog?.type) {
track(
AnalyticsEvents.NavigateDialog({
type: activeDialog.type,
fromDialogType: previousActiveDialogType,
})
);
}

if (previousActiveDialogType) {
track(AnalyticsEvents.NavigateDialogClose({ type: previousActiveDialogType }));
}

setPreviousActiveDialogType(activeDialog?.type);
},
// This effect should only trigger on updates to the current active dialog, not previousActiveDialogType
// eslint-disable-next-line react-hooks/exhaustive-deps
[activeDialog]
);

// AnalyticsEvent.NavigateExternal
useEffect(() => {
Expand Down

0 comments on commit f967fc4

Please sign in to comment.