From 2d99ae0394d9433ff2478a8ffe94d5fb9d36bbd4 Mon Sep 17 00:00:00 2001 From: Guilherme Biff Zarelli Date: Sun, 25 Oct 2026 14:41:50 -0300 Subject: [PATCH] fix(analytics): keep initial pageviews enabled --- src/app/components/GoogleAnalytics.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/components/GoogleAnalytics.tsx b/src/app/components/GoogleAnalytics.tsx index ed899f5..ca36b5f 100644 --- a/src/app/components/GoogleAnalytics.tsx +++ b/src/app/components/GoogleAnalytics.tsx @@ -16,12 +16,19 @@ declare global { export default function GoogleAnalytics() { const pathname = usePathname(); const lastTrackedPath = useRef(null); + const hasTrackedInitialPage = useRef(false); const pendingPageViews = useRef>([]); const [gtagReady, setGtagReady] = useState(false); useEffect(() => { if (!pathname) return; + if (!hasTrackedInitialPage.current) { + hasTrackedInitialPage.current = true; + lastTrackedPath.current = pathname; + return; + } + if (lastTrackedPath.current !== pathname) { lastTrackedPath.current = pathname; pendingPageViews.current.push({ pathname, pageTitle: document.title }); @@ -50,7 +57,7 @@ export default function GoogleAnalytics() { {`window.dataLayer = window.dataLayer || []; window.gtag = window.gtag || function(...args) { window.dataLayer.push(args); }; window.gtag('js', new Date()); - window.gtag('config', '${measurementId}', { send_page_view: false });`} + window.gtag('config', '${measurementId}');`} );