Google Tag Manager is based upon having tags that are fired on triggers. These triggers are defined as an event occurring on the website, like the user clicking a button or visiting a certain URL.
Note: When using the Cookie Control SDK within GTM, the pop-up MUST be implemented in the source-code above the GTM script. If not the combination of trigger events will fail.
Settings up the triggers
The most common trigger in GTM is PAGE VIEW. This trigger when set to, all pages will fire the tag on all page of the website.
Our Cookie Control SDK will upon consent from the user, push out each cookie category the GTM's DataLayer. These can be used to check against in the trigger as a CUSTOM EVENT.
By default, there are 3 cookie categories which the users can consent to:
These will also serve as an event name for the triggers.
Setting up triggers
1. Navigate to the main dashboard, click "Triggers" section, and select "New"
2. Select CUSTOM EVENT trigger from the list
3. Fill in the required inputs:
Use one of the existing cookie categories listed above as the trigger's event name, e.g. "cookie_cat_statistic"
The trigger itself, however, does not need to use the category name.
4. Repeat the steps above for all individual cookie categories to cover all the possible
choices of the end-user.
Remember that a trigger's event name is a key-value, while the name of the trigger can be set according to your preferences and will not affect the trigger’s functionality.
When to use a Custom Event as a trigger
If for instance, you have a Google Analytics Tag that must fire on all pages of your website, you would previously add a PAGE VIEW trigger, but instead, you must add the CUSTOM EVENT trigger (cookie_cat_statistic). As long as the user has consented to that category, the Tag will fire on all pages, because the DataLayer itself is present on all pages.
- A tag can be called using a number of triggers. If more than one trigger is added, Google
Tag Manager will require at least one of them to fire to execute the tag.
- Additionally, you can set how many times a tag can be triggered per a client’s visit.
- Remember to publish your changes or the tag will not work as expected.
When you can't use a custom event (Important!)
Some Tags can't take custom events as a trigger. eg. click elements or click links. Also when you can't have a trigger with more that one Custom Event on.
This example will NOT WORK, because there are more than one custom event defined: eventNumber1 and cookie_cat_statistic
Change the cookie category accordingly
The function will return TRUE or FALSE
This can then also be used in combination with trigger based on Custom Events
- Not having the pop-up script implemented before GTM.
The pop-up script must be implemented in the source-code before the GTM-script
- Having more than one trigger on the same tag.
Eg. All Pages and a Custom Event. Only one of these triggers has to be true before the tag is fired. This means that the Custom event is rendered invalid.
- Having Type errors
The data-layer is case-sensitive, so be aware to type categories correctly.