How to install CookieScript with Google Tag Manager
How to install CookieScript with Google Tag Manager?
This guide will explain how to install CookieScript with Google Tag Manager.
If you implement Google consent mode according to the instructions below, the consent mode
default command will load before Google tags fire. Google tags will fire based on your selection of Basic or Advanced consent mode implementation.
For troubleshooting missing Consent Mode or TCF signals on Google tags, clients should first contact the CMP support, as specified by Google.
You can also watch a video about how to implement Google Consent Mode v2 using CookieScript and Google Tag Manager:
The easiest way to implement Google Consent Mode on your website is by using a CookieScript Google Tag Manager (GTM) Tag template.
First, create your GTM account and a website container in GTM, and install the GTM container to your website, where you could add your tags. Read the guide on how to create a GTM account and install the GTM container.
Second, install CookieScript. There are 2 ways to deploy CookieScript with Google Tag Manager: using CookieScript GTM Template or as a custom HTML Tag. See instructions for each case below and choose which one suits you best. Remember to only use one of those deployment options.
It is assumed that you have already had experience with GTM and your GTM account is created, also you created a website container in GTM and added the GTM container snippet to your website as required: https://support.google.com/tagmanager/answer/6103696.
Note: If you implemented your cookie banner using a GTM tag template, the Google Ads script should also be implemented using a GTM tag template. Also, make sure that you use a trigger, which sets the Google Ads script after the trigger Consent initialization. If you implemented your cookie banner using a GTM tag template, and implemented the Google Ads script manually, your Ads script will not work.
If you implemented your cookie banner manually, implement the Google Ads script manually as well. Just make sure that your cookie banner script loads first, and only then- the Google Ads script.
1. Installing the CookieScript using GTM Tag Template (recommended)
This deployment method should be used if you want to use Google Consent Mode. It comes with all the necessary default consent state settings and code, so you don't need to worry about writing a single line of code.
To install CookieScript using a GTM Tag template, follow the steps below:
Step 1: Go to Tags and click New
Step 2: Fill in the name and click on the Tag Configuration area:
Step 3: Click on the link to show Community Template Gallery and search for CookieScript:
Step 4: Click Add to Workspace and confirm your choice.
Step 5: Configure the banner according to your needs: fill in your Cookie Banner script URL (can be found in the banner settings > Installation tab) and choose the default consent state (which is applied before the user makes any selection):
Step 6: As a firing trigger choose Consent Initialization - All Pages. It's important to have this specific trigger since it is fired before any other tags and ensures proper work of the Tag.
All done, your banner is now ready. Just publish the changes and you are ready to go.
2. Installing the CookieScript as a Custom HTML Tag (not recommended)
This type is useful if you don't want to use Google Consent Mode. This way no default state for Consent Mode will fire and the script will be inserted just as a Custom HTML Tag.
In your GTM Workspace create a new tag by clicking New tag > Custom HTML Tag. In the HTML field, insert CookieScript code copied from your item. The code should look similar to the one below:
<!--Start Cookie Script--><script type="text/javascript" charset="UTF-8" src="http://cdn.cookie-script.com/s/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.js"></script> <!--End Cookie Script-->
Next, click Add trigger choose DOM Ready, and apply a name to your tag.
Your final tag configuration window should look like this. (A unique number of .js files have been changed ):
At the end, click "Publish" to apply your changes to your website.
3. How to configure third-party scripts in GTM?
After you have added the CookieScript popup to your website you might need to configure some third-party scripts to be loaded only after the user's consent. This is needed to block third-party cookies. Fortunately, CookieScript has a built-in integration with Google Tag Manager events which allows you to set all the triggers and tags in your GTM account. You can find detailed instructions in our manual for disabling third-party scripts using GTM. Or you can use Google Consent Mode to adjust Tag firing conditions. Hey, we even have created a custom GTM Variable Template to read current consent state.
See also:
How to implement Google Consent Mode v2 with GTM or manually?
How to check if Google Consent Mode v2 is implemented correctly?
Did this answer your question?