Last active
August 30, 2024 20:49
-
-
Save hyebahi-trustarc/4e6cac855217ebe7beb0537915130e5f to your computer and use it in GitHub Desktop.
CMP - Generic Event Listener
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
window.addEventListener("message", (event) => { | |
let eventDataJson = null; | |
// We only care about TrustArc Events at this point. And TrustArc's even it encoded in JSON | |
try { | |
eventDataJson = JSON.parse(event.data); | |
} catch { | |
// Some other event that is not JSON. | |
// TrustArc encodes the data as JSON | |
// console.log(event.data); | |
} | |
// Safeguard to make sure we are only getting events from TrustArc | |
if (eventDataJson && eventDataJson.source === "preference_manager") { | |
// Means that the user has submited their preferences | |
if (eventDataJson.message === "submit_preferences") { | |
// Reload the page | |
//window.location.reload() | |
} | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment