diff --git a/admin-compliance/lib/sdk/einwilligungen/generator/cookie-banner-embed.ts b/admin-compliance/lib/sdk/einwilligungen/generator/cookie-banner-embed.ts index 6b553d7..b2fdcdf 100644 --- a/admin-compliance/lib/sdk/einwilligungen/generator/cookie-banner-embed.ts +++ b/admin-compliance/lib/sdk/einwilligungen/generator/cookie-banner-embed.ts @@ -245,13 +245,16 @@ function generateHTML(config: CookieBannerConfig, privacyPolicyUrl: string): str const categoriesHTML = config.categories .map((cat) => { const isRequired = cat.isRequired + // COMPLIANCE: Only "required" categories may be pre-enabled (EuGH Planet49) + // Non-required categories must NEVER be defaultEnabled + const isEnabled = isRequired ? true : false return ` @@ -286,10 +289,22 @@ function generateHTML(config: CookieBannerConfig, privacyPolicyUrl: string): str - - ${config.texts.privacyPolicyLink.de} - + + + + + Cookie-Einstellungen + `.trim() } @@ -397,6 +412,31 @@ function generateJS(config: CookieBannerConfig): string { overlay?.classList.remove('active'); } + // Script-Blocking: activate scripts with data-cookie-category ONLY after consent + function activateConsentedScripts() { + const consent = getConsent(); + if (!consent) return; + + // Find all blocked scripts (type="text/plain" with data-cookie-category) + document.querySelectorAll('script[data-cookie-category][type="text/plain"]').forEach(script => { + const category = script.getAttribute('data-cookie-category'); + if (consent[category] === true) { + // Replace type to activate the script + const newScript = document.createElement('script'); + if (script.src) newScript.src = script.src; + else newScript.textContent = script.textContent; + newScript.type = 'text/javascript'; + script.parentNode.replaceChild(newScript, script); + } + }); + + // Also fire custom event for programmatic listeners + window.dispatchEvent(new CustomEvent('cookieConsentActivated', { detail: consent })); + } + + // Run script activation after consent is saved + window.addEventListener('cookieConsentUpdated', activateConsentedScripts); + window.CookieConsent = { getConsent, saveConsent, @@ -405,14 +445,32 @@ function generateJS(config: CookieBannerConfig): string { document.getElementById('cookieBanner')?.classList.add('active'); document.getElementById('cookieBannerOverlay')?.classList.add('active'); }, - hide: closeBanner + hide: closeBanner, + activateScripts: activateConsentedScripts, }; if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', initBanner); + document.addEventListener('DOMContentLoaded', () => { + initBanner(); + activateConsentedScripts(); + }); } else { initBanner(); + activateConsentedScripts(); } })(); + +/* + * USAGE: Script-Blocking + * + * Instead of: + * + * + * Use: + * + * + * The script will only execute AFTER the user consents to "statistics". + */ `.trim() }