1/** 2 * digitas-cmp-handler.js 3 * 4 * Verwaltet den eTracker-Consent-Status in Verbindung mit dem ConsentManager (consentmanager.net). 5 * 6 * Kernlogik: Wechsel von Zustimmung â Ablehnung für eTracker 7 * 1. Initialen eTracker-Consent-Status beim Seitenaufruf speichern 8 * 2. Auf `consentcustom`-Event hören 9 * 3. Bei Wechsel von true â false: Cookie `_et_coid` löschen + Seite neu laden 10 * 11 * Vendor-ID eTracker : s987 12 * Cookie-Name : _et_coid 13 */ 14 15(function () { 16 17 /** 18 * Debug-Modus: auf `true` setzen, um console.log-Ausgaben zu aktivieren. 19 * Vor dem Commit auf `false` zurücksetzen. 20 * 21 * Kann auch über den globalen Scope gesteuert werden, z.B. via TypoScript: 22 * page.headerData.99 = TEXT 23 * page.headerData.99.value = <script>window.digitasDebug = true;</script> 24 * 25 * @type {boolean} 26 */ 27 var digitasDebug = (typeof window.digitasDebug !== 'undefined') ? window.digitasDebug : false; 28 29 /** 30 * Initialer Consent-Status â wird beim `consent`-Event des CMP gesetzt, 31 * sobald die gespeicherten Consent-Daten nach dem Seitenaufruf geladen wurden. 32 * Null solange das CMP noch nicht bereit ist. 33 * 34 * @type {boolean|null} 35 */ 36 var digitasPreviousEtrackerConsent = null; 37 38 /** 39 * Interne Log-Hilfsfunktion â gibt nur aus, wenn digitasDebug === true. 40 * 41 * @param {...*} args 42 */ 43 var digitasLog = function () { 44 if (digitasDebug) { 45 console.log.apply(console, arguments); 46 } 47 }; 48 49 /** 50 * Gibt alle relevanten Domain-Varianten des aktuellen Hosts zurück, 51 * damit das Cookie zuverlässig auf allen Ebenen gelöscht wird. 52 * 53 * @returns {string[]} 54 */ 55 var digitasGetDomains = function () { 56 digitasLog('[digitas-cmp-handler] digitasGetDomains()'); 57 var parts = location.hostname.split('.'); 58 return [ 59 location.hostname, 60 '.' + location.hostname, 61 '.' + parts.slice(-2).join('.'), 62 '.' + parts.slice(-3).join('.') 63 ]; 64 }; 65 66 /** 67 * Löscht ein Cookie für alle relevanten Domain-Varianten. 68 * 69 * @param {string} cookieName 70 */ 71 var digitasDeleteCookie = function (cookieName) { 72 digitasLog('[digitas-cmp-handler] digitasDeleteCookie = function (cookieName:%o)', cookieName); 73 var domains = digitasGetDomains(); 74 domains.forEach(function (domain) { 75 digitasLog('[digitas-cmp-handler] delete cookie: ' + cookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=' + domain); 76 document.cookie = cookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=' + domain; 77 }); 78 }; 79 80 /** 81 * Liest den aktuellen eTracker-Consent-Status aus den CMP-Daten. 82 * 83 * @returns {boolean|null} true = zugestimmt, false = abgelehnt, null = unbekannt 84 */ 85 var digitasGetEtrackerConsent = function () { 86 try { 87 var cmpData = __cmp('getCMPData'); 88 if (cmpData && cmpData.vendorConsents) { 89 return cmpData.vendorConsents['s987'] === true; 90 } 91 } catch (e) { 92 digitasLog('[digitas-cmp-handler] GetEtrackerConsent - exception: __cmp nicht verfügbar (e:%o)', e); 93 } 94 return null; 95 }; 96 97 /** 98 * Initialisierungs-Handler â feuert einmalig, wenn das CMP beim Seitenaufruf 99 * die gespeicherten Consent-Daten geladen hat (`consent`-Event). 100 * Setzt den Ausgangswert für die Wechsel-Erkennung. 101 * 102 * @param {object} event 103 */ 104 var digitasCmpInitHandler = function (event) { 105 digitasPreviousEtrackerConsent = digitasGetEtrackerConsent(); 106 digitasLog('[digitas-cmp-handler] consent event (CMP ready) â initial eTracker consent: %s', digitasPreviousEtrackerConsent); 107 }; 108 109 /** 110 * Event-Handler für CMP-Consent-Ãnderungen. 111 * Reagiert auf den `consentcustom`-Event des ConsentManagers. 112 * 113 * @param {object} event 114 */ 115 var digitasCmpHandler = function (event) { 116 var currentEtrackerConsent = digitasGetEtrackerConsent(); 117 digitasLog('[digitas-cmp-handler] consentcustom event â previous: %s, current: %s', digitasPreviousEtrackerConsent, currentEtrackerConsent); 118 119 // Wechsel: Zustimmung â Ablehnung 120 if (digitasPreviousEtrackerConsent === true && currentEtrackerConsent === false) { 121 digitasLog('[digitas-cmp-handler] eTracker consent withdrawn â deleting cookie and reloading'); 122 digitasDeleteCookie('_et_coid'); 123 location.reload(); 124 return; 125 } 126 127 digitasPreviousEtrackerConsent = currentEtrackerConsent; 128 }; 129 130 // Event-Listener beim ConsentManager registrieren. 131 document.addEventListener('DOMContentLoaded', function () { 132 digitasLog('[digitas-cmp-handler] DOMContentLoaded â registering CMP event listeners'); 133 // `consent`-Event: feuert einmalig beim Laden mit gespeicherten Consent-Daten 134 __cmp('addEventListener', ['consent', digitasCmpInitHandler, false], null); 135 // `consentcustom`-Event: feuert bei aktiver Nutzeränderung 136 __cmp('addEventListener', ['consentcustom', digitasCmpHandler, false], null); 137 }); 138 139}());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.