Skip to content

Commit 6b6a470

Browse files
committed
fix: render CookieYes script as raw tag in <head> for crawler detection
Next.js Script with beforeInteractive renders through RSC payload, not as a literal <script> tag. CookieYes verification requires the tag to be visible in raw HTML source.
1 parent b06cd06 commit 6b6a470

2 files changed

Lines changed: 22 additions & 27 deletions

File tree

src/app/layout.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ export default function RootLayout({ children }: { children: React.ReactNode })
4343

4444
return (
4545
<html lang="en" suppressHydrationWarning>
46-
<head />
46+
<head>
47+
{process.env.NEXT_PUBLIC_COOKIEYES_ID && process.env.NEXT_PUBLIC_ADSENSE_CLIENT && (
48+
<>
49+
<script
50+
dangerouslySetInnerHTML={{
51+
__html: `window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('consent','default',{ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',analytics_storage:'denied',wait_for_update:500});gtag('set','ads_data_redaction',true);`,
52+
}}
53+
/>
54+
<script
55+
id="cookieyes"
56+
type="text/javascript"
57+
src={`https://cdn-cookieyes.com/client_data/${process.env.NEXT_PUBLIC_COOKIEYES_ID}/script.js`}
58+
/>
59+
</>
60+
)}
61+
</head>
4762
<body style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
4863
<AdScripts />
4964
<script
Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
import Script from 'next/script'
2-
import { getAdsenseClient, getCookieyesId, isAdsEnabled } from '@/lib/ads'
2+
import { getAdsenseClient } from '@/lib/ads'
33

44
export function AdScripts() {
55
const client = getAdsenseClient()
6-
const cookieyesId = getCookieyesId()
7-
const consentEnabled = isAdsEnabled()
86

9-
// AdSense script loads when publisher ID is set (needed for verification + serving)
107
if (!client) return null
118

129
return (
13-
<>
14-
{/* Consent Mode + CookieYes only load when both env vars are set */}
15-
{consentEnabled && (
16-
<>
17-
<Script id="consent-mode-defaults" strategy="beforeInteractive">
18-
{`window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('consent','default',{ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',analytics_storage:'denied',wait_for_update:500});gtag('set','ads_data_redaction',true);`}
19-
</Script>
20-
<Script
21-
id="cookieyes"
22-
src={`https://cdn-cookieyes.com/client_data/${cookieyesId}/script.js`}
23-
strategy="beforeInteractive"
24-
/>
25-
</>
26-
)}
27-
28-
{/* Google AdSense — loads when publisher ID is set */}
29-
<Script
30-
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${client}`}
31-
strategy="afterInteractive"
32-
crossOrigin="anonymous"
33-
/>
34-
</>
10+
<Script
11+
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${client}`}
12+
strategy="afterInteractive"
13+
crossOrigin="anonymous"
14+
/>
3515
)
3616
}

0 commit comments

Comments
 (0)