From 2fd40e7372f3bfcc72603cd69d314306066f30e0 Mon Sep 17 00:00:00 2001 From: Fredrik Strand Oseberg Date: Thu, 4 Sep 2025 09:35:56 +0200 Subject: [PATCH] fix: only load ga and gtm in production (#10612) CookieYes was throwing an uncaught error triggered by GA and GTM scripts. We don't want analytics to run in development anyway, so I disabled them in these environments. --- website/src/components/VideoContent.jsx | 2 +- website/src/theme/Root.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/website/src/components/VideoContent.jsx b/website/src/components/VideoContent.jsx index ef908ead83..09248e82a9 100644 --- a/website/src/components/VideoContent.jsx +++ b/website/src/components/VideoContent.jsx @@ -39,7 +39,7 @@ const LazyVideo = ({ url, title = 'YouTube video player' }) => { className={styles.thumbnailImage} src={`https://img.youtube.com/vi/${videoId}/hqdefault.jpg`} alt={`${title} thumbnail`} - fetchPriority='high' + fetchpriority='high' />
{ + // Skip Google Analytics in development + if (process.env.NODE_ENV === 'development') { + return; + } + if ( window.gtag || document.querySelector('script[src*="googletagmanager"]') @@ -33,6 +38,11 @@ export default function Root({ children }: { children: React.ReactNode }) { }; const loadGoogleTagManager = () => { + // Skip GTM in development + if (process.env.NODE_ENV === 'development') { + return; + } + if ( window.google_tag_manager || document.querySelector(