function __cb_setupFunction() { try { const scriptElm = document.getElementById('privasee-cb'); if (!scriptElm) return; // These variables are changed when the script compiles on our server const crossDomainSharing = 'false' === 'true' ? true : false; const tcfEnabled = 'false' === 'true' ? true : false; const _companyId = '636e2b42372aff001344d253'; const settingsId = `E14BC4oSR`; const isTesting = `false` === 'true' ? true : false; const isCookieBannerV3 = `false` === 'true' ? true : false; const themingId = `default`; const domain = `https://products.privasee.io`; const gcm = `false` === 'true' ? true : false; const smartCookieBlocker = `false` === 'true' ? true : false; // The Usercentrics loader.js lazy loads parts of the banner and needs eval to do so. When the website's // Content Security Policy blocks eval, it requests those parts from the website's own domain and fails (404). // For those websites we use bundle.js instead, which Usercentrics recommends for sites with a CSP. function getUsercentricsScript() { if (isCookieBannerV3) return `//web.cmp.usercentrics.eu/ui/loader.js`; return `//app.usercentrics.eu/browser-ui/latest/${__cb_isEvalBlocked() ? 'bundle' : 'loader'}.js`; } const usercentricsScript = getUsercentricsScript(); // We defined the dependencies that will be loaded onto the client's website. const arr = [ { rel: `preconnect`, href: isCookieBannerV3 ? `//web.cmp.usercentrics.eu` : `//app.usercentrics.eu` }, { rel: `preconnect`, href: `//api.usercentrics.eu` }, { rel: `preconnect`, href: `//privacy-proxy.usercentrics.eu` }, { rel: `preload`, href: usercentricsScript, as: 'script' } ]; // We create the and then insert onto the website's body. arr.forEach((elm, ix) => { var link; link = document.createElement('link'); link.rel = elm.rel; link.href = elm.href; link.id = `cb-assets-${ix}`; if (elm.as) { link.as = elm.as; } __cb_insertAfter(link, ix == 0 ? scriptElm : document.getElementById(`cb-assets-${ix - 1}`)); }); // Load the theme if any.. (once Usercentrics is ready) if (themingId !== 'default') { __cb_onUsercentricsReady(function () { __cb_addStyles({ themingId, domain }); }); } // We now will create the default script which is gonna load the cookie banner. // This script is provided by Usercentrics. function injectUsercentricsScript(src) { let script1 = document.createElement('script'); script1.id = 'usercentrics-cmp'; script1.setAttribute('data-settings-id', settingsId); script1.src = `https:${src}`; script1.async = true; // If we are in a testing environment, this field must be added. if (isTesting) { script1.setAttribute('data-sandbox', 'true'); } // If TCF is enabled we need to make sure the script is loaded synchronously. if (tcfEnabled) { script1.setAttribute('data-tcf-enabled', 'true'); script1.async = false; // TCF must be not async. } // We inject it onto the website's document body. __cb_insertAfter(script1, document.getElementById(`cb-assets-${arr.length - 1}`)); // It makes it clear where our code injections ends. __cb_insertAfter(document.createComment('END COOKIE BANNER - PRIVASEE.IO'), script1); } // A CSP tag only applies once it has been parsed. When this script runs from the
, a CSP tag further down // the is not active yet, so we choose the Usercentrics script once the has been parsed (when the is created). // Only loader.js can turn out to be the wrong choice, and TCF must load straight away, so only that case waits. if (!isCookieBannerV3 && !tcfEnabled && !document.body && usercentricsScript.endsWith('/loader.js')) { const observer = new MutationObserver(function () { if (!document.body) return; observer.disconnect(); injectUsercentricsScript(getUsercentricsScript()); }); observer.observe(document.documentElement, { childList: true }); } else { injectUsercentricsScript(usercentricsScript); } // It makes it clear where our code injections starts. __cb_insertAfter(document.createComment('COOKIE BANNER - PRIVASEE.IO'), scriptElm); // Deleting the original CDN Script to keep things clear. scriptElm.remove(); // If we are in a testing environment we will also announce it in the console. if (isTesting) { console.warn(`[LOADED] Cookie banner has been loaded.`); } // When Cross Domain sharing is enabled this must be invoked. if (crossDomainSharing) { // Set the dependencies up __cb_crossDomain_setFunctions(domain, _companyId); __cb_crossDomain_setEvents(domain); } // If google consent mode is enabled if (gcm) { __cb_loadGoogleConsentMode(smartCookieBlocker); } } catch (err) { console.error(`[ERROR] Privasee - Cookie Banner`, err); } } function __cb_isEvalBlocked() { // A CSP set by a tag can be read, so we check it first. This avoids the CSP violation report the eval test below causes. const metaTags = document.querySelectorAll('meta[http-equiv="Content-Security-Policy" i]'); for (const metaTag of metaTags) { const directives = (metaTag.content || '').split(';').map((directive) => directive.trim().toLowerCase().split(/\s+/)); // Eval is controlled by script-src, which falls back to default-src. const scriptSrc = directives.find((directive) => directive[0] === 'script-src') || directives.find((directive) => directive[0] === 'default-src'); if (scriptSrc && !scriptSrc.includes(`'unsafe-eval'`)) return true; } // A CSP set by a header can't be read, so we test eval directly. try { new Function(''); return false; } catch (err) { return true; } } function __cb_addStyles(args) { // Find the target const target = document.getElementById('usercentrics-root'); if (!target || !target.shadowRoot) return false; // Check browser name... const browserName = __cb_getBrowserName(); if (browserName === 'Safari') return false; // not compatible. // Create a stylesheet const stylesheet = document.createElement('link'); stylesheet.rel = 'stylesheet'; stylesheet.href = `${args.domain}/assets/css/cookieBanner/${args.themingId}.css`; // Inject it target.shadowRoot.appendChild(stylesheet); } function __cb_insertAfter(newNode, referenceNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); } function __cb_getBrowserName() { const userAgent = navigator.userAgent; if (userAgent.indexOf('Safari') !== -1 && userAgent.indexOf('Chrome') === -1) { return 'Safari'; } else if (userAgent.indexOf('OPR') !== -1 || userAgent.indexOf('Opera') !== -1) { return 'Opera'; } else if (userAgent.indexOf('Chrome') !== -1) { return 'Chrome'; } else { return 'Others'; } } function __cb_onUsercentricsReady(callback) { // Usercentrics may already be initialized (e.g. it was loaded before this script ran). if (window.UC_UI && window.UC_UI.isInitialized && window.UC_UI.isInitialized()) { callback(); return; } // Otherwise wait for Usercentrics to finish loading. (Wrapped so the same callback can be queued more than once.) window.addEventListener( 'UC_UI_INITIALIZED', function () { callback(); }, { once: true } ); } function __cb_showPreferences() { // The visitor asked to manage their preferences, so cross domain consent sharing must not accept everything and close the panel for them. window.__cbPreferencesRequested = true; let opened = false; __cb_onUsercentricsReady(function () { opened = true; window.UC_UI.showSecondLayer(); }); // If Usercentrics never loads (e.g. blocked by an ad blocker or a CSP) nothing would open, so we let it be known in the console. if (!opened) { setTimeout(function () { if (!opened) console.warn('[COOKIE BANNER] Usercentrics has not loaded yet, so the cookie preferences could not be opened.'); }, 10000); } } function __cb_checkIfRedirectForCookiePreferences() { const triggerParam = `cb-manage-cookies`; // Returns the current query string without our trigger param, or null if the trigger param is not there. function getSearchWithoutTrigger() { const params = window.location.search.slice(1).split('&'); const remainingParams = params.filter((param) => param.split('=')[0] !== triggerParam); if (remainingParams.length === params.length) return null; return remainingParams.length ? `?${remainingParams.join('&')}` : ''; } // If this user was redirected from our hosted privacy portal to their main website. if (getSearchWithoutTrigger() === null) return; window.privasee.cookieBanner.showPreferences(); // Once the panel has opened, remove the trigger from the URL. Other params and the history state (SPA routers keep theirs there) are kept. __cb_onUsercentricsReady(function () { const search = getSearchWithoutTrigger(); if (search === null) return; const url = new URL(window.location.href); url.search = search; history.replaceState(history.state, '', url.href); }); } function __cb_loadGoogleConsentMode(smartCookieBlockerEnabled = false) { // try { // // Create a script element // var scriptElement = document.createElement('script'); // scriptElement.type = 'text/javascript'; // scriptElement.id = `privasee-cb-googleConsentMode-1`; // // Add the provided code to the script // scriptElement.innerHTML = ` // // create dataLayer // window.dataLayer = window.dataLayer || []; // function gtag() { // dataLayer.push(arguments); // } // // set "denied" as default for both ad and analytics storage, // gtag("consent", "default", { // ad_user_data: "denied", // ad_personalization: "denied", // ad_storage: "denied", // analytics_storage: "denied", // wait_for_update: 500 // milliseconds to wait for update // }); // // Enable ads data redaction by default [optional] // gtag("set", "ads_data_redaction", true); // `; // // Add it. // __cb_insertAfter(scriptElement, document.getElementById('usercentrics-cmp')); // // If smart cookie blocker is enabled we will unlock gtm after 500 ms (We need to wait for the script cmp script to load first) // if (smartCookieBlockerEnabled) { // // Create a script element // var scriptElementSecondary = document.createElement('script'); // scriptElementSecondary.type = 'text/javascript'; // scriptElementSecondary.id = `privasee-cb-googleConsentMode-2`; // scriptElementSecondary.innerHTML = ` // setTimeout( () => { // if(window.uc) { // window.uc.deactivateBlocking([ // 'BJ59EidsWQ', // GTM is not blocked // ]); // } // }, 500 ); // `; // __cb_insertAfter(scriptElementSecondary, document.getElementById('privasee-cb-googleConsentMode-1')); // } // } catch (err) { // console.error(`loadGoogleConsentMode`, err); // } } if (window.privasee === undefined) { window.privasee = {}; } window.privasee.cookieBanner = { showPreferences: __cb_showPreferences }; __cb_setupFunction(); __cb_checkIfRedirectForCookiePreferences();