Block Third-Party Cookies With Tag Manager (GTM)

Last updated on March 9, 2026

CookieYes automatically blocks third-party cookies on your website prior to obtaining user consent. However, if you're using Google Tag Manager to add third-party scripts to your website, you may want to block cookies set via GTM that have not been consented to use. For this, you will have to create an appropriate custom event trigger in your GTM account. Here’s an example of blocking third-party cookies with Google Tag Manager.

For blocking third-party cookies with google tag manager in the new version(Single Cookie) of CookiesYes refer to our guide.

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.

For better understanding, throughout this guide, let’s consider the case of blocking a Functional cookie script (added to your GTM account) until you obtain user consent.

Step 1: Create a user-defined variable

  1. Sign in to your Google Tag Manager account > Click the required Container Name from your Accounts.
  2. From the left panel, select Variables > In the User-Defined Variables section, click New.variables.png
  3. Click Variable Configuration > Choose variable type as 1st Party Cookie from under Page Variables.
    Note: 1st Party Cookie variable allows Google Tag Manager to access the first-party cookies created by your website.
    inspect wth 1st party cookies.png
  4. In the Cookie Name text box, enter the name of that cookie for which you need to retrieve the value. E.g. cookieyes-functional
  5. Name the variable (here, we’ve named it ‘Live Chat Trigger Variable’) and click Save to save the variable.cookieyes functional naming cookie variable.png

Step 2: Create a custom event trigger

  1. From the left panel of your GTM account, select Triggers > In the Triggers section, click New.trigger.png
  2. Click Trigger Configuration > Choose Custom Event as the trigger type.custom-event.png
  3. In the Event Name text box, enter .* as shown below and check the Use regex matching option.naming trigger event.png
  4. Under This trigger fires on, choose Some Custom Events.
  5. Under Fire this trigger when an Event occurs and all of these conditions are true, set up a trigger condition.e.g. Live Chat Trigger Variable (i.e. the name of the user-defined variable that you have created in Step 1), equals, and yes (as shown below)google-tag-manager-trigger-condiiton-save-trigger-name.png
  6. Name the Trigger (we’ve named it ‘Live Chat Trigger’) and click Save to save the custom event trigger.

Step 3: Add the custom event trigger to the required custom HTML tag

  1. From the left panel of your GTM account, select Tags > Click the Tag name that needs to be fired.google-tag-manager-open-tag.png
  2. Click Triggering.google-tag-manager-clikc-to-add-tag.png
  3. Choose the custom event trigger that you have created in Step 2.google-tag-manager-choose-live-chat-trigger.png
  4. Click Save.google-tag-manager-click-save-to-save-the-tag-trigger.png

Step 4: Submit changes

  1. Click the Submit button at the top right corner of your GTM account.google-tag-manager-submit-tag.png
  2. Finally, click Publish to make this tag live on your website.google-tag-manager-publish-the-tag.png

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 your website’s active cookies before and after adding the custom event trigger in GTM.

Website

Before adding the custom event trigger in GTM

Website

After adding the custom event trigger in GTM

This is how you can block cookies with Google Tag Manager.

Was this article helpful?

Have more questions?

Reach out to us and we'll answer them.

Contact us