Features
Block Third-Party Cookies With Google Tag Manager (GTM)
CookieYes automatically blocks third-party cookies on your website prior to obtaining user consent. But if you use Google Tag Manager to add third-party scripts to your website, you will need to ensure that your site blocks all cookies that are set via GTM but have not been consented to use. In this article, we will show you how to block cookies with Google Tag Manager and CookieYes.
If, for instance, you have added a functional cookie script to your GTM account, and if a user visiting your website gives consent to only Analytics cookies, ideally your site should block all the other types of cookies.
But in this case, the Functional cookies will also possibly get triggered. The reason behind this is that when you enable Analytics cookies, it will trigger the Google Tag Manager, which would, in turn, trigger all the other cookie scripts set via GTM.
To avoid this issue, you will have to create an appropriate custom event trigger in your GTM account. Here’s an example of how you can block third-party cookies with Google Tag Manager.
Creating a custom event trigger in GTM
The following are the steps to create a custom event trigger in Google Tag Manager that helps CookieYes block third-party cookie scripts on your website (set via GTM) prior to receiving user consent.
Note |
Step 1: Create a user-defined variable
- Sign in to your Google Tag Manager account > Click the required Container Name from your Accounts.
- From the left panel, select Variables > In the User-Defined Variables section, click New.
- Name the variable > Click Variable Configuration > Choose variable type as 1st Party Cookie from under Page Variables.
- In the Cookie Name text box, enter the name of that cookie for which you need to retrieve the value.
e.g. cookieyes-functional - Click Save to save the variable.
Step 2: Create a custom event trigger
- From the left panel of your GTM account, select Triggers > In the Triggers section, click New.
- Name the Trigger > Click Trigger Configuration > Choose trigger type as Custom Event.
- In the Event Name text box, enter the .* regular expression and check the Use regex matching option.
- Under This trigger fires on, choose Some Custom Events.
- Under Fire this trigger when an Event occurs and all of these conditions are true, set up a trigger condition.
e.g. Tawk.to trigger variable (i.e. the name of the user-defined variable that you have created in Step 1), equals, and yes. - Click Save to save the custom event trigger.
Step 3: Add the custom event trigger to the required custom HTML tag
- From the left panel of your GTM account, select Tags > Click the Tag name that needs to be fired.
- Click Triggering.
- Choose the custom event trigger that you have created in Step 2.
- Click Save.
Step 4: Submit changes
- Click the Submit button at the top right corner of your GTM account.
- Finally, click Publish to make this tag live on your website.
Once you have done these steps, your site visitors will not have Functional cookies running in the background after enabling Analytics cookies and disabling Functional cookies.
Now, take a look at how a website’s cookie installation differs before and after adding the custom event trigger in GTM.


We hope you understood how to block cookies with Google Tag Manager.
Try CookieYes and make your website GDPR and CCPA compliant for cookies.