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 Cookie-Script build-in integration with Google Tag Manager.
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?
You can use build-in Cookie-Script GTM events to trigger certain scripts' inclusion. Cookie-Script also has custom events that can be used without GTM as documented here.
Cookie-Script fires following GTM events:
CookieScriptCategory-functionality - fires if the user agreed to Functionality cookies
CookieScriptCategory-strict - fires if the user agreed to Strictly necessary cookies
CookieScriptCategory-targeting - fires if the user agreed to Targeting cookies
CookieScriptCategory-performance - fires if the user agreed to Performance cookies
CookieScriptCategory-unclassified - fires if the user agreed to Unclassified cookies
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.