Article
OneTrust + Google Tag Manager: How Cookie Categories Control Tags
Installing a OneTrust banner doesn’t mean every script on your site respects the visitor’s consent choices. The banner collects preferences. Your website, and your Google Tag Manager (GTM) container, must then apply them to analytics, advertising, embeds, and other optional technology.
This guide explains how OneTrust cookie categories control GTM tags. It covers the OnetrustActiveGroups variable, category-based triggers, consent changes, Google Consent Mode, and how to test the result.
Why Use Google Tag Manager for Consent Management?
A website may use Google Analytics, advertising pixels, conversion tracking, customer-support tools, and more. Each service needs a script or tracking tag. Without a central approach, those scripts end up scattered across theme files, plugins, and header settings. That makes it hard to know what loads, when it loads, and which consent category should control it.
GTM gives you one place to manage tags and their firing rules. Once the container is installed, many tag changes can be made there without editing your templates. Some implementations still need development work to supply the events and data those tags rely on.
For consent, the main advantage is visibility. You can review the tags in the container, identify their purpose, and check the conditions that allow each one to run.
GTM is optional. OneTrust can also work with scripts loaded directly by your website. GTM is most useful when you want to manage several tracking services and their rules together.
How Do OneTrust and GTM Work Together?
The integration follows a sequence:
- OneTrust establishes the visitor’s current consent preferences.
- The integration makes those preferences available to GTM.
- GTM evaluates the relevant consent controls when a tag is triggered.
- The tag runs, is blocked, or adjusts its behavior according to its configuration.
For example, a visitor might allow analytics but reject advertising. Your implementation should apply those choices separately. Accepting one optional category is not permission for every tag.
The sections below cover a category-based trigger approach. Google tags that support Consent Mode have their own consent features, which are covered separately below.
What Is OnetrustActiveGroups?
OnetrustActiveGroups is a data layer value that OneTrust can provide. It lists the currently active category IDs, based on the visitor’s preferences or your configured defaults.
A data layer lets a website and its integrations pass information to GTM. A GTM Data Layer Variable reads a particular value from it. An example value looks like this:
,C0001,C0002,C0003,
Category IDs are identifiers, not descriptive names. Before you write a firing rule, confirm which ID matches the category that should control the tag. Verify the IDs in your own OneTrust configuration, because not every implementation uses the same mapping.
How to Create the OnetrustActiveGroups Variable in GTM
To make active categories available in your trigger conditions:
- Open your GTM container and select Variables.
- Create a new user-defined variable.
- Select Data Layer Variable as the type.
- Set the Data Layer Variable Name to
OnetrustActiveGroups, keeping the capitalization. - Give the variable a recognizable name, such as
OnetrustActiveGroups, and save it.
Use GTM Preview to confirm the variable receives the expected value when OneTrust updates consent.
How to Use a Cookie Category to Control a Tag
Suppose you’ve verified that C0002 is the category required for a particular optional tag. A condition can check for the complete category token:
Variable: OnetrustActiveGroups
Operator: matches RegEx
Value: ,C0002,
These lines describe fields in the GTM interface. They aren’t JavaScript to paste into your website.
The surrounding commas mark the boundaries of the category ID. That makes the condition more precise than searching for an unbounded fragment of the value.
What Happens When a Visitor Changes Consent?
OneTrust provides a data layer event named OneTrustGroupsUpdated. A GTM Custom Event trigger can listen for it and evaluate the category condition. For a tag that should start when the category becomes active, configure:
Trigger type: Custom Event
Event name: OneTrustGroupsUpdated
Fire on: Some Custom Events
Condition: OnetrustActiveGroups matches RegEx ,C0002,
This helps when a visitor grants consent without reloading the page. Keep these cautions in mind:
- Consent updates aren’t business events. Don’t use this event in place of a purchase, form submission, or other action you want to measure.
- Check repeated updates and consent withdrawal. A trigger can’t undo JavaScript that has already loaded.
Match the Trigger to the Tag’s Purpose
Before you apply a consent trigger, decide what the tag is meant to do:
- Load an optional service: The service may need to initialize when its required consent becomes available.
- Record a form submission: The tag should respond to a real submission and check the required consent at that moment.
- Record a purchase: The tag should respond to the purchase event, with the correct transaction details and consent controls.
Attaching every tag to a consent-update event can produce incorrect measurements. Accepting cookies should never be recorded as a purchase or a form submission.
Why Multiple GTM Triggers Can Break Consent Controls
A common mistake is adding a consent trigger alongside an existing firing trigger and assuming both conditions must be true. Separate firing triggers on a tag mean either one can fire it. An existing All Pages trigger can therefore undermine your consent restriction.
A Trigger Group waits until all of its member triggers have fired at least once on the page. That can combine event requirements, but it doesn’t continuously check that consent is still granted.
For a tag that measures a specific action, design the setup so the required consent is checked when the action happens. Depending on the tag, that may involve GTM’s consent settings, conditions on the action trigger, or an exception evaluated on the same event.
Test the full sequence you intend to support: consent granted, withdrawn, and granted again. A Trigger Group alone doesn’t handle every consent change.
How Does OneTrust Relate to Google Consent Mode?
OneTrust category IDs and Google’s consent types are different systems. Seeing C0002 in the active groups doesn’t prove that Google has received an analytics_storage consent update. If you use Google Consent Mode, verify the integration that maps your preferences to Google’s consent states.
Google tags that support Consent Mode have built-in consent checks. Other tags may need additional consent requirements or category-based blocking. Expected behavior also depends on your setup:
- Basic Consent Mode: Google tags are blocked until the relevant consent is granted.
- Advanced Consent Mode: Google tags load with denied defaults and can send cookieless pings before consent is granted.
So a network request before consent doesn’t automatically mean your implementation is faulty. Compare what you observe with the consent model you intentionally configured.
Consent defaults must be set before measurement tags run, then updated once the visitor’s preferences are known. GTM offers a Consent Initialization trigger for integrations that set those defaults.
Don’t Forget Scripts Outside GTM
GTM is only part of a consent audit. A site may also load analytics, advertising, embeds, or other third-party JavaScript directly through:
- Theme templates
- CMS plugins
- Header/footer injection
- Custom JavaScript
- Embedded forms
- Iframes
These scripts don’t become consent-aware just because GTM is configured correctly. For example, a marketing platform might be loaded once by a WordPress plugin and again through GTM. Controlling the GTM copy leaves the plugin’s copy unaffected, and it can also cause duplicate tracking.
Review where each service is installed and make sure its consent controls cover every loading path.
How to Test Your OneTrust and GTM Consent Setup
Test from a clean browser session. Use GTM Preview alongside the browser’s Network and storage tools. For a complete walkthrough, see our guide on how to test whether GTM and GA4 respect cookie consent.
- Before interacting with the banner: Check the initial consent state and which services load.
- Reject optional categories: Confirm behavior matches your configured consent model.
- Allow one category: Check that the matching functionality becomes available without enabling unrelated services.
- Perform a real action: Test a form submission, purchase, or other event. Confirm the correct tag fires once with the expected information.
- Withdraw consent: Check the updated state, later events, and behavior after navigating to another page.
- Return to the site: Confirm saved preferences are applied before optional services run.
For each relevant event, inspect the consent state, variable values, tags that fired, tags that were blocked, and actual network activity.
Pay particular attention to withdrawal. Blocking future tag executions doesn’t necessarily stop an already loaded service or remove cookies it created earlier. Check what each service and your integration require to handle withdrawal.
Treat consent management as an implementation that needs testing, not a banner installed on top of a website. For the broader compliance picture, read about what GDPR and U.S. privacy practices require from cookie consent, tag managers, and Google Analytics.
Frequently Asked Questions
Does OneTrust automatically block Google Tag Manager tags?
No. The banner collects preferences, but your implementation must apply them to the tags in your container and to scripts loaded elsewhere.
Do I need GTM to use OneTrust?
No. OneTrust can also work with scripts loaded directly by your website. GTM is useful when you want to manage multiple tracking services and their rules in one place.
What does OnetrustActiveGroups contain?
It contains the currently active OneTrust category IDs, such as ,C0001,C0002,C0003,. Verify which ID maps to which category in your own configuration.
Does a network request before consent mean my setup is broken?
Not necessarily. With Advanced Consent Mode, Google tags can send cookieless pings before consent is granted. Compare what you see with the consent model you configured.
Get Help with Consent and Analytics Implementation
AZTANDC helps organizations implement and troubleshoot consent management, Google Tag Manager, analytics, and the web technology around them. We can review how your tags load, how consent choices reach them, and whether the resulting behavior matches your intended configuration. Learn more about our analytics, SEO, and privacy services, or contact us to discuss your setup.