(() => { const GTM_ID = "GTM-MRBQ3D5"; const GTM_SRC = `https://www.googletagmanager.com/gtm.js?id=${GTM_ID}`; window.__phGtmLoaded = window.__phGtmLoaded || false; function getCookie(name) { return document.cookie .split("; ") .find(c => c.startsWith(`${name}=`)) ?.split("=")[1]; } function hasConsent() { return getCookie("PHPPPE_GCC") === "a"; } function isGtmAlreadyInjected() { const scriptExists = !!document.querySelector( `script[src*="googletagmanager.com/gtm.js?id=${GTM_ID}"]` ); const gtmRuntimeExists = window.google_tag_manager && Object.prototype.hasOwnProperty.call(window.google_tag_manager, GTM_ID); return scriptExists || gtmRuntimeExists; } function isGpcOptedOut() { return navigator.globalPrivacyControl === true; } function loadGtm() { if (window.__phGtmLoaded) return; if (isGpcOptedOut()) return; if (!hasConsent()) return; if (isGtmAlreadyInjected()) return; window.dataLayer = window.dataLayer || []; window.dataLayer.push({ "gtm.start": Date.now(), event: "gtm.js" }); const script = document.createElement("script"); script.async = true; script.src = GTM_SRC; const nonceEl = document.querySelector("[nonce]"); if (nonceEl) { script.nonce = nonceEl.nonce || nonceEl.getAttribute("nonce"); } script.onload = () => { window.__phGtmLoaded = true; }; document.head.appendChild(script); } let previousConsent = hasConsent(); function handleConsentChange() { const currentConsent = hasConsent(); if (previousConsent && !currentConsent) { location.replace(location.href); return; } if (!previousConsent && currentConsent) { loadGtm(); } previousConsent = currentConsent; } loadGtm(); document.addEventListener( "ph:gdpr:OptanonWrapperUpdated", handleConsentChange ); })();