Skip to main content

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:

EventDetail optin sentLayers
Accept allconsent-allFirst layer
Reject allreject-allFirst layer
Close bannerclose-bannerFirst layer
Save preferencessave-preferencesSecond 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.