mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-16 19:38:26 +00:00
20 lines
514 B
TypeScript
20 lines
514 B
TypeScript
import { useEffect } from 'react';
|
|
import { useLocation } from 'react-router-dom';
|
|
|
|
import analytics from '@app/analytics/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]);
|
|
};
|