feat: Google Tag Manager + Consent Mode v2 + Cookie-Banner (DSGVO)
- Auf allen 26 Seiten: altes GA-gtag-Snippet (G-CC4TX68365) ersetzt durch Google-Consent-Mode-v2-Default „denied" + GTM-Container GTM-T6CVBLPR (head) - GTM-noscript-iframe direkt nach <body> - Neue custom/consent.js: selbstgebautes Consent-Banner (Akzeptieren / Nur Notwendige / Datenschutz-Link), speichert Wahl in localStorage, updated Consent Mode. Auf allen Seiten eingebunden. Voraussetzung für Google Ads; DSGVO-konform (keine Cookies vor Einwilligung). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
6a20d6021a
commit
cf8e67c452
27 files changed
+611
-125
No files matched your search
@@ -0,0 +1,62 @@
|
||||
// Cookie-/Consent-Banner (Google Consent Mode v2).
|
||||
// Selbstgebaute, DSGVO-konforme Einwilligung. Defaults stehen auf „denied" (im head),
|
||||
// nach Nutzerwahl update per gtag('consent','update',…). Wahl landet in localStorage.
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var KEY = 'lt_consent_v1';
|
||||
|
||||
function update(granted) {
|
||||
if (typeof gtag !== 'function') return;
|
||||
var v = granted ? 'granted' : 'denied';
|
||||
gtag('consent', 'update', {
|
||||
'ad_storage': v,
|
||||
'ad_user_data': v,
|
||||
'ad_personalization': v,
|
||||
'analytics_storage': v
|
||||
});
|
||||
}
|
||||
|
||||
var saved = null;
|
||||
try { saved = localStorage.getItem(KEY); } catch (e) {}
|
||||
|
||||
if (saved === 'all') { update(true); return; }
|
||||
if (saved === 'none') { update(false); return; }
|
||||
|
||||
// Keine Entscheidung gespeichert → Banner einblenden.
|
||||
function show() {
|
||||
var style = document.createElement('style');
|
||||
style.textContent = [
|
||||
'#lt-consent{position:fixed;left:0;right:0;bottom:0;z-index:9999;background:#fff;color:#111;',
|
||||
'box-shadow:0 -4px 24px rgba(0,0,0,.12);padding:18px 20px;font:inherit;font-size:14px;line-height:1.5}',
|
||||
'#lt-consent .lt-inner{max-width:1080px;margin:0 auto;display:flex;gap:16px;align-items:center;flex-wrap:wrap}',
|
||||
'#lt-consent p{margin:0;flex:1 1 320px}',
|
||||
'#lt-consent a{color:#111;text-decoration:underline}',
|
||||
'#lt-consent .lt-btns{display:flex;gap:10px;flex-wrap:wrap}',
|
||||
'#lt-consent button{font:inherit;font-weight:600;border-radius:10px;padding:10px 18px;cursor:pointer;border:1px solid #ddd;background:#fff;color:#111}',
|
||||
'#lt-consent button.lt-accept{background:#111;color:#fff;border-color:#111}'
|
||||
].join('');
|
||||
document.head.appendChild(style);
|
||||
|
||||
var b = document.createElement('div');
|
||||
b.id = 'lt-consent';
|
||||
b.innerHTML = '<div class="lt-inner"><p>Diese Seite nutzt Google Analytics & Google Ads, um die Nutzung zu messen und dir relevantere Werbung zu zeigen. Mit „Alle akzeptieren" stimmst du der Verarbeitung zu. Du kannst „Nur Notwendige" wählen. Mehr in der <a href="./datenschutz">Datenschutzerklärung</a>.</p><div class="lt-btns"><button class="lt-accept" type="button">Alle akzeptieren</button><button class="lt-decline" type="button">Nur Notwendige</button></div></div>';
|
||||
document.body.appendChild(b);
|
||||
|
||||
function close() { b.remove(); style.remove(); }
|
||||
b.querySelector('.lt-accept').addEventListener('click', function () {
|
||||
try { localStorage.setItem(KEY, 'all'); } catch (e) {}
|
||||
update(true); close();
|
||||
});
|
||||
b.querySelector('.lt-decline').addEventListener('click', function () {
|
||||
try { localStorage.setItem(KEY, 'none'); } catch (e) {}
|
||||
update(false); close();
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', show);
|
||||
} else {
|
||||
show();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user