var rmgGdpr = { askLocation: false, settings: false, localStorageKey: 'rmgConsentData', setLocalStorageKey: function (localStorageKey) { this.localStorageKey = localStorageKey; }, getSettings: function () { if (localStorage.getItem(this.localStorageKey)) { var consentData = JSON.parse(localStorage.getItem(this.localStorageKey)); this.settings = { "ads": consentData.ads, "content": consentData.content, "consentString": consentData.consentString, "purposes": consentData.purposes }; } return this.settings; }, handleAll: function () { this.handleBT(); this.handleGenericContent(); this.handleCXense(); this.handleTracking(); }, handleBT: function () { var settings = this.getSettings(); if (typeof BT !== 'undefined') { if (settings.content === true) { BT.optin(); } else { BT.optout(); } } }, handleGenericContent: function () { /* * used for generic elements that follow simple rules e.g.: trackuity, outbrain.. * elements with class "rmg-gdpr-content": * - will be hidden if settings.content == false * - src="x" will be added if data-src="x" exists and settings.content == true */ var settings = this.getSettings(); var elements = document.querySelectorAll(".rmg-gdpr-content:not(.gdpr-loaded)"); for (var i = 0; i < elements.length; i++) { var element = elements.item(i); if (settings.content === true) { if (typeof element.dataset.src !== 'undefined') { element.src = element.dataset.src; } } else { element.style.display = 'none'; } //make sure we don't process the same element in a next call: element.classList.add("gdpr-loaded"); } }, handleLocation: function () { // Check if location should be asked if (!localStorage.getItem('locationTimestamp')) { this.askLocation = true; localStorage.setItem('locationTimestamp', Date.now()); } else { var difference = Date.now() - localStorage.getItem('locationTimestamp'); var daysDifference = Math.floor(difference / 1000 / 60 / 60 / 24); if (daysDifference < 10) { this.askLocation = false; } else { this.askLocation = true; localStorage.setItem('locationTimestamp', Date.now()); } } }, handleCXense: function () { var cXenseStatus = this.getCXenseStatus(); if (typeof cX !== 'undefined') { cX.callQueue.push(['setConsent', {pv: cXenseStatus}]); } }, handleTracking: function () { var settings = this.getSettings(); if (typeof rmgParamObject !== 'undefined') { var eventLabel = ''; for (var index in settings.purposes) { eventLabel += "P" + index + "-" + (settings.purposes[index] ? "Y" : "N"); if (index < 5) eventLabel += "_"; } rmgParamObject.tracking.wrapper('send', 'event', 'cookies', 'click', eventLabel); } if (typeof dataLayer !== 'undefined') { var dlCookieStatus = ''; if (settings.ads && settings.content) { dlCookieStatus = 'content-yes_ads-yes'; } else if (settings.ads && !settings.content) { dlCookieStatus = 'content-no_ads-yes'; } else if (!settings.ads && settings.content) { dlCookieStatus = 'content-yes_ads-no'; } else if (!settings.ads && !settings.content) { dlCookieStatus = 'content-no_ads-no'; } dataLayer.push( {'dl_cookie_status': dlCookieStatus} ); } }, getFacebookPixelStatus: function () { var settings = this.getSettings(); return settings.ads; }, getGoogleRetargetingStatus: function () { var settings = this.getSettings(); return settings.ads; }, getCXenseStatus: function () { var settings = this.getSettings(); return settings.content; }, reset: function () { this.settings = false; rmgGdpr.handleAll(); }, showPreferenceCenter: function () { if (localStorage.getItem(this.localStorageKey) != null) { document.querySelector('.rmgSpinner').style.display = 'block'; } rmgModal.inject('oil-wrapper', '