# Block Third-Party Cookies With Google Tag Manager (GTM)

> For the complete site index, see [llms.txt](/llms.txt). Every page is also available as Markdown: replace the trailing slash with `.md` (`/pricing/` becomes `/pricing.md`), or send `Accept: text/markdown` to the page URL itself.

If you use Google Tag Manager to add third-party scripts to your website, learn how to block cookies with GTM & CookieYes before user consent.

---

**Categories:** Integrations Documentation, Features Documentation
**Last updated:** June 5, 2025
**Image:** https://assets.cookieyes.com/logo_5e63644c04.png
**URL:** https://www.cookieyes.com/documentation/block-third-party-cookies-with-google-tag-manager-and-cookieyes/

---

[CookieYes](https://www.cookieyes.com/) automatically blocks third-party cookies on your website prior to obtaining user consent. However, if you’re using [Google Tag Manager](https://tagmanager.google.com/) 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.

> **Note:**

> For blocking third-party cookies with Google Tag Manager in the older version (multiple cookies) of CookieYes, refer to our [guide](https://www.cookieyes.com/documentation/block-third-party-cookies-with-google-tag-manager-gtm-old-version/). 
>

## Creating a custom event trigger in GTM

The following are the steps to create a custom event trigger in GTM 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 an Analytics cookie script (added to your [GTM account](https://tagmanager.google.com/#/home)) 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***.
![select-container.png](https://assets.cookieyes.com/select_container_58e036bbbb.png)
2. From the left panel, select **Variables** > In the **User-Defined Variables** section, click **New**.
![variables.png](https://assets.cookieyes.com/variables_f6d4f862b7.png)
3. Click **Variable Configuration** > Choose variable type as **1st Party Cookie** from under **Page Variables**.
![first-party-cookie.png](https://assets.cookieyes.com/first_party_cookie_2d7ce297d9.png)
> **Note:**
>  1st Party Cookie variable allows Google Tag Manager to access the first-party cookies created by your website.
![cookieyes-consent-cookie.jpg](https://assets.cookieyes.com/cookieyes_consent_cookie_a0bd3f2ca0.jpg)
> *Cookies installed by the site — are displayed under the Application tab of the Developer console*
> .
4. In the Cookie Name text box, enter the name of the cookie for which you need to retrieve the value. *e.g. cookieyes-consent*
5. Name the variable (here, we’ve named it ‘Analytics’) and click **Save** to save the variable.
![name-cookie.png](https://assets.cookieyes.com/name_cookie_38450c61b3.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](https://assets.cookieyes.com/trigger_1e41f14b99.png)
2. Click **Trigger Configuration** > *Choose**** Custom Event ***as the trigger type.
![custom-event.png](https://assets.cookieyes.com/custom_event_cc41136b31.png)
3. In the Event Name text box, enter cookie_consent_update as shown below and check the Use regex matching option.
![update-event.png](https://assets.cookieyes.com/update_event_acc34f205b.png)
> **Note**
> : For users who have disabled the 
> **Support GCM**
>  option in CookieYes, please enter the event name as '.*'.
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. Analytics Trigger (i.e. the name of the user-defined variable that you have created in Step 1), contains, and analytics:yes (as shown below).
![analytics-trigger.jpg](https://assets.cookieyes.com/analytics_trigger_875504df33.jpg)
6. Name the Trigger (we’ve named it ‘Analytics Trigger’) and click **Save** to save the custom event trigger.

## Step 3. Add the custom event trigger to the required tag

Now edit the tag configuration that is responsible for loading third-party scripts to include the trigger you created in the previous step. Follow these steps:
1. From the left panel of your GTM account, select **Tags** > Click the Tag name that needs to be fired. Here it is, Analytics Tag.
2. Click **Triggering**.
3. Choose the custom event trigger that you have created in ***Step 2***.
4. Then click Save.

## Step 4: Submit changes

1. Click the Submit button at the top right corner of your GTM account. 
![submit-tag.jpg](https://assets.cookieyes.com/submit_tag_86c847d4df.jpg)
2. Finally, click [Publish](https://support.google.com/tagmanager/answer/6107163?sjid=13321911949618766862-AP) to make this tag live on your website.
![publish-tag.png](https://assets.cookieyes.com/publish_tag_91eb1e04f9.png)

## Step 5: Verify integration

To [preview and debug](https://support.google.com/tagmanager/answer/6107056?sjid=13321911949618766862-AP) your website, click the **Preview** button at the top right corner of your GTM account. For more instructions, follow Google's guide to [check if you've blocked tags](https://support.google.com/google-ads/answer/12962079?hl=en&sjid=16157904163159706065-AP#:~:text=How%20to%20check%20if%20you%20have%20blocked%20tags).
![preview.png](https://assets.cookieyes.com/preview_186f329629.png)
CookieYes and GTM integration is now complete. Your website will unblock and load third-party scripts only when visitors select a specific category and provide their consent.


---

## Structured Data

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Article",
      "headline": "Block Third-Party Cookies With Google Tag Manager (GTM)",
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://www.cookieyes.com/documentation/block-third-party-cookies-with-google-tag-manager-and-cookieyes/"
      },
      "url": "https://www.cookieyes.com/documentation/block-third-party-cookies-with-google-tag-manager-and-cookieyes/",
      "publisher": {
        "@type": "Organization",
        "name": "CookieYes",
        "url": "https://www.cookieyes.com",
        "logo": {
          "@type": "ImageObject",
          "url": "https://www.cookieyes.com/cookieyes-logo.png",
          "width": 2048,
          "height": 2048
        }
      },
      "description": "If you use Google Tag Manager to add third-party scripts to your website, learn how to block cookies with GTM & CookieYes before user consent.",
      "datePublished": "2020-10-15T06:31:19+00:00",
      "dateModified": "2025-06-05T00:00:00+00:00",
      "author": {
        "@type": "Person",
        "name": "CookieYes Doc Team"
      },
      "image": [
        "https://assets.cookieyes.com/logo_5e63644c04.png"
      ]
    },
    {
      "@type": "BreadcrumbList",
      "@id": "https://www.cookieyes.com/documentation/block-third-party-cookies-with-google-tag-manager-and-cookieyes/#breadcrumb",
      "itemListElement": [
        {
          "@type": "ListItem",
          "position": 1,
          "name": "Home",
          "item": "https://www.cookieyes.com/"
        },
        {
          "@type": "ListItem",
          "position": 2,
          "name": "Documentation",
          "item": "https://www.cookieyes.com/documentation/"
        },
        {
          "@type": "ListItem",
          "position": 3,
          "name": "Features Documentation",
          "item": "https://www.cookieyes.com/category/documentation/features/"
        },
        {
          "@type": "ListItem",
          "position": 4,
          "name": "Integrations Documentation",
          "item": "https://www.cookieyes.com/category/documentation/features/integrations/"
        },
        {
          "@type": "ListItem",
          "position": 5,
          "name": "Block Third-Party Cookies With Google Tag Manager (GTM)",
          "item": "https://www.cookieyes.com/documentation/block-third-party-cookies-with-google-tag-manager-and-cookieyes/"
        }
      ]
    },
    {
      "@type": "WebSite",
      "@id": "https://www.cookieyes.com/#website",
      "url": "https://www.cookieyes.com/",
      "name": "CookieYes",
      "description": "CookieYes is a Google-certified consent management platform that helps businesses comply with GDPR, CCPA, and other global privacy laws.",
      "inLanguage": "en-US",
      "publisher": {
        "@id": "https://www.cookieyes.com/#organization"
      },
      "potentialAction": {
        "@type": "SearchAction",
        "target": {
          "@type": "EntryPoint",
          "urlTemplate": "https://www.cookieyes.com/?s={search_term_string}"
        },
        "query-input": {
          "@type": "PropertyValueSpecification",
          "valueRequired": true,
          "valueName": "search_term_string"
        }
      }
    },
    {
      "@type": "Organization",
      "@id": "https://www.cookieyes.com/#organization",
      "name": "CookieYes",
      "url": "https://www.cookieyes.com/",
      "logo": {
        "@type": "ImageObject",
        "@id": "https://www.cookieyes.com/#/schema/logo/image/",
        "inLanguage": "en-US",
        "url": "https://www.cookieyes.com/cookieyes-logo.png",
        "contentUrl": "https://www.cookieyes.com/cookieyes-logo.png",
        "width": 2048,
        "height": 2048,
        "caption": "CookieYes"
      },
      "image": {
        "@id": "https://www.cookieyes.com/#/schema/logo/image/"
      }
    }
  ]
}
```
