Created
September 27, 2018 04:22
-
-
Save peter-mcrae/579d0d0ca7dabb8d413958429a6c0729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script async="async" src=//consent.trustarc.com/notice?domain=tibco.com&c=teconsent&js=nj¬iceType=bb>m=1 crossorigin=""></script> | |
<script> | |
window.trustArcCookieCounter = 0; | |
window.firedTrustArcConsent = false; | |
//look for the existence of the trust arc cookie that indicates if it's implied or expressed consent | |
function checkForTrustArcCookie() { | |
//helper to read cookie values | |
var getCookieValue = function(a) { | |
var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)'); | |
return b ? b.pop() : ''; | |
} | |
//track how long the polling is run so that we can kill it if the page doesn't have the trust arc code on it | |
trustArcCookieCounter++; | |
if (!!document.cookie.match(/notice_behavior/)) { | |
var cookieValue = getCookieValue('notice_behavior'); | |
//if it's implied or if we have the users consent choices we can fire the event | |
if (cookieValue.indexOf('implied') >= 0 || !!document.cookie.match(/cmapi_cookie_privacy/)) { | |
//fire GTM event that will be used as a trigger for all tags that need to run immediately | |
window.firedTrustArcConsent = true; | |
analyticsDataLayer.push({ | |
event: 'TrustArc_HaveConsentChoice', | |
consentType: 'implied' | |
}); | |
} else { | |
//fire a GTM event in case we want to do anything at this point in the future | |
analyticsDataLayer.push({ | |
event: 'TrustArc_RequiresUserInput' | |
}); | |
} | |
//stop the polling | |
clearInterval(pollforTrustArcCookie); | |
} | |
//give up | |
if (trustArcCookieCounter > 75) { | |
clearInterval(pollforTrustArcCookie); | |
} | |
} | |
//start polling | |
var pollforTrustArcCookie = setInterval(checkForTrustArcCookie, 50); | |
//look for trust arc post messages | |
function tePostMessageHandler(msg) { | |
var data = msg.data; | |
console.log(msg); | |
try { | |
if (msg.origin === 'https://consent-pref.trustarc.com' && typeof msg.data !== "undefined" && JSON.parse(msg.data).message === 'submit_preferences') { | |
//fire the GTM event we can use to trigger tags that should run immediately after consent | |
//first check to make sure this hasn't already fired on the page so we don't double load | |
if (window.firedTrustArcConsent === false) { | |
window.firedTrustArcConsent = true; | |
analyticsDataLayer.push({ | |
event: 'TrustArc_HaveConsentChoice', | |
consentType: 'expressed' | |
}); | |
} | |
} | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
//start listening | |
window.addEventListener("message", tePostMessageHandler, false); | |
//hijack some existing divs just for testing. the trust arc script will be placed on the page before gtm.js | |
jQuery(function() { | |
jQuery("div.full-width.header").attr('id', 'consent_blackbar'); | |
jQuery("[href*='tibco-now-explore']").parent().attr('id', 'teconsent'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment