All articles

How OneTrust tells Google Tag Manager what a visitor chose

One variable and two events carry every consent choice from OneTrust into GTM. Here's how to read them and build triggers that don't miss.

Naini Anjaneyulu, 5 December 2026

A visitor clicks Accept on your OneTrust banner. Half a second later your tags in Google Tag Manager are supposed to know about it. Between those two moments there's a single string of text, and once you can read it, most OneTrust problems stop being mysterious.

The string that holds every answer

Open any site running OneTrust, press F12 and type this into the Console:

OnetrustActiveGroups

You'll get something like ,C0001,C0003,. That's the list of cookie categories the visitor has allowed, with commas at both ends. On a default OneTrust setup the IDs mean:

IDCategory
C0001Strictly necessary
C0002Performance (analytics)
C0003Functional
C0004Targeting (advertising)
C0005Social media

Don't trust that table for your own site, though. Category IDs can be renamed or added in the OneTrust admin, so check yours under Cookie Categories before building anything on them. On an older account, analytics might sit under C0003 just because someone set it up that way years ago.

C0001 is always in the list. Strictly necessary cookies can't be refused, so a visitor who rejects everything still gives you ,C0001,.

The two events OneTrust sends to the dataLayer

OneTrust doesn't just set that variable. It also pushes it into the dataLayer, attached to one of two events:

  • OneTrustLoaded when the banner script has finished loading and knows the stored choice
  • OneTrustGroupsUpdated whenever the visitor saves a new choice

Each push carries OnetrustActiveGroups with it. You can watch both happen in GTM Preview mode: they show up in the event list on the left, and the Variables tab shows the groups at that moment.

Building the trigger

In GTM, create a Data Layer Variable called OnetrustActiveGroups. Then make a Custom Event trigger for analytics:

  • Event name: OneTrustLoaded|OneTrustGroupsUpdated, with regex matching on
  • Fires on: OnetrustActiveGroups contains ,C0002,

Keep the commas in the condition. Without them, C0002 would also match a category called C00021 if anyone ever creates one, and that's a quiet bug you'd find months later.

Why I don't use the Page View trigger here

The obvious move is to keep your GA4 tag on All Pages and add a condition on OnetrustActiveGroups. It often fails, and the reason is timing. GTM's page view usually happens before OneTrust has loaded, so at that moment the variable is empty. The condition is false, the tag doesn't fire, and you lose the page view of every returning visitor who had already said yes.

Firing on OneTrustLoaded waits for the answer. Firing on OneTrustGroupsUpdated catches the visitor who accepts on their very first page.

Check that it fires once

There's a catch with listening to both events. On some setups OneTrust sends OneTrustGroupsUpdated on page load too, right after OneTrustLoaded. If both match, your page view goes out twice and your sessions look busier than they are.

Open Preview, reload a page as a visitor who has already accepted, and count how many times the tag fires. If it's two, add a trigger exception, or switch to a single event and handle the first-accept case separately.

This variable-and-trigger approach is the older way of doing things. Most sites now also pass consent to Google through Consent Mode, which works differently. Next: how to map OneTrust's categories onto it.

More articles

Does your site honour Global Privacy Control?

Some browsers tell every site "don't sell or share my data". In California that signal counts as an opt-out. Here's how to check that your site listens.

5 minute read

Opt-in for Europe, opt-out for the US: one OneTrust setup for both

European law wants permission before tracking. US state laws want a clear way to refuse. Geolocation rules let one site do both.

7 minute read

How to read OneTrust's OptanonConsent cookie

OneTrust writes every choice into one cookie. Decode it and you can answer "what did this visitor agree to?" in seconds.

5 minute read

Mapping OneTrust categories to Google Consent Mode

OneTrust thinks in cookie categories, Google thinks in seven consent types. A mapping that works, and the one setting that causes double defaults.

7 minute read

Consent checks or triggers? Two ways to make a tag wait in GTM

Google Tag Manager can hold a tag back with consent settings or with trigger conditions. They behave differently when a visitor changes their mind.

6 minute read

Does your cookie banner block anything?

A banner can look right and still let every tag fire. Four checks, all in your own browser.

5 minute read

How to check your dataLayer in five minutes

A quick routine, using only your browser, to see whether your site is sending the data your tags depend on.

6 minute read

Dashboards that answer one question well

Why most dashboards get ignored, and a simple way to design ones that people open every week.

7 minute read

Why tags break after a site update

The usual reasons tracking fails after a release, and a short checklist to stop it happening to you.

6 minute read

Can you trust your data?

Tell me what you track, and what you ask visitors before you track it.

Start a project