Google Consent Mode v2 and GTM
Principle: default deny
As soon as the Agreely loader runs, it installs Consent Mode v2 in default-deny mode synchronously, before the banner module is downloaded and before GTM loads any tag:
// what the loader installs immediately (no action required on your part)
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
functionality_storage: 'denied',
security_storage: 'granted',
});
The security_storage: 'granted' signal covers the agreely_consent cookie
itself, classified as strictly necessary (article 14: the consent cookie is
required for the mechanism to function).
Load order
The Agreely tag must appear before the GTM tag in your <head>:
<head>
<!-- 1. Agreely first - installs default deny (no async: must run synchronously) -->
<script
src="https://cdn.agreely.ca/e/v1/loader.js"
data-agreely="agr_pub_YOUR_KEY"></script>
<!-- 2. GTM next -->
<script async src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXX"></script>
<!-- ... rest of head ... -->
</head>
If GTM loads before Agreely, tags fire without a consent signal and zero-click enforcement is not guaranteed.
Signal mapping
When a visitor makes a decision, the banner sends a gtag('consent', 'update', ...)
signal with the following mapping:
| Agreely category | Consent Mode v2 signals updated |
|---|---|
| Marketing | ad_storage, ad_user_data, ad_personalization |
| Analytics | analytics_storage |
| Functional | functionality_storage |
| Strictly necessary | (no signal - always granted) |
Categories the visitor has not granted stay at denied until an update. A consent
withdrawal resets all signals to denied (except security_storage).
Consent Mode without GTM
If you use gtag.js directly (without GTM), the flow is identical: Agreely
installs the default, and on each visitor decision it pushes a
gtag('consent', 'update', ...) with the mapping above. Your upstream code can
call gtag('config', ...) as usual; the Consent Mode update is what gates your
tags.
Reacting to a consent change
There is no custom DOM event to listen for. The banner does not dispatch an
agrConsent (or similar) event. To run your own code when consent changes, use
one of these real surfaces:
- Google Consent Mode: the loader pushes
gtag('consent', 'update', ...)on each decision, so tags gated by Consent Mode react automatically. - The
window.agreelyCookiesAPI: its methods (open(),acceptAll(),refuseAll(),withdraw()) let you drive the banner, and you can read the current decision from theagreely_consentcookie after a change. - The
agreely_consentcookie: re-read it (client- or server-side) to learn the visitor's current per-category decision.
Verifying the default signal is applied
Open your browser in private mode (no pre-existing cookies), navigate to your site, and in the DevTools console:
// before any interaction with the banner:
window.google_tag_data?.ics?.entries ?? 'not loaded yet'
All non-essential signals should be denied. If you see granted, the GTM tag
is probably loading before the Agreely tag.