Docs menu
Google Tag Manager
The CookieHug template for Google Tag Manager: installation, the Consent Initialization trigger, parameters, behavior and template permissions.
Google Tag Manager template
CookieHug ships an official Google Tag Manager custom template so you can deploy the consent banner and Google Consent Mode v2 entirely from GTM — no <head> snippet required. It is published in the GTM Community Template Gallery (search *CookieHug Consent Banner*) and the source lives in a dedicated public repo: github.com/cookiehug-com/gtm-cookiehug.
The template is a thin, universal loader: every site pastes its own license key, so the same template works for every CookieHug domain. It does exactly two things — sets all GCM v2 signals to denied *before* any tag fires, then injects the CookieHug SDK, which applies your region-aware defaults and calls updateConsentState when the visitor acts. All banner configuration (categories, copy, colors, blocking) stays on the CookieHug dashboard; the template is a connector, not a settings surface.
When to use it
Use the GTM template instead of the <head> snippet when you already manage your analytics/ads tags through Google Tag Manager and want a single place — GTM's Consent Initialization — where defaults are set before any tag evaluates its consent. If you do not use GTM, keep the standard <script> snippet or the WordPress plugin; do not install both, or the defaults will be set twice.
Installation
- From the gallery (recommended): GTM → Templates → Tag Templates → Search Gallery → search *CookieHug Consent Banner* → Add to workspace.
- Manual import (before the gallery listing is live): download `template.tpl`, then GTM → Templates → Tag Templates → New → ⋮ → Import and select the file.
- Create a tag: Tags → New → CookieHug Consent Banner.
- Attach it to the Consent Initialization — All Pages trigger. This is the earliest GTM-native trigger and guarantees the denied defaults are set before any analytics/ads tag runs. Do not use Page View / All Pages / DOM Ready.
Parameters
| Parameter | Type | Default | Notes |
|---|---|---|---|
licenseKey | TEXT | *required* | Your site key from Dashboard → Domain → Settings. |
region | SELECT | auto | Force a region for the default consent state (EEA/GB/CH/US/US-CA/ROW). Leave on auto in production. |
loadPosition | SELECT | async | async (fast, non-blocking) or defer (after HTML parse). Both set defaults before other tags. |
debugMode | CHECKBOX | false | Shows the CookieHug diagnostic badge. Preview/test containers only — never ship to production. |
What the template runs
1. setDefaultConsentState({ ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied', functionality_storage: 'denied', personalization_storage: 'denied', security_storage: 'granted', wait_for_update: 500 }) — stops marketing/analytics tags from firing until consent is updated.
2. injectScript('https://cookiehug.com/api/script/<licenseKey>.js') — loads the CookieHug SDK, which replaces the defaults with region-appropriate ones, shows the banner if needed, and calls updateConsentState when the user clicks a button.
If you reject the inject_script permission in a locked-down container, the tag calls gtmOnFailure() cleanly: no banner loads, but downstream tags stay blocked because the defaults remain denied.
Permissions requested
access_consent— read + write for every GCM v2 signal (ad_storage,ad_user_data,ad_personalization,analytics_storage,functionality_storage,personalization_storage,security_storage).inject_script— scoped tohttps://cookiehug.com/api/script/*only.logging— debug environments only.
Do not stack it with the snippet
The GTM template and the <head> snippet both set Consent Mode defaults. Use exactly one integration per site. If you migrate a site from the snippet to the GTM template, remove the <script id="cookiehug"> tag from <head> first — otherwise GTM's second default call can overwrite CookieHug's regional defaults and break EEA gating.