Code Monkey home page Code Monkey logo

backtrack's Introduction

backTrack

Repush dataLayer events that occurred before consent loaded.

Why use backTrack?

dataLayer events allow you to fire your tags at the right moment with the correct data. The timing becomes more complex when consent becomes involved. If your dataLayer push arrives before the consent management platform and Google Consent Mode (Basic) have initialised - functionality is needed to delay firing the respective tag.

Trigger groups are the feature available in GTM to handle this, but they are unwieldy and can lead to very messy setups. Some of the data associated with the event may also not be available when the trigger group fires.

backTrack is a template attempting to solve this issue and make handling event-timing a lot easier and more convenient.

How to use backTrack

  1. Install the template from the community gallery
  2. Create a tag using the template.
  3. Set the tag to fire once per page.
  4. Add a trigger to fire the tag on the first event with consent.

Example:

Screenshot 2024-05-06 at 20 09 12
  1. [Optional] Configure the REGEX for which events you want to re-push. By default GTM events and the most common consent events are excluded from being re-pushed. This is very important to prevent the consent state from being altered. To be explicit, change the REGEX to match the specific events you want to re-push.
  2. [Optional] Configure the prevent recursive merge feature by changing the setting to ‘On’ and adding any objects that should be cleared between events (for example ecommerce).

Example:

Screenshot 2024-05-06 at 20 06 35

Google Consent - Advanced Mode

Google Consent Mode (Advanced) has its own functionality to automatically fire events again after consent is granted (via the update command). backTrack will function for all tags as it is repushing events. To prevent duplicate events being sent, a blocking trigger needs to be added to all Google Tags when Consent Mode (Advanced only) is being used. The blocking trigger should fire on all events with pushType 'Artificial’.

Screenshot 2024-05-06 at 20 03 19

After the tag has finished re-pushing all events, it will set a dataLayer variable backTrack_fired with the boolean value true to indicate that the tag has already fired.

Safety Features

The template has in-built functionality to prevent multiple firings, as this could cause infinite loops. It is still worth explicity setting the tag to fire once per page.

backTrack_fired

After the tag has finished re-pushing all events, it will set a dataLayer variable backTrack_fired with the boolean value true to indicate that the tag has already fired.

A Note on Privacy

The aim of this template is not to track events that occurred before the user provided consent, rather to make handling the timing easier. A consent decision should be enforced by the banner before the user interacts with the page. If you have a single page application ensure that the entire page is reloaded when consent is changed - as this is needed to unload analytics/marketing libraries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.