document.addEventListener("DOMContentLoaded", function () { function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) === ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length); } return null; } function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/; SameSite=Lax"; } function loadScript(url, callback) { var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { // IE script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } }; } else { // Others script.onload = function () { callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); } function checkCookieAndLoadScript(cookieName) { var consentCookie = getCookie(cookieName); if (consentCookie) { var consentValues = JSON.parse(consentCookie); if (consentValues.includes("statistics")) { console.log("Loading Google Analytics"); loadScript('https://www.googletagmanager.com/gtm.js?id=GTM-TXGSFSV5', function () { // Your code to run after the script is loaded window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); }); var iframe = document.createElement('iframe'); iframe.style.display = "none"; iframe.style.visibility = "hidden"; iframe.width = "0"; iframe.height = "0"; iframe.src = "https://www.googletagmanager.com/ns.html?id=GTM-TXGSFSV5"; document.body.insertBefore(iframe, document.body.firstChild); } if (consentValues.includes("marketing")) { //console.log("Loading marketing"); //loadScript(); } } } var scriptTag = document.getElementById("conditional-script"); var cookieName = scriptTag.getAttribute("data-cookie"); //var valueToCheck = scriptTag.getAttribute("data-value"); var consent = getCookie('consent'); //var consentParsed = null; var expectedVersionElement = document.getElementById('cookie-version'); var expectedVersion = expectedVersionElement.getAttribute('data-expected-version'); var consentVersion = getCookie('consent_version'); if (consentVersion !== expectedVersion) { document.getElementById('cookie-consent').style.display = 'block'; // Optionally clear the old 'consent' cookie setCookie('consent', '', -1); } document.getElementById('accept').addEventListener('click', function () { var selectedCategories = []; var checkboxes = document.querySelectorAll('#cookie-categories input:checked'); checkboxes.forEach(function (checkbox) { selectedCategories.push(checkbox.name); }); setCookie('consent', JSON.stringify(selectedCategories), 365); setCookie('consent_version', expectedVersion, 365); // Set the version cookie here document.getElementById('cookie-consent').style.display = 'none'; }); document.getElementById('decline').addEventListener('click', function () { setCookie('consent', 'false', 365); setCookie('consent_version', expectedVersion, 365); // Set the version cookie here document.getElementById('cookie-consent').style.display = 'none'; }); // Call checkCookieConsent when the page loads checkCookieAndLoadScript(cookieName); });