Files
portfolio-photo/public/custom/consent.js
T
Leon TonhäuserandClaude Opus 5.5 6ae031b3cb fix: Google Tag Manager erst nach Einwilligung laden
GTM-Loader ist jetzt eine Funktion (ltLadeGtm), die consent.js nur bei
„Alle akzeptieren“ bzw. gespeicherter Zustimmung aufruft. noscript-iframe
entfernt, da er ohne Einwilligung Google kontaktiert hat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-22 23:47:20 +02:00

64 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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) {
// GTM erst nach Einwilligung laden – vorher keine Verbindung zu Google.
if (granted && typeof window.ltLadeGtm === 'function') window.ltLadeGtm();
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 &amp; 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();
}
})();