diff --git a/websites/confetti/src/cookie-consent.js b/websites/confetti/src/cookie-consent.js index e79ecb784f5..ebb58af0044 100644 --- a/websites/confetti/src/cookie-consent.js +++ b/websites/confetti/src/cookie-consent.js @@ -96,6 +96,10 @@ function initAdSense() { return; } + // Auto-ads are configured via the AdSense dashboard and activated automatically + // by the script when loaded with ?client=ca-pub-XXXXX — no manual push needed. + // Pushing enable_page_level_ads manually conflicts with the script's own init + // and causes "Only one 'enable_page_level_ads' allowed per page" TagError. loadScript( 'adsense-script', `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_CLIENT_ID}`, @@ -105,10 +109,6 @@ function initAdSense() { ); window.adsbygoogle = window.adsbygoogle || []; - window.adsbygoogle.push({ - google_ad_client: ADSENSE_CLIENT_ID, - enable_page_level_ads: true, - }); adsenseInitialized = true; } @@ -131,6 +131,7 @@ function initConsentDefaults() { } function updateConsentMode(activeConsent) { + initConsentDefaults(); ensureGtagStub(); window.gtag('consent', 'update', { diff --git a/websites/website/docs/.vitepress/theme/tracking/runtime.ts b/websites/website/docs/.vitepress/theme/tracking/runtime.ts index 26b82db9a9d..4b5a1283d98 100644 --- a/websites/website/docs/.vitepress/theme/tracking/runtime.ts +++ b/websites/website/docs/.vitepress/theme/tracking/runtime.ts @@ -104,6 +104,9 @@ function initGoogleAdSense(): void { return; } + // Load the AdSense script with the client ID in the URL. + // Auto-ads are configured via the AdSense dashboard; the script enables them + // automatically when loaded with ?client=ca-pub-XXXXX — no manual push needed. loadScriptOnce( ADSENSE_SCRIPT_ID, `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${trackingConfig.googleAdSenseClientId}`, @@ -116,10 +119,6 @@ function initGoogleAdSense(): void { } trackingWindow.adsbygoogle ??= []; - trackingWindow.adsbygoogle.push({ - google_ad_client: trackingConfig.googleAdSenseClientId, - enable_page_level_ads: true, - }); adSenseInitialized = true; } @@ -145,6 +144,8 @@ function updateConsentMode(preferences: CookieConsentPreferences): void { return; } + initConsentModeDefaults(); + const trackingWindow = ensureGtagStub(); if (!trackingWindow?.gtag) {