Only load analytics in production

This commit is contained in:
2026-09-30 14:19:13 +03:00
parent 77cc86ddf9
commit a06a93019f
+16 -11
View File
@@ -58,6 +58,7 @@ const websiteLd = {
author: { "@type": "Person", name: site.name }, author: { "@type": "Person", name: site.name },
}; };
const isProd = process.env.NODE_ENV === "production";
const gaId = "G-9XLTKZF07C"; const gaId = "G-9XLTKZF07C";
const umamiScript = process.env.PUBLIC_UMAMI_SCRIPT_URL; const umamiScript = process.env.PUBLIC_UMAMI_SCRIPT_URL;
@@ -83,17 +84,21 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
<body> <body>
<JsonLd data={websiteLd} /> <JsonLd data={websiteLd} />
<Layout>{children}</Layout> <Layout>{children}</Layout>
<Script {isProd && (
src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`} <>
strategy="afterInteractive" <Script
/> src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}
<Script id="google-analytics" strategy="afterInteractive"> strategy="afterInteractive"
{`window.dataLayer = window.dataLayer || []; />
function gtag(){dataLayer.push(arguments);} <Script id="google-analytics" strategy="afterInteractive">
gtag('js', new Date()); {`window.dataLayer = window.dataLayer || [];
gtag('config', '${gaId}');`} function gtag(){dataLayer.push(arguments);}
</Script> gtag('js', new Date());
{umamiScript && umamiId && ( gtag('config', '${gaId}');`}
</Script>
</>
)}
{isProd && umamiScript && umamiId && (
<Script defer src={umamiScript} data-website-id={umamiId} /> <Script defer src={umamiScript} data-website-id={umamiId} />
)} )}
</body> </body>