How to fire GTM Tags with CookieScript events
If you are using Google Tag Manager to include external third-party scripts to your website, it's very easy to start complying with cookie regulations using CookieScript build-in integration with Google Tag Manager.
Note: This article explains how to implement CookieScript built-in events in Google Tag Manager. You can use those events to fire Tags.
You can also adjust Tag behavior based on the current Consent State variable. Or you can use build-in Google Consent Mode to change Tag firing conditions.
Why do I have to block third-party scripts?
In short, third-party scripts that you include on your website might track your website, visitors, behavior, and those scripts that might require user consent to be included (unless they are strictly necessary for your website to work). You can read more about third-party cookies here.
How do I block third-party scripts with Google Tag Manager?
CookieScript fires following GTM events:
CookieScriptCategory-strict - fires if the user agreed to Strictly necessary cookies or declines all cookies (which is technically the same)
CookieScriptCategory-functionality - fires if the user agreed to Functionality cookies
CookieScriptCategory-targeting - fires if the user agreed to Target cookies
CookieScriptCategory-performance - fires if the user agreed to Performance cookies
CookieScriptCategory-unclassified - fires if the user agreed to Unclassified cookies
CookieScriptCategory-all - fires only if the banner is set up to be used without categories and the user just clicks "Accept all" button
Step 1. Add the Cookie-Script Consent Banner Code Snippet on GTM
On the GTM dashboard go to the Tags section and click the New button.
Go to the Choose a tag type to begin set-up..., then select Custom HTML, place your copied Cookie-Script code snippet, then go the Choose a trigger to make this tag fire... and select All Pages, finally click Save.
Step 2. Create a Cookie-Script trigger for your third-party tag.
Go to the Triggers section and click the New button.
Click the Choose a trigger type to begin set-up..., then select Custom Events.
Choose Cookie-Script event, for example, CookieScriptCategory-targeting, which fires if the user selected/checked the "Targeting" checkbox category.
Step 3. Bind Cookie-Script trigger to appropriate Third-party code/library.
Go back to the Tag section and click the Choose a tag type to begin set-up..., then select Custom HTML, place your own or Third-party code snippet, then go the Choose a trigger to make this tag fire... select just created CookieScriptCategory-targeting trigger, and click Save.
Step 4. Test and preview your Website.
Now your Cookie-Script configuration and integration to GTM are done. Your website will from now unblock and load third-party scripts of the corresponding category only when the visitor select that one and gives their consent.