Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 4147794f authored by Léon Amirkhanian's avatar Léon Amirkhanian
Browse files

added Google Analytics

parent efd61c86
No related branches found
No related tags found
No related merge requests found
Pipeline #53477 passed
......@@ -30,4 +30,4 @@ pages:
paths:
- public
only:
- main
- main
\ No newline at end of file
......@@ -5,9 +5,17 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LENIX.IO</title>
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-TH8TBQFKHJ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
\ No newline at end of file
</html>
import { useEffect } from 'react';
declare global {
interface Window {
gtag: (
type: string,
action: string,
params?: { [key: string]: any }
) => void;
}
}
export const useGoogleAnalytics = () => {
const trackPageView = (url: string) => {
if (typeof window.gtag !== 'undefined') {
window.gtag('config', 'G-XXXXXXXXXX', {
page_path: url,
});
}
};
const trackEvent = (category: string, action: string, label?: string, value?: number) => {
if (typeof window.gtag !== 'undefined') {
window.gtag('event', action, {
event_category: category,
event_label: label,
value: value,
});
}
};
useEffect(() => {
// Track initial page view
trackPageView(window.location.pathname);
// Track when hash changes (for SPA navigation)
const handleHashChange = () => {
trackPageView(window.location.pathname + window.location.hash);
};
window.addEventListener('hashchange', handleHashChange);
return () => {
window.removeEventListener('hashchange', handleHashChange);
};
}, []);
return { trackEvent };
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment