function getCookie(name) { const m = document.cookie.match(new RegExp('(?:^|; )' + name.replace(/[$()*+.?[\\\]^{|}]/g,'\\$&') + '=([^;]*)')); return m ? decodeURIComponent(m[1]) : null; } // Matomo commonly uses these cookies when using consent APIs: function getMatomoConsentState() { // Some Matomo docs mention cookie "consent" :contentReference[oaicite:2]{index=2} if (getCookie("consent")) return "accepted"; // Common in real deployments / issues & forum discussions :contentReference[oaicite:3]{index=3} if (getCookie("mtm_consent") || getCookie("mtm_cookie_consent")) return "accepted"; if (getCookie("mtm_consent_removed") || getCookie("mtm_cookie_consent_removed")) return "rejected"; return null; // no choice } (function () { /********************************************************** * CONFIG — CHANGE THESE **********************************************************/ const MATOMO_URL = "https://matomo.klassik-stiftung.de/"; // must end with / const MATOMO_SITE_ID = "40"; const CONSENT_KEY = "matomo_consent_choice"; // accepted | rejected | null /********************************************************** * MATOMO SETUP (Consent Required) **********************************************************/ window._paq = window._paq || []; // Require consent BEFORE tracking is allowed _paq.push(["requireConsent"]); // Apply saved consent choice const saved = getMatomoConsentState(); if (saved === "accepted") { _paq.push(["rememberConsentGiven"]); } else if (saved === "rejected") { _paq.push(["forgetConsentGiven"]); } // Load Matomo script function loadMatomo() { _paq.push(["setTrackerUrl", MATOMO_URL + "matomo.php"]); _paq.push(["setSiteId", MATOMO_SITE_ID]); const g = document.createElement("script"); g.async = true; g.src = MATOMO_URL + "matomo.js"; document.head.appendChild(g); } loadMatomo(); /********************************************************** * BANNER HTML (Injected dynamically) **********************************************************/ function injectBanner() { // Create banner div const old = document.getElementById("matomo-consent-banner"); if (old) old.remove(); const banner = document.createElement("div"); banner.id = "matomo-consent-banner"; const choice = getMatomoConsentState() let statusText = "⚠️ No choice made yet."; if (choice === "accepted") statusText = "✅ Matomonachverfolgung ist zur Zeit EIN."; if (choice === "rejected") statusText = "❌ Matomonachverfolgung ist zur Zeit AUS."; banner.innerHTML = `

Auf dieser Seite benutzen wir Matomo zur Webanalyse. Es werden sonst ausschließlich technische Cookies genutzt. Für eingebettete Inhalte wird jeweils explizit eine Einwilligung erbeten. Es gilt diese Datenschutzbestimmung. 

Status: ${statusText}

`; document.body.appendChild(banner); // Add CSS dynamically too const style = document.createElement("style"); style.textContent = ` #matomo-consent-banner { position: fixed; bottom: 0; left: 0; right: 0; background: #111; color: white; padding: 16px; font-family: system-ui, sans-serif; z-index: 99999; display: flex; justify-content: center; } #matomo-consent-banner .matomo-row { width: 100%; max-width: 1100px; display: flex; justify-content: space-between; align-items: center; gap: 15px; flex-wrap: wrap; } #matomo-consent-banner p { margin: 0; line-height: 1.4; } #matomo-consent-banner a { color: #fff; text-decoration: underline; margin-left: 6px; } .matomo-status { margin-top: 8px; font-size: 14px; opacity: 0.9; } .matomo-actions { display: flex; gap: 10px; } .matomo-actions button { padding: 10px 14px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; } #matomo-accept { background: white; color: black; } #matomo-reject { background: #333; color: white; } `; document.head.appendChild(style); /********************************************************** * BUTTON ACTIONS **********************************************************/ document.getElementById("matomo-accept").onclick = function () { localStorage.setItem(CONSENT_KEY, "accepted"); _paq.push(["rememberConsentGiven"]); _paq.push(["trackPageView"]); banner.remove(); }; document.getElementById("matomo-reject").onclick = function () { localStorage.setItem(CONSENT_KEY, "rejected"); _paq.push(["forgetConsentGiven"]); banner.remove(); }; } /********************************************************** * SHOW BANNER ONLY IF NO CHOICE YET **********************************************************/ const consentState = getMatomoConsentState(); if (!consentState) injectBanner(); /********************************************************** * OPTIONAL: Expose API for Footer Link **********************************************************/ window.MatomoConsent = { open: injectBanner, reset: function () { localStorage.removeItem(CONSENT_KEY); injectBanner(); } }; })();