Files
twenty/front/src/modules/analytics/hooks/useTrackPageView.ts
Charles Bochet 6ced8434bd Uniformize folder structure (#693)
* Uniformize folder structure

* Fix icons

* Fix icons

* Fix tests

* Fix tests
2023-07-16 14:29:28 -07:00

27 lines
730 B
TypeScript

import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import usePrevious from '~/hooks/usePrevious';
import { useEventTracker } from './useEventTracker';
export function useTrackPageView() {
const location = useLocation();
const previousLocation = usePrevious(location);
const eventTracker = useEventTracker();
useEffect(() => {
// Avoid lot of pageview events enven if the location is the same
if (
!previousLocation?.pathname ||
previousLocation?.pathname !== location.pathname
) {
eventTracker('pageview', {
location: {
pathname: location.pathname,
},
});
}
}, [location, eventTracker, previousLocation?.pathname]);
}