datahub/datahub-web-react/src/app/analytics/useTrackPageView.ts
John Joyce 29832e5385
feat(Product Analytics): Introducing In-App Analytics Beta (#2499)
Co-authored-by: Harshal Sheth <harshal@acryl.io>
Co-authored-by: Dexter Lee <dexter@acryl.io>
Co-authored-by: Gabe Lyons <itsgabelyons@gmail.com>
2021-05-11 15:41:42 -07:00

19 lines
500 B
TypeScript

import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import analytics from './analytics';
// Note: we explicitly keep this outside of React state management.
let prevPathname: string = document.referrer;
/**
* Hook used for logging page view events.
*/
export const useTrackPageView = () => {
const location = useLocation();
return useEffect(() => {
analytics.page({ prevPathname });
prevPathname = location.pathname;
}, [location]);
};