Google Tag Manager
There are two ways to run ConsentAlly with Google Tag Manager. The recommended one puts the ConsentAlly script first in your page and your container after it, unchanged. If Tag Manager is the only way you can add a script to your site, the ConsentAlly template sets Consent Mode's defaults and loads the banner from inside your container.
Choose a setup
- The script first (recommended). The ConsentAlly script runs before anything else on the page, so it holds every third-party script, iframe and image from the start, whether your container adds it or your theme does.
- The template. The template loads the same script from inside your container, after Tag Manager has started, so it holds what loads after it and nothing that ran before. Use it when you cannot edit your site's
<head>.
Use one of them, not both. If both are on a page, the template's copy of the script does nothing, and both set the same Consent Mode defaults.
The script first
Put your Google Tag Manager container after the ConsentAlly script and leave its snippet as it is. The container loads at once and finds Consent Mode's denied default already on the dataLayer, and every third-party script, iframe and image its tags add is held until the visitor allows it; a third-party request its tags make before then fails, as with an ad blocker.
Order in the page
<!doctype html><html lang="en"> <head> <meta charset="utf-8" /> <!-- First: the ConsentAlly tag from the script install page. --> <!-- Then Google Tag Manager's snippet, unchanged: --> <script> (function (w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" }); var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != "dataLayer" ? "&l=" + l : ""; j.async = true; j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl; f.parentNode.insertBefore(j, f); })(window, document, "script", "dataLayer", "GTM-XXXXXXX"); </script> <title>Your store</title> </head> <body></body></html>On Shopify, the app embed loads ConsentAlly as early as Shopify lets an app load, at the end of the theme's <head>, so a container pasted into your theme's <head> runs before it. Move the container to the top of <body>, below ConsentAlly's script.
What loads and what waits
-
The container loads before a choice.
gtm.jswith exactly one id startingGTM-is allowed at once, so Tag Manager can read Consent Mode and run its triggers. The same file asked for with any other id (G-,AW-,DC-) is a Google tag, and ConsentAlly treats it as gtag.js. -
Google's tags read Consent Mode. The Google tag, Google Analytics and Google Ads in your container see the denied default before they run and the update when the visitor decides. In basic mode, what they load and send is held until the visitor allows it; see Consent Mode for advanced mode.
-
Every other tag's requests are held. Scripts, iframes and images a tag adds, and the requests it makes, go through ConsentAlly: known trackers wait under their category, any other third party as marketing. When the visitor allows them, held scripts, iframes and images load where the tag put them, without a page reload; requests made before then failed and are not sent again.
With the script first, you need no Consent Mode template and no Consent Initialization tag: the
default is already on the dataLayer when the container starts.
The ConsentAlly template
Add it to your container
- Download the template file (
ca-tag-template.tpl). - In your container, open Templates, choose New under Tag Templates, open the menu at the top right of the template editor, choose Import and pick the file. Then choose Save.
- Create a tag of the type ConsentAlly and enter your Store key: the 16 characters of
data-ca-keyon your script install page. - Give it the trigger Consent Initialization - All Pages, then publish the container.
What the tag does
-
It sets the defaults first. Before any other tag in the container, it sets every Consent Mode type to denied but
security_storage, withwait_for_updateat 500 milliseconds andads_data_redactionon. Tick Pass ad click information through URLs to seturl_passthroughtoo, when it is on in your banner's settings. -
It loads the banner for your store. The tag loads ConsentAlly's script for your store key from
edge.consentally.com, the only address it may load from, and the script loads the banner with your published settings. A store key that is not 16 characters loads nothing and leaves the defaults denied. -
The visitor's choice reaches the container. When the visitor decides, the banner sends a Consent Mode update on the
dataLayer, which the container applies before its next event, and then the eventconsentally_consent_update, which tags waiting for consent can fire on (see below). Basic or advanced Consent Mode stays a setting of your banner, not of the tag.
What the template cannot hold
-
What runs before the script arrives. The script loads while the container keeps going, so tags on the Initialization and All Pages triggers can run before it, and what they load and send then is not held. Google's tags read the defaults the template set; give every other tag a consent check, as below.
-
Scripts outside the container that run first. Scripts in your theme or page that run before the container has loaded the ConsentAlly script are not held.
-
A renamed data layer. The banner's updates go on the standard
dataLayer, so a container loaded with another data layer name does not receive them.
Consent checks in the container
Inside the container, custom HTML tags and custom templates run their own code, and cookies they write directly are not held. Give each of them a consent check: in the tag's Advanced Settings, under Consent Settings, require additional consent for the type of its purpose, such as ad_storage for an advertising tag or analytics_storage for an analytics one. With Enable consent overview turned on in the container's settings, you can see and set every tag's checks in one place.
Firing tags after the visitor decides
A tag whose consent check fails when its trigger fires does not run on that trigger. ConsentAlly
pushes the event consentally_consent_update on the dataLayer after every Consent Mode update
it sends: when the visitor decides, and on each later page view that has their stored choice.
Add it to such a tag's triggers and the tag runs on the page where the visitor allows it.
In basic mode, a Google tag that fires only on Initialization - All Pages sends its page view before the visitor decides; ConsentAlly holds that request and it is not sent again, so the page where the visitor accepts records no page view. Set the tag up like this so it does:
- In Triggers, choose New, then Custom Event. Enter
consentally_consent_updateas the event name, keep All Custom Events and save the trigger. - Open your Google tag. In Advanced Settings, under Consent Settings, choose Require additional consent for tag to fire and add
analytics_storage. - Under Tag firing options, choose Unlimited. Not Once per page: Tag Manager counts the attempt its consent check blocked on Initialization as the page's one firing, so the tag would never run on the new trigger.
- In Triggering, keep Initialization - All Pages and add the new trigger. Save the tag and publish the container.
The tag then sends one page view on each page view where analytics is allowed: at once for a returning visitor who allowed it, and on the visitor's choice otherwise. A visitor who allows analytics and then, on the same page, allows more sends a second page view for that page.
Good to know
-
With the script first, the container usually loads before your configuration arrives, so a classification cannot hold the container itself.
-
A server-side container on a subdomain of your site loads as first party, but requests to Google's standard paths on it (
/gtag/js,/g/collect) are held as Google Analytics until the visitor allows analytics. What your server sends on from there is outside the browser.