window.ComplianceMgrConsentUtils = window.ComplianceMgrConsentUtils || {}; window.ComplianceMgrConsentUtils = (function () { function isWcpConsentPresent() { return (typeof WcpConsent !== 'undefined' && WcpConsent && typeof WcpConsent.siteConsent !== 'undefined' && WcpConsent.siteConsent); } function isGpcOptInPresent() { return (typeof GPC_DataSharingOptIn !== 'undefined' && GPC_DataSharingOptIn != null); } function areConsentObjsPresent(name) { return (name == "consent" && isWcpConsentPresent() && isGpcOptInPresent()); } /*Function to try to find a specific object */ function waitForObj(objectName) { var waitTimeInMS = 50; var maxRetryCt = 100; return new Promise(function (resolve, reject) { var retryCt = 0; var intervalHandle = setInterval(function () { // Trying to find the specified object if (retryCt < maxRetryCt) { if (areConsentObjsPresent(objectName)) { clearInterval(intervalHandle); resolve(); } else { retryCt++; } } else { // Giving up trying to find the specified object clearInterval(intervalHandle); reject(); } }, waitTimeInMS); }); } return { waitForObj: waitForObj } }()); var ComplianceManagerConsentHandler = (function () { // Redefine essential cookies var essentialCookies = [ "3PAdsOptOut", "MSCC", "ApplicationGatewayAffinity", "ApplicationGatewayAffinityCORS", "MC1", "MS0", "MSFPC", "MicrosoftApplicationsTelemetryDeviceId", "ai_session", "ai_user", "CAS_PROGRAM", "Cascade.AuthUPN", "Cascade.OpenIdConnect", "Cascade.AuthSSO", "ak_bmsc", "akacd_OneRF", "bm_sv", "mbox", // this is not an essential cookie and is being handled by pre-existing experimentation script "AMCV_EA76ADE95776D2EC7F000101%40AdobeOrg", // this is not an essential cookie and is being handled by pre-existing experimentation script "AMCVS_EA76ADE95776D2EC7F000101%40AdobeOrg", // this is not an essential cookie and is being handled by pre-existing experimentation script "isFirstSession", "thx_guid", "tmx_guid", "X-FD-FEATURES", "X-FD-Time", "at_check", "mboxEdgeCluster", "RT", "PMGSKUMarketCk", "ocrAIChat", "cartItemCount", "cartMuid", "bStore", ]; var essentialCoookiesDynamicName = [ ".AspNetCore.Correlation.", ".AspNetCore.OpenIdConnect.", ".AspNetCore.OpenIdConnect.Nonce.", "modal-redirect-dismissed-", "akacd_" ]; var fraudProtectionCookies = [ "MUID", "fptctx2" ]; /* Function to delete a specific cookie */ function deleteCookie(cookieName) { document.cookie = cookieName + '=;max-age=-1;path=/;domain=.microsoft.com;'; } // Function to check if the iframe is present function isFptIframePresent() { return document.querySelector('iframe[title="cli_fpt_iframe"]') !== null; } /* Function to delete all cookies not in the essential list */ function deleteNonEssentialCookies() { var cookies = document.cookie.split(";"); var iframePresent = isFptIframePresent(); cookies.forEach(function(cookie) { var cookieName = cookie.split("=")[0].trim(); // Skip deleting cookies that start with any dynamic cookie name if (essentialCoookiesDynamicName.some(function(prefix) { return cookieName.startsWith(prefix); // Check if cookie name starts with any dynamic prefix })) { return; // Do nothing, skip this cookie } // If iframe is present, do not delete fraud protection cookies if (iframePresent && fraudProtectionCookies.includes(cookieName)) { return; // Do nothing, skip this cookie } if (essentialCookies.indexOf(cookieName) === -1) { deleteCookie(cookieName); // Delete non-essential cookies } }); } /* Function to check if user consent is granted */ function checkUserConsent() { // Return false if the conditions are not met if (!WcpConsent || !WcpConsent.siteConsent || !WcpConsent.siteConsent.getConsent) { return false; // Consent information is missing, so return false immediately } // Now check the user's consent var userConsent = WcpConsent.siteConsent.getConsent(); // Return true only if all the necessary consents are granted return userConsent && userConsent.Advertising && userConsent.Analytics && userConsent.SocialMedia; } /* Callback function to handle consent change */ function consentChangeCallBack() { if (!checkUserConsent()) { // If consent is not granted, delete non-essential cookies deleteNonEssentialCookies(); } } /* Register the consent change callback */ function handleConsentChange() { window.ComplianceMgrConsentUtils.waitForObj("consent").then(function () { if (WcpConsent && WcpConsent.onConsentChanged) { WcpConsent.onConsentChanged(consentChangeCallBack); } // Check consent on page load consentChangeCallBack(); }).catch(function (err) { console.log("Error handling consent change:", err); }); } if (typeof exports === 'object') { module.exports = { consentChangeCallBack:consentChangeCallBack, handleConsentChange:handleConsentChange, checkUserConsent:checkUserConsent }; } return { handleConsentChange: handleConsentChange, checkUserConsent: checkUserConsent }; })(); if (document.readyState === "complete" || document.readyState === "interactive") { ComplianceManagerConsentHandler.handleConsentChange(); } else { document.addEventListener("DOMContentLoaded", ComplianceManagerConsentHandler.handleConsentChange, false); }