Skip to main content

Set up preventative blocking via Google Tag Manager

Below are instructions for configuring preventative tag blocking through Google Tag Manager.

Configuration

Avacy provides an avacy_consent event in two circumstances: page loading (page_load) or changing and saving banner preferences (consent_update). The event contains details regarding the banner's data layers.

To handle the avacy_consent event, you can create a custom HTML tag on Google Tag Manager, with All Pages trigger and write some Javascript code inside it. This is an example of how you can use Javascript to listen to the event and insert data that we may need into the dataLayer (such as, in this case, the supplier identifier):

<script>
window.addEventListener('avacy_consent',  function(event)  {
  if  (event.detail.customVendorsWithConsent)  {
    event.detail.customVendorsWithConsent.forEach(function(element){
        window.dataLayer.push({
          event:  'avacy_custom_vendor_'  +  element.id
        });
      })
  }

  if  (event.detail.iabVendorsWithConsent)  {
    event.detail.iabVendorsWithConsent.forEach(function(element){
        window.dataLayer.push({
          event:  'avacy_iab_vendor_'  +  element.id
        });
      })
  }
})
</script>

The next step is to create a trigger based on one of the events that have been inserted into the dataLayer via this script, such as avacy_custom_vendor_:id. This trigger must then be associated with the tag you want to block, so that the tag is only activated if the user has given consent for that specific provider. In other words, the tag will fire only when the appropriate consensus event is present in the dataLayer.

Testing

Once you have set the tags and their triggers, open the preview and the Tag Assistant; from the preview it is possible to opt-in by accepting all cookies, or select only the purposes and supplier specified in the tag attributes.

From the Tag Assistant, however, it is important that the avacy_consent_update event is intercepted and, if the purposes and suppliers are checked, also the avacy_custom_vendor_:id event (or avacy_iab_vendor if the supplier to be checked is in the section Third Parties IAB).

By selecting the event from the Tag Assistant, the tag (or tags) whose execution was associated with the avacy_custom_vendor_:id trigger will appear in the right pane.

If the script runs only after you have given your consent, pre-blocking has been configured correctly.