Listen to consent interaction
Below we will see how to listen to and use the events emitted by a consensus interaction. The interactions issued are linked to the following actions:
Event | Detail optin sent | Layers |
---|---|---|
Accept all | consent-all | First layer |
Reject all | reject-all | First layer |
Close banner | close-banner | First layer |
Save preferences | save-preferences | Second layer |
Example
Let's see how you can listen to the avacy_interaction
event and use it to send an event to Google Tag Manager.
window.addEventListener("avacy_interaction", function (event) {
window.dataLayer.push({
event: event.detail.optin,
});
});
Having an event to listen to allows us not to be tied to a particular analysis tool, but to be able to use any analysis tool that supports listening to events.