Measurement and analytics
Google Tag Manager
Setup, Consent Mode v2 and common mistakes
On this page
- What is Google Tag Manager?
- How to set up Google Tag Manager
- Web GTM and server-side GTM
- Consent Mode v2: how consent controls the tags
- Common consent mistakes in Google Tag Manager
- Modelled figures: when Google Analytics shows visits that do not exist
- How to check that consent works
- How we can help you with Google Tag Manager
Google Tag Manager (GTM) is Google’s free tool for adding and managing tracking code on a website without changing the website’s own code. With GTM, the marketing team can add a tag for Google Ads or Meta themselves, but the tool does not make the tracking correct on its own. Two common faults are linked to consent: tags that send data without consent, and figures in Google Analytics that are largely modelled.
What is Google Tag Manager?
GTM is a tag management system. Everything that belongs to a website is collected in a container, which consists of tags, triggers and variables (Google). A tag is a code snippet that sends data to a tool, such as Google Analytics 4, Google Ads or an advertising platform. A trigger decides when the tag runs, and every tag must have at least one. Variables capture values such as the page address, a clicked element or an order value.
Through a data layer (dataLayer), the website can also send its own information to GTM, such as product, price and whether the visitor is logged in. This is the safest route for data that will be used in several tags, because the values are then not taken from the page’s appearance, which changes when the website is rebuilt.
GTM is free. There is a paid version, Tag Manager 360, which is part of Google Marketing Platform and offers, among other things, an unlimited number of workspaces (the free version has three), approvals before publishing and a service level agreement.
How to set up Google Tag Manager
Google recommends one container per website. The installation code is placed as high in the page’s head section as possible. Google now shows a single code snippet; older installations have two, with the second in the body section, and they do not need to be replaced (Google).
Changes are made in a workspace and tested in preview mode, which connects the website to Tag Assistant so that you can see which tags run on each page. Every publication is saved as a version, and a faulty version can be rolled back. Always run preview mode before publishing, and write what has changed in the version name.
If you only need to send data to Google’s own services, the Google tag (gtag.js) directly in the code is enough. GTM is needed when tags from other suppliers are to be added.
Web GTM and server-side GTM
GTM comes in two parts. The web container runs in the visitor’s browser, and each tag sends its data directly from the browser to its supplier. Server-side GTM (sGTM) is a server container that runs on a server you control yourselves (Google). The browser then sends data to your own server, and only there is it decided what is passed on and to whom.
Google highlights two advantages: the page runs less code when fewer tags sit in the browser, and visitor data is better protected when it is collected and distributed from an environment you manage yourselves. Best practice is to place the server on a subdomain of your own website. We recommend running it on your own server or with a Swedish hosting provider rather than on Google’s Cloud Run.
In the server container, data can be removed before it leaves your server. With the Transformations feature, you control which parameters each tag can see and exclude sensitive data (Google). This is how personal data is removed, such as an email address that has ended up in a page address, before data is sent to Google or other suppliers. We have extensive experience of installing sGTM servers for clients and help them remove personal data to comply with the regulations.
Consent Mode v2: how consent controls the tags
Under the Swedish Electronic Communications Act, cookies and similar data may only be stored on or read from the visitor’s device if the visitor has been informed of the purpose and has consented. The exception is what is needed to transmit the communication or is necessary for a service the visitor has explicitly requested. The Swedish Post and Telecom Authority (PTS) supervises cookies, and the Swedish Authority for Privacy Protection (IMY) supervises the processing of personal data that follows (IMY). PTS writes that it must be as easy to say yes as no (PTS).
Consent Mode is Google’s way of passing the visitor’s choice from the consent management tool to Google’s tags. Version 2 arrived in November 2023 and has four parameters:
| Parameter | Controls |
|---|---|
analytics_storage |
Cookies for statistics, such as Google Analytics |
ad_storage |
Cookies for advertising |
ad_user_data |
Whether user data may be sent to Google for advertising, including for conversion tracking |
ad_personalization |
Whether data may be used for personalised ads and remarketing |
For visitors in the EEA, Google requires the website to send consent signals for Google’s tags to be used for measurement, personalised ads and remarketing. Visitors are only included in advertising audiences if the signals show that they have consented (Google). Google bases the requirement on its own EU user consent policy.
Consent Mode comes in two variants. In basic mode, Google’s tags do not load until the visitor has consented, and no data is sent to Google before then, not even the consent status. In advanced mode, the tags load straight away but send measurements without cookies while consent is missing, and Google uses them to model what cannot be measured.
A default state, denied for visitors in the EEA, is set before any tag runs and is updated when the visitor makes their choice. In GTM this is done with the Consent Initialization trigger, which always runs before all others. Most consent management tools, such as Cookiebot, Cookie Information, OneTrust and Usercentrics, have ready-made templates in GTM’s template gallery.
Common consent mistakes in Google Tag Manager
The default state is set too late. If the ad tag runs before the default state has been set, consent has no effect on that page view. Google also advises against setting consent with a custom HTML tag in GTM.
Tags other than Google’s lack consent requirements. Only Google’s own tags follow Consent Mode automatically. Tags for Meta, LinkedIn or TikTok, for example, need their own consent requirement in the tag settings. Unfortunately, it is very common for tags in production to lack correct consent settings.
Consent does not control third-party tags in server-side GTM by itself. Google’s own tags in the server container read the consent in the request, but other tags do not. In a server container we troubleshot, a third-party tag ran for just over a month even though visitors had only accepted necessary cookies. The tag’s built-in consent setting had no effect in the server container. The solution was a condition on the consent value that the Google tag sends with the request (the gcs parameter). Google describes what the parameter carries but not how the values are encoded, and states that the fields may change. Such a condition therefore needs to be checked after updates. Read more about how we set up and check server-side GTM.
Extra consent requirements on Google’s tags. If you use Consent Mode and also add your own consent requirements to Google’s tags, the tags will not run for visitors who have not consented. Sometimes they will not run even when consent comes after the tag was triggered. In practice this becomes basic mode: modelled conversions become less accurate, and behavioural modelling in Google Analytics cannot be used (Google).
Duplicate tags. The same Google tag in both the code and GTM, or two containers on the same page, can result in duplicate data or mixed settings.
Modelled figures: when Google Analytics shows visits that do not exist
With advanced mode, Google Analytics 4 fills in the gaps left by visitors who have said no. This requires advanced mode, at least 1,000 events per day from visitors without consent for at least seven days and at least 1,000 users per day with consent for at least seven of the previous 28 days (Google). The model can give a reasonable overall picture, but it can also hide what is happening in a campaign.
We have seen sessions on a product page increase around 40 times in Google Analytics compared with the previous month. A comparison with the raw data in BigQuery showed that around 95 per cent of the sessions in Google Analytics were modelled, that over 90 per cent of the visitors to the page had declined cookies and that the real increase was around 5 times. The cause was an advertising campaign with low-quality traffic, and the model had made it hard to detect.
On another website we have analysed, the figures for large campaigns were 30 to 70 per cent higher in Google Analytics than in the BigQuery export. The model also affects different metrics to different degrees: sessions can differ sharply between measured and modelled data, while leads, for example, were barely affected in that case. So compare the figures in Google Analytics with the BigQuery export, broken down by consent status, before drawing conclusions about a campaign.
How to check that consent works
- Test three states: everything accepted, only necessary cookies, and statistics but not marketing. In each state, check which tags run and which cookies are stored.
- Read the Consent tab in Tag Assistant: the On-page Default column shows the default state and On-page Update what changed after the choice. An empty tab means that Consent Mode has not been implemented on the page, or that the Google tag is blocked from loading (Google).
- Run preview mode in both containers: an event can appear in the web container but be stopped or wrongly let through in the server container.
- Follow up in the data: a sudden increase in events without a user ID in the BigQuery export, or in traffic without a source, may point to modelling or to consent having failed.
How we can help you with Google Tag Manager
- Audit: a review of the container, focusing on consent, duplicate tags and tags without consent requirements.
- Consent Mode: connecting the consent management tool and GTM, with tests of all states.
- Server-side: installing and running sGTM servers, with personal data removed before data is passed on.
- Data quality: a comparison between Google Analytics and the BigQuery export, so that you know which figures are measured.
If you measure with Matomo instead of Google Analytics, there is more on the Matomo page, and the full picture is described under web analytics. Want to know whether your container respects consent? Contact us, and we will start with a review.
Want to know where you stand today?
Call us, or fill in the form and we will get back to you.