Skip to main content

Send a cookie step event to Google Tag Manager

Manon Manso avatar
Written by Manon Manso
Updated over 10 months ago

Do you want to notify your Google Tag Manager container when all the cookies from a step have been accepted, in addition to the events sent for each cookie? Here's how to do it!

First, you will need to load this script:

window.dataLayer = window.dataLayer || [];
window._axcb = window._axcb || [];
window._axcb.push(function(sdk){
sdk.on('cookies:complete', function(choices){
const steps = sdk.config.cookies[0].steps;
const cookiesSteps = steps.splice(1, steps.length);
cookiesSteps.forEach(step => {
const vendors = step.vendors;
let allAccepted = true;
vendors.forEach(vendor => {
const choice = choices[vendor.name];
if(choice === false || choice === undefined){
allAccepted = false;
}
});
if(allAccepted === true){
dataLayer.push({'event': step.name + '_accepted'});
}
});
});
});

You can add this script after your Axeptio script, or in a separate <script> tag. Since this script is asynchronous, you don't need to load it in a specific place.

Once the script is added, the events will be automatically sent to Google Tag Manager, based on the identifier of the accepted step. For example:

Capture d’écran 2023-12-12 à 10.49.36.png

Here, the sent event will be "analytics_accepted".

🍪 For information screens, their identifier is set by default to the value "info" and cannot be changed. In this case, the sent event will therefore always be "info_accepted".

Did this answer your question?