function setOneTrustByEnvironment() { let loader = document.getElementById('oneTrustLoader'); if (window.location.href.toLowerCase().includes('hondainfo.programhq.com')) { loader.setAttribute('data-domain-script','39cb24f3-a683-4597-a308-842fce9d2388'); } else { loader.setAttribute('data-domain-script','39cb24f3-a683-4597-a308-842fce9d2388-test'); } //don't declare src until domain script set, or else will load without variable and fail loader.setAttribute('src','https://cdn.cookielaw.org/scripttemplates/otSDKStub.js'); } function OptanonWrapper() { // Get initial OnetrustActiveGroups ids if(typeof OptanonWrapperCount == "undefined"){ otGetInitialGrps(); } //Delete cookies otDeleteCookie(otIniGrps); // Assign OnetrustActiveGroups to custom variable function otGetInitialGrps(){ OptanonWrapperCount = ''; otIniGrps = OnetrustActiveGroups; // console.log("otGetInitialGrps", otIniGrps) } function otDeleteCookie(iniOptGrpId) { var otDomainGrps = JSON.parse(JSON.stringify(Optanon.GetDomainData().Groups)); var otDeletedGrpIds = otGetInactiveId(iniOptGrpId, OnetrustActiveGroups); if(otDeletedGrpIds.length != 0 && otDomainGrps.length !=0){ for(var i=0; i < otDomainGrps.length; i++){ //Check if CustomGroupId matches if(otDomainGrps[i]['CustomGroupId'] != '' && otDeletedGrpIds.includes(otDomainGrps[i]['CustomGroupId'])){ for(var j=0; j < otDomainGrps[i]['Cookies'].length; j++){ // console.log("otDeleteCookie",otDomainGrps[i]['Cookies'][j]['Name']) //Delete cookie eraseCookie(otDomainGrps[i]['Cookies'][j]); } } //Check if Hostid matches if(otDomainGrps[i]['Hosts'].length != 0){ for(var j=0; j < otDomainGrps[i]['Hosts'].length; j++){ //Check if HostId presents in the deleted list and cookie array is not blank if(otDeletedGrpIds.includes(otDomainGrps[i]['Hosts'][j]['HostId']) && otDomainGrps[i]['Hosts'][j]['Cookies'].length !=0){ for(var k=0; k < otDomainGrps[i]['Hosts'][j]['Cookies'].length; k++){ //Delete cookie eraseCookie(otDomainGrps[i]['Hosts'][j]['Cookies'][k]); } } } } } } otGetInitialGrps(); //Reassign new group ids // emergency catch for removing EncryptedPax on login if performance cookies already rejected if (!iniOptGrpId.includes('C0002')) { eraseCookie({'Name':'EncryptedPax','Host':window.location.hostname}); } } //Get inactive ids function otGetInactiveId(customIniId, otActiveGrp){ //Initial OnetrustActiveGroups // console.log("otGetInactiveId",customIniId) customIniId = customIniId.split(","); customIniId = customIniId.filter(Boolean); //After action OnetrustActiveGroups otActiveGrp = otActiveGrp.split(","); otActiveGrp = otActiveGrp.filter(Boolean); var result=[]; for (var i=0; i < customIniId.length; i++){ if ( otActiveGrp.indexOf(customIniId[i]) <= -1 ){ result.push(customIniId[i]); } } return result; } //Delete cookie (uses cookie object) function eraseCookie(cookie) { let name = cookie.Name; if(cookie.Host.includes('google.com')) { deleteAlternateDomainCookie(name,'google.com'); return; } if(name.includes('_ga_') || name.includes('_gat_')) { handleContainerCookie(); return; } //Delete root path cookies domainName = window.location.hostname; rootDomainName = window.location.hostname.split('.').reverse().splice(0,2).reverse().join('.'); document.cookie = name+'=; Max-Age=-99999999; Path=/;Domain='+ domainName; document.cookie = name+'=; Max-Age=-99999999; Path=/;Domain=.'+ rootDomainName; //esoteric case common to SalesNext document.cookie = name+'=; Max-Age=-99999999; Path=/;'; //Delete LSO incase LSO being used, cna be commented out. // localStorage.removeItem(name); sessionStorage.removeItem(name); //Check for the current path of the page pathArray = window.location.pathname.split('/'); //Loop through path hierarchy and delete potential cookies at each path. for (var i=0; i < pathArray.length; i++){ if (pathArray[i]){ //Build the path string from the Path Array e.g /site/login var currentPath = pathArray.slice(0,i+1).join('/'); document.cookie = name+'=; Max-Age=-99999999; Path=' + currentPath + ';Domain='+ domainName; document.cookie = name+'=; Max-Age=-99999999; Path=' + currentPath + ';'; //Maybe path has a trailing slash! document.cookie = name+'=; Max-Age=-99999999; Path=' + currentPath + '/;Domain='+ domainName; document.cookie = name+'=; Max-Age=-99999999; Path=' + currentPath + '/;'; } } } // container cookies are not a precise name match, handle them without that matcher function handleContainerCookie() { const cookieArray = document.cookie.split(';'); const containerCookies = cookieArray.filter(cookie => cookie.trim().startsWith('_ga_')); if(containerCookies.length > 0){ // at least one container cookie found. In case of multiple containers, doing loop for (let i=0; i < containerCookies.length; i++){ const containerName = containerCookies[i].substring(0, containerCookies[i].indexOf("=")); domainName = window.location.hostname; rootDomainName = domainName.split('.').reverse().splice(0,2).reverse().join('.'); document.cookie = containerName+'=; Max-Age=-99999999; Path=/;Domain='+ domainName; document.cookie = containerName+'=; Max-Age=-99999999; Path=/;Domain=.'+ rootDomainName; //esoteric case common to SalesNext } } } // use to delete third-party cookies, as domain will not match function deleteAlternateDomainCookie(name, domain) { document.cookie = name+'=; Max-Age=-99999999; Path=/;Domain='+ domain; document.cookie = name+'=; Max-Age=-99999999; Path=/;Domain=.'+ domain; //esoteric case common to SalesNext document.cookie = name+'=; Max-Age=-99999999; Path=/;'; } } setOneTrustByEnvironment();