How to install CookieScript with Google Tag Manager

How to install CookieScript with Google Tag Manager

Written by NelsonLast update 1 month ago

You can easily install CookieScript via Google Tag Manager (GTM) by following these step-by-step instructions.

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:

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.

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=""></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 ):

In the end, click "Publish" to apply your changes to your website.

Configuring Third-party Scripts in Google Tag Manager

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, Cookie-Script 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.

Checklist for the correct implementation of Google Ads and Google Consent Mode

  1. Google Consent Mode is enabled in settings.
    See the guide about how to enable Google Consent Mode.

  2. CookieScript is installed in GTM using the latest template from gallery.
    See the guide about how to update the GTM template.

  3. CookieScript trigger is set to Consent Initialization (AND no other tags in that trigger)

  4. GA trigger is set to Initialization
    The right GA trigger should look like this:

    The common mistake is the wrong GA trigger selected like in this example:

  5. Clear browser Cache

  6. Use preview mode to see how it works. Link to debugger info.

Note: There is no need to modify the google tag code, just enable the Google Consent Mode in the settings and Google will handle it.

How to know if CookieScript is implemented correctly?

When you installed the CookieScript, go to your account > Settings, where at the top of the page you will find information about your banner status. Wait until the scan finishes, then the banner status will be updated:

Did this answer your question?