(function () { // Pardot config window.piAId = 69592; window.piCId = 5932; window.piHostname = "go.bestcase.com"; const PARDOT_CONSENT_GROUP = "C0004"; let pardotLoaded = false; function loadPardot() { if (pardotLoaded) return; pardotLoaded = true; window.pi = window.pi || function () { (window.pi.q = window.pi.q || []).push(arguments); }; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = "https://" + window.piHostname + "/pd.js"; s.onload = function () { if (window.pi) { pi("create", window.piAId, window.piCId); pi("setOptIn", true); pi("sendPageView"); console.log("Pardot initialized"); } }; document.body.appendChild(s); } function handleConsent(groups) { const hasConsent = groups.includes(PARDOT_CONSENT_GROUP); console.log("Consent groups:", groups); console.log("Has Pardot consent:", hasConsent); if (hasConsent) { loadPardot(); } else { if (window.pi) { pi("setOptIn", false); pi("revokeConsent"); } } } // Listen for OneTrust updates window.addEventListener("OneTrustGroupsUpdated", function (e) { handleConsent(e.detail || []); }); // Fallback for existing consent on page load function getInitialGroups() { if (window.OnetrustActiveGroups) { return window.OnetrustActiveGroups.split(",").filter(Boolean); } return []; } // Run once on load (important!) handleConsent(getInitialGroups()); })();