Skip to main content

Send an event by cookie step to Google Tag Manager

Written by Alexandre Dias Da Silva

You want to notify your Google Tag Manager container when all cookies in 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 tag

Did this answer your question?