> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cookiechimp.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Tag Manager

> Set up a consent banner with Google Tag Manager and Google Consent Mode.

## How do I install the CookieChimp script?

You can install CookieChimp two ways. **Direct HTML is the recommended approach** — it guarantees CookieChimp loads before Google Tag Manager and any other scripts, so it can set consent defaults before any tag fires.

<Tabs>
  <Tab title="Direct HTML (Recommended)">
    Add your website's CookieChimp JS snippet at the top of the `<head>` tag in your HTML, **before** the Google Tag Manager script and any other scripts.

    ```html theme={null}
    <script src="https://cookiechimp.com/widget/abc123.js"></script>
    ```

    Replace `abc123` with your website's unique CookieChimp ID.

    <Snippet file="install/script-first-warning.mdx" />
  </Tab>

  <Tab title="Via Google Tag Manager">
    If you can't edit your site's HTML directly, you can install CookieChimp through GTM. Fire it from the **Consent Initialization - All Pages** trigger — this is the earliest trigger GTM exposes, so it gives CookieChimp the best chance of loading before other tags.

    <Warning>
      **This method does not guarantee strict ordering.** The Consent Initialization trigger controls when GTM **injects** the CookieChimp `<script>` tag — but the external script still has to download and execute asynchronously. On slower networks, other tags fired by Initialization or Page View triggers can run before CookieChimp has set its consent defaults, which can lead to cookies being set without consent.

      If strict ordering matters (and for GDPR compliance it usually does), use the **Direct HTML** method instead.
    </Warning>

    **To add CookieChimp via GTM:**

    1. In your GTM workspace, create a new tag and choose **Custom HTML**.
    2. Paste the CookieChimp script into the tag:

       ```html theme={null}
       <script src="https://cookiechimp.com/widget/abc123.js"></script>
       ```

       Replace `abc123` with your website's unique CookieChimp ID.
    3. For the trigger, select **Consent Initialization - All Pages**.
    4. Save the tag and **publish** your container.

    <Tip>
      You can reduce the async-download race by configuring **Tag Sequencing** on your other tags so they wait for the CookieChimp tag to finish, or by gating downstream tags on the `cookiechimp_consent_update` custom event (covered in the section below). Direct HTML remains the most reliable option.
    </Tip>
  </Tab>
</Tabs>

## How do I block tags with Google Tag Manager?

<Steps>
  <Step title="Enable Google Consent Mode">
    Navigate to "Integrations" from the sidebar and enable the Google Consent Mode integration.

    <img src="https://mintcdn.com/identitysquare/PNp7zvpuSh_GT_4M/images/google-tag-manager/enable-gcm.png?fit=max&auto=format&n=PNp7zvpuSh_GT_4M&q=85&s=cb911dfa27fd7be89f16584a1838ba36" alt="Enable GCM" width="2880" height="1695" data-path="images/google-tag-manager/enable-gcm.png" />
  </Step>

  <Step title="Add/Edit Tag">
    Create or update a tag and add an additional consent check so the tag only fires once the matching vendor has consent.

    Navigate to "Advanced Settings" > "Consent Settings". Select "Require additional consent for tag to fire" and enter the name of the category or service that the tag needs to fire on.

    <img src="https://mintcdn.com/identitysquare/PNp7zvpuSh_GT_4M/images/google-tag-manager/consent-settings.png?fit=max&auto=format&n=PNp7zvpuSh_GT_4M&q=85&s=5173c5d3c6e2741d4bd17b4c84a776ad" alt="Consent Settings" width="2880" height="1692" data-path="images/google-tag-manager/consent-settings.png" />

    <Tabs>
      <Tab title="Recommended">
        Enter the exact vendor name as it appears in your CookieChimp [Vendor Library](/features/vendor-management#what-are-vendors), e.g `Google Analytics`, `Hotjar`, or `Facebook Pixel`. CookieChimp sends the consent state of each vendor to Google, so the tag will only fire when that specific vendor has been granted consent in the banner.

        This is the recommended approach because your visitors can opt in or out of individual vendors inside a category, and a tag should usually only fire when its own vendor is allowed, not just when the broader category has consent.

        <Tip>The vendor name must match the name configured in your CookieChimp Vendor Library exactly, including capitalisation and spacing.</Tip>
      </Tab>

      <Tab title="Alternative">
        If you'd rather scope the additional consent to a whole category (so the tag fires whenever any vendor in that category has consent), you can use one of the Google consent types that CookieChimp maps your categories to. For example `analytics_storage` for the `analytics` category. See [the mapping below](#how-does-cookiechimp-map-to-google-consent-types) for the full list.
      </Tab>
    </Tabs>
  </Step>

  <Step title="Add a custom trigger">
    This is required to listen for changes in consent state. This event will be triggered by CookieChimp on page load and when the user changes their consent settings.

    <img src="https://mintcdn.com/identitysquare/PNp7zvpuSh_GT_4M/images/google-tag-manager/add-trigger.png?fit=max&auto=format&n=PNp7zvpuSh_GT_4M&q=85&s=992a3d9ee399b4025731f41c724b81c1" alt="Add Trigger" width="1440" height="895" data-path="images/google-tag-manager/add-trigger.png" />

    Choose "Custom Event"

    <img src="https://mintcdn.com/identitysquare/PNp7zvpuSh_GT_4M/images/google-tag-manager/choose-trigger.png?fit=max&auto=format&n=PNp7zvpuSh_GT_4M&q=85&s=381f913f8c71333f4895476370c4f983" alt="Choose Custom Event" width="2845" height="1800" data-path="images/google-tag-manager/choose-trigger.png" />

    Set up the custom trigger with event name `cookiechimp_consent_update` and save the tag.

    <img src="https://mintcdn.com/identitysquare/PNp7zvpuSh_GT_4M/images/google-tag-manager/create-custom-trigger.png?fit=max&auto=format&n=PNp7zvpuSh_GT_4M&q=85&s=f24317998c8492da59e935b7424253f2" alt="Create custom trigger" width="2400" height="1200" data-path="images/google-tag-manager/create-custom-trigger.png" />
  </Step>
</Steps>

This tag is now set up and will only fire when the required consent is granted.

## How does CookieChimp map to Google consent types?

GTM supports 7 different default consent types. CookieChimp maps these Google consent types into the following categories:

| CookieChimp Category ID | Google Consent Type                              |
| ----------------------- | ------------------------------------------------ |
| essential               | functionality\_storage, security\_storage        |
| marketing               | ad\_storage, ad\_user\_data, ad\_personalization |
| analytics               | analytics\_storage                               |
| personalization         | personalization\_storage                         |

These categories are setup by default. When a user opts-in to a consent category or a Google service in the category is consented to, the linked Google consent type will change from 'denied' to 'granted' and vice versa.

Apart from the default 7 consent types, we will also send the consent state of your services to Google. For example, when a user consents to a service named "Hotjar", the consent state for this service is updated as 'granted'. This is what allows you to use the vendor name directly in a tag's "Require additional consent for tag to fire" setting (the recommended approach in the [Add/Edit Tag](#how-do-i-block-tags-with-google-tag-manager) step), so the tag only fires when that specific vendor has been granted consent and not just the broader category.
