mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-20 16:10:24 +00:00
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]);
|
||
|
};
|