Update useGoogleAnalytics.js

This commit is contained in:
plebeius.eth
2023-09-23 21:15:03 +02:00
committed by GitHub
parent e518dedf38
commit 93eb4d78cf
+15 -10
View File
@@ -6,15 +6,20 @@ const GA_MEASUREMENT_ID = "G-2M2VYEFL7B";
const useGoogleAnalytics = () => {
const location = useLocation();
useEffect(() => {
if (typeof window.gtag === 'function') {
const fullPath = location.pathname + location.search + location.hash;
window.gtag('config', GA_MEASUREMENT_ID, {
'page_path': fullPath,
});
window.gtag('event', 'page_view', {'page_path': fullPath});
}
}, [location]);
useEffect(() => {
if (typeof window.gtag === 'function') {
const fullPath = location.pathname + location.search + location.hash;
window.gtag('config', GA_MEASUREMENT_ID, {
'page_path': fullPath,
});
window.gtag('event', 'page_view', {
'page_path': fullPath,
'page_location': window.location.href
});
}
}, [location]);
};
export default useGoogleAnalytics;
export default useGoogleAnalytics;pat