mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-19 07:30:54 +00:00

Co-authored-by: Harshal Sheth <harshal@acryl.io> Co-authored-by: Dexter Lee <dexter@acryl.io> Co-authored-by: Gabe Lyons <itsgabelyons@gmail.com>
19 lines
500 B
TypeScript
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]);
|
|
};
|