Last active
March 8, 2025 19:23
-
-
Save thisismydesign/18a795f0d056a7ca3c67dd080d91597c to your computer and use it in GitHub Desktop.
The ultimate guide to Google Analytics /2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from "react"; | |
import { useLocation } from "react-router-dom"; | |
export const usePageTracking = () => { | |
const location = useLocation(); | |
useEffect(() => { | |
window.gtag("event", "page_view", { | |
page_path: location.pathname + location.search + location.hash, | |
page_search: location.search, | |
page_hash: location.hash, | |
}); | |
}, [location]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment