Repush dataLayer events that occurred before consent loaded.
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.
- Install the template from the community gallery
- Create a tag using the template.
- Set the tag to fire once per page.
- Add a trigger to fire the tag on the first event with consent.
Example:
![Screenshot 2024-05-06 at 20 09 12](https://private-user-images.githubusercontent.com/125863377/328274539-e521e325-cd73-479d-83b8-9ecc2bac9927.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYxNzYxOTEsIm5iZiI6MTcyNjE3NTg5MSwicGF0aCI6Ii8xMjU4NjMzNzcvMzI4Mjc0NTM5LWU1MjFlMzI1LWNkNzMtNDc5ZC04M2I4LTllY2MyYmFjOTkyNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMlQyMTE4MTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wMDhmNDE0MDA5NDQ3MDExZWUyOTkyNDE5NzllOThmNTY1ZWY4YzU4MGQwODkzZGEwY2MzODhhNmFjYWM3MmIxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.bgVrTn7VlwexH7sQQb57MmA_8ZWgDn9OOQ5FWUZB7ig)
- [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.
- [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](https://private-user-images.githubusercontent.com/125863377/328274050-65ed8dce-6f15-4d07-b615-b13ee2c39039.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYxNzYxOTEsIm5iZiI6MTcyNjE3NTg5MSwicGF0aCI6Ii8xMjU4NjMzNzcvMzI4Mjc0MDUwLTY1ZWQ4ZGNlLTZmMTUtNGQwNy1iNjE1LWIxM2VlMmMzOTAzOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMlQyMTE4MTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04OWZjNjYyYWQxYWQ3NTlkZWVhYTNjZDUwMzk1YmQ5OGM1ZTIxNzVkNzg0OTI4YWViMzg1ZDMzMDM4MTE4NjYyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.BTQfcpdWCYWwwEx2rgXQ-iYWU9hp3Jcs8LMIEjeFOPY)
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](https://private-user-images.githubusercontent.com/125863377/328273001-0c223f07-5970-4553-b6c9-15553d418e56.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYxNzYxOTEsIm5iZiI6MTcyNjE3NTg5MSwicGF0aCI6Ii8xMjU4NjMzNzcvMzI4MjczMDAxLTBjMjIzZjA3LTU5NzAtNDU1My1iNmM5LTE1NTUzZDQxOGU1Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkxMlQyMTE4MTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zZTI1YmM1NjFkYTc4ZTQxMTdiZTdlOTBhYjNiYmE5ZWRkNzgyYWJhOTIzYjQzZWZmNTdkMzgwYzFmOGI3N2VlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.BCCDqsC9Q4aq0p69nPxoJDa2_0ySavQ-TXKCvQxMNGU)
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.
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.
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.
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.