feat: auth race condition & optimize ApolloFactory & too many pageview (#602)
This commit is contained in:
@ -1,17 +1,26 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
import usePrevious from '@/utils/hooks/usePrevious';
|
||||
|
||||
import { useEventTracker } from './useEventTracker';
|
||||
|
||||
export function useTrackPageView() {
|
||||
const location = useLocation();
|
||||
const previousLocation = usePrevious(location);
|
||||
const eventTracker = useEventTracker();
|
||||
|
||||
useEffect(() => {
|
||||
eventTracker('pageview', {
|
||||
location: {
|
||||
pathname: location.pathname,
|
||||
},
|
||||
});
|
||||
}, [location, eventTracker]);
|
||||
// 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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user