Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add previous page to navigatePage [OTE-768] #1170

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be location.pathname ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah that makes sense. 🤔 can fix later though so we don't have to re-approve this PR

// AnalyticsEvent.NavigateDialog
Expand Down
Loading