import { useEffect } from "react"; | |
import { useLocation } from "react-router-dom"; | |
export function usePageTracking() { | |
const location = useLocation(); | |
useEffect(() => { | |
// Send pageview to Google Analytics | |
if (window.gtag) { | |
console.debug('sending page view event', location.pathname, location.search, location.hash); | |
window.gtag("event", "page_view", { | |
page_path: location.pathname + location.search + location.hash, | |
page_location: window.location.href, | |
page_title: document.title | |
}); | |
} | |
}, [location]); | |
} | |