The Cookiebot events work fine for tags that normally load as the page loads. For example, those using a Page View event:
For All pages you can replace the original event with one of the Cookiebot events:
For Some Pages you can combine one of the Cookiebot events with another condition. For example:
If we want a tag to fire when a page loads, where the URL includes "?lang=en", and the user has consented to preference cookies:
Page URL contains ?lang=en
Event equals cookie_consent_preferences
An important thing to note, is that Cookiebot events are pushed to the dataLayer at the time the script retrieves the consent state from the CookieConsent cookie, or at the time the user submits his or her consent.
Things become slightly more complicated when an event is triggered by an interaction, such as Click:
Or User Engagement:
To help understand why combining combining an event with a condition can be useful, it helps understanding what an event actually is.
Events are occurrences that can initiate actions. Normally, these actions only occur at the moment the event occurs. You could compare this to a sprint in athletics. The gunshot would be the event, which triggers the athletes to start sprinting.
Only when the event occurs does it illicit an action. In our athletics example, if an athlete for some reason didn't register the gunshot, he or she would stay in the starting block, still anticipating the gunshot.
In Google Tag Manager, events are pushed to an Array with Objects called the dataLayer. You can view this as a timeline, which Google Tag Manager uses to keep track of which events have occurred.
When all events have occurred that are part of the Trigger Group, the tag fires.
We can also define conditions that can be checked at the time an event occurs.
For example, in our athletics example, the gunshot won't cause everyone that perceives the gunshot to run, only the contestants.
If a contestant is in the starting block (the condition), when they hear the gunshot (the event), they start running.
However, for a trigger to fire, an event is needed. Merely meeting the condition doesn't initiate an action. Just like in our example, the athlete won't start running just because he or she is in the starting block, if not both the gunshot is heard, and the athlete is in the starting block, the athlete doesn't start running.
The same is true for Tags and Trigger Groups. For a Tag to fire, all events and conditions in the Trigger Group must be met.
To set a condition, which we can pair with an event, we can use the Cookiebot Consent State variable, which is available in the Template Gallery.
Take the Trigger (Group) you want to use and select This trigger fires on "Some Custom Events" and add one or several of these conditions:
Cookiebot Consent Statecontains preferences
Cookiebot Consent Statecontains statistics
Cookiebot Consent Statecontains marketing
If this variables return true at the time the event it's paired with occurs, the trigger fires.
Here's an example of a simple Trigger Group for a tag which should ONLY fire, if an element is clicked with an id attribute with the value "submit", AND if consent has been given for statistical cookies:
Click ID equals submit
Cookiebot.consent.statistics equals true