Google Tag Manager with CookieRay Pro
CookieRay Pro can add your Google Tag Manager (GTM) container to every page and tie its loading to the visitor’s consent. You paste a container ID; CookieRay outputs the code in the page head.
This page covers GTM only. For the other two tools see Meta Pixel and Adobe Experience Platform, or the overview of all integrations.
Set it up
- Make sure your Pro license is active.
- Open CookieRay → Settings → Integrations.
- Switch on Google Tag Manager.
- Enter your Container ID, for example
GTM-XXXXXXX. - Click Save Integrations.
The GTM code is output only when the card is switched on and the Container ID is filled in.
What CookieRay outputs
How GTM loads depends on your consent mode in Settings → Consent Behavior.
| Consent mode | What happens |
|---|---|
| Strict (Block Until Consent) | CookieRay creates the dataLayer straight away, but holds back the gtm.js script until the visitor grants analytical consent. |
| Log Only (Log Consent Only) | The standard GTM snippet loads immediately. Consent is recorded but nothing is blocked. |
In Strict mode, a visitor who declines analytical cookies never loads gtm.js at all.
Consent update event for your triggers
Each time a visitor makes a choice, and again on every later page load for a returning visitor, CookieRay pushes this to the dataLayer:
{
event: 'cookieray_consent_update',
analytics_storage: 'granted', // or 'denied'
ad_storage: 'denied' // or 'granted'
}
analytics_storageisgrantedwhen the visitor allowed the Analytical category.ad_storageisgrantedwhen the visitor allowed the Marketing category.
In GTM you can create a Custom Event trigger with the event name cookieray_consent_update, and read analytics_storage and ad_storage through Data Layer Variables. Use it to fire a tag after consent changes.
Because GTM itself does not load in Strict mode until analytical consent, a visitor who has not allowed analytics will not run any tag in the container, whatever its triggers say.
In Strict mode GTM loads after the visitor consents, so triggers that rely on the built-in page view or gtm.js events may not fire on that first page. For tags that need consent, use the Custom Event trigger on cookieray_consent_update, and check your setup in GTM’s preview mode (Tag Assistant).
Google Consent Mode v2
Consent Mode v2 is a free feature of CookieRay and is separate from this integration. When it is switched on, CookieRay sets the default consent state to denied before the GTM code, so your tags see the denied state first, and updates it after the visitor chooses. See Google Consent Mode v2 and the tutorial Set up Consent Mode v2 with GA4 and GTM.
Avoid loading GTM twice
If your theme, another plugin, or hard-coded code already adds the same container, turn that off or leave this integration switched off. Two copies of the container can load twice and double-count events.
Test it
- Open your site in a private window.
- In developer tools → Network, filter for
googletagmanager. - In Strict mode, confirm there is no
gtm.jsrequest before you click the banner. - Click Accept All and confirm
gtm.jsnow loads. In the console, typedataLayerand look for thecookieray_consent_updateentry. - Repeat with Decline All.
gtm.jsshould not load in Strict mode.
If the banner is hidden for a visitor’s country by Geo Targeting, or switched off, the GTM code is still printed but no consent push happens. In Strict mode gtm.js never loads for those visitors. In Log Only mode it loads straight away. See Integrations.
Troubleshooting
See Pro troubleshooting if GTM does not appear in the page source or loads twice.