-
-
Save stefanatcroud/cd103ecfabf7dbe37d6a13d01557775f to your computer and use it in GitHub Desktop.
Enable TrustArc integrations. Sends a "TrustArc Consent" data layer event, which contains "trustarc.consent" as a string indicating each consent status, much like how OneTrust reports consent updates.
This file contains 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> | |
var __i__ = self.postMessage && setInterval(function () { | |
if (self.PrivacyManagerAPI && __i__) { | |
var apiObject = { | |
PrivacyManagerAPI: | |
{ | |
action: "getConsentDecision", | |
timestamp: new Date().getTime(), | |
self: self.location.host | |
} | |
}; | |
self.top.postMessage(JSON.stringify(apiObject), "*"); | |
__i__ = clearInterval(__i__); | |
} | |
}, 50); | |
self.addEventListener("message", function (e, d) { | |
try { | |
if (e.data && (d = JSON.parse(e.data)) && (d = d.PrivacyManagerAPI) && d.capabilities && d.action == "getConsentDecision") { | |
var newDecision = self.PrivacyManagerAPI.callApi("getGDPRConsentDecision", self.location.host).consentDecision.toString(); | |
self.dataLayer && self.dataLayer.push( | |
newDecision==="0" ? {"event": "TrustArc Pre-Consent"} | |
: {"event": "TrustArc Consent", "trustarc": {"consent": newDecision}} | |
); | |
} | |
} catch (xx) { /** not a cm api message **/ } | |
}); | |
</script> |
Amazing, just what I needed as well.
Thanks for this 🙏
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea of this gist is to send a single data layer push containing the consent agreed as metadata within the push.