Skip to content

Commit

Permalink
feat: add previous page to navigatePage [OTE-768]
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Oct 17, 2024
1 parent a692bef commit 89488b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const AnalyticsEvents = unionize(
// Navigation
NavigatePage: ofType<{
path: string;
previousPath: string;
}>(),
NavigateDialog: ofType<{
type: DialogTypesTypes;
Expand Down
12 changes: 7 additions & 5 deletions src/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import { shallowEqual } from 'react-redux';
import { useLocation } from 'react-router-dom';
Expand Down Expand Up @@ -150,14 +150,16 @@ export const useAnalytics = () => {
);
}
}, [status]);

// AnalyticsEvent.NavigatePage
const location = useLocation();

const previousPathRef = useRef(location.pathname);
useEffect(() => {
// Ignore hashchange events from <iframe>s x_x
if (location.pathname.startsWith('/'))
track(AnalyticsEvents.NavigatePage({ path: location.pathname }));
if (location.pathname.startsWith('/')) {
const previousPath = previousPathRef.current;
track(AnalyticsEvents.NavigatePage({ path: location.pathname, previousPath }));
previousPathRef.current = location.pathname;
}
}, [location]);

// AnalyticsEvent.NavigateDialog
Expand Down

0 comments on commit 89488b0

Please sign in to comment.