Skip to content

Commit 3d50dfe

Browse files
committed
fix: conditionally render analytics scripts based on environment variables
1 parent 64aa1d8 commit 3d50dfe

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/app/layout.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ export default function Layout({ children }: { children: ReactNode }) {
2222
return (
2323
<html lang="en" className={inter.className} suppressHydrationWarning>
2424
<body className="flex flex-col min-h-screen">
25-
<Script
26-
defer
27-
data-domain={process.env.NEXT_PUBLIC_ANALYTICS_DOMAIN}
28-
src={process.env.NEXT_PUBLIC_ANALYTICS_URL}
29-
id="plausible-script"
30-
/>
31-
<Script
32-
dangerouslySetInnerHTML={{
33-
__html: `window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }`,
34-
}}
35-
id="plausible-window"
36-
/>
25+
{process.env.NEXT_PUBLIC_ANALYTICS_DOMAIN && process.env.NEXT_PUBLIC_ANALYTICS_URL && (
26+
<>
27+
<Script
28+
defer
29+
data-domain={process.env.NEXT_PUBLIC_ANALYTICS_DOMAIN}
30+
src={process.env.NEXT_PUBLIC_ANALYTICS_URL}
31+
id="plausible-script"
32+
/>
33+
<Script
34+
dangerouslySetInnerHTML={{
35+
__html: `window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }`,
36+
}}
37+
id="plausible-window"
38+
/>
39+
</>
40+
)}
3741
<RootProvider>{children}</RootProvider>
3842
</body>
3943
</html>

0 commit comments

Comments
 (0)