Free GA4 auditCheck

Google Tag Manager: how it works, how to install it and how not to break your tracking

November 3, 2026 9 min readPaweł Strzelecki
Google Tag Manager: how it works, how to install it and how not to break your tracking

What is Google Tag Manager and what is it for?

Google Tag Manager (GTM) is a tool in which you add and change measurement and advertising tags without editing your site code. According to the introduction in Tag Manager help, you add two snippets of code to each page once, and you make later changes in the GTM interface.

Google's help describes GTM through a few terms that appear in every implementation:

  • Account: lets you administer the tags for one or more websites or apps; one account per company is typical.
  • Container: a collection of tags, triggers, variables and related configurations installed on a given website or app.
  • Tag: a piece of code placed in the container instead of being pasted into the page by hand, for example a Google Ads or Google Analytics tag.
  • Trigger: a condition that says when a tag fires, for example on a page load or after a form is submitted.
  • Variable: a value used by tags and triggers, for example a page URL or an order value.

A tag, a trigger and a variable together make one measurement rule: what to send, when to send it and with what data. A GTM implementation comes down to arranging such rules so that every event is counted once.

How do you install Google Tag Manager on a website?

Installation means pasting two snippets of code from the container install dialog onto every page. Google's installation help says to paste the first snippet as high in the head tag as possible and the second immediately after the opening body tag.

  • First snippet: the container script, pasted as high in the head section as possible.
  • Second snippet: a noscript block with an iframe that loads ns.html from googletagmanager.com with the container ID; you paste it right after the opening body tag.
  • Container ID: in the sample code, replace the placeholder ID with your own container ID.

If the site runs on a CMS or a site builder, the same help points to ready-made integrations so you do not edit the code of every page. After pasting the code, enter the site URL in the install dialog and click Test, then check the container in the preview mode described below.

What is the data layer (dataLayer) and why does GTM need it?

The data layer (dataLayer) is a JavaScript object that Google Tag Manager and gtag.js use to pass information to tags. That is how the developer documentation defines it, and in practice its job is to give GTM data that is not visible in the page URL itself, such as an order value.

The documentation shows three constructions that a developer uses most often:

  • Declaration: window.dataLayer = window.dataLayer || []; placed high in the page source, above the container snippet, so the object exists before Tag Manager loads.
  • Variable: dataLayer.push({'variable_name': 'variable_value'}); passes one value to the data layer.
  • Event: dataLayer.push({'event': 'login'}); the event key names an action, so tags with event triggers can fire.

The division of work is simple: the page sends events to the data layer, and GTM picks them up and decides which tag should react. This lets you assign an event from a single push to several platforms without touching the page code again.

How do you set up a tag, trigger and variable for a form submission?

You configure a form event in three places: in the page code, in the trigger and in the GA4 tag. Tag Manager help on the custom event trigger describes this case: tracking form submissions when the default behavior of the submit button has been changed.

  • After a successful form submission, the page pushes to the data layer, for example dataLayer.push({'event': 'form_submit_success'}).
  • In GTM you create a custom event trigger and enter the name form_submit_success.
  • You create a GA4 event tag and assign that trigger to it.
  • You send extra values, such as a conversion value, in the same push and read them with a data layer variable.

Be careful with regular expressions in the event name. According to the same help, the pattern .* matches every event, including those that Google Tag Manager and the Google tag emit automatically, so the help recommends a narrower pattern.

How do you test GTM changes before publishing?

You test changes in preview mode, which lets you browse the site as if the current container draft were already published. Google's help on preview and debug says the connected Tag Assistant shows which tags fired and in what order.

  • Visibility: you see the debug interface only in the browser where preview was enabled, or for people you share it with; regular visitors do not see it.
  • Sharing: you can send the preview to others through a generated URL.
  • Limitation: the debug interface is not available for mobile app containers.
Row of identical labels on a wire, one doubled: a tag firing twice

In preview, check that the trigger fired on the right action, that the tag fired once and that the variables have values. After publishing, the GA4 Audit does a second check: it scans the site from a URL and detects, among other things, a duplicate page_view and missing purchase funnel events.

How do you manage permissions and container versions?

You grant permissions in GTM separately for each container, and Google's help on permissions lists five access levels. At the account level, a user has either the Admin or the User role.

LevelWhat the user can do
No accessThe container is not visible in the account
ReadSees the container, tags, triggers and variables, with no right to change them
EditCreates workspaces and makes changes, but cannot create versions or publish
ApproveCreates versions and workspaces and makes changes, but cannot publish
PublishHas full rights, including publishing
Container access levels according to Google's help

A version is, according to the help on versions and publishing, a snapshot of a container configuration at a particular time. Publishing makes changes active in the chosen environment, and every publish saves a version automatically, so you can return to an earlier configuration if something goes wrong. Approval requests are available only in Google Tag Manager 360.

For agencies and freelancers, the Edit or Approve level works well. Leave Publish to a person on the company side who answers for the result, because every published change goes straight to the live site.

You handle consent in GTM with the Consent Initialization trigger and the consent settings in tags. Tag Manager help on consent says every web container has a default “Consent Initialization - All Pages” trigger, which always fires before all other tags, including those with an Initialization trigger.

  • Tags that manage consent: for example a consent management platform (CMP) tag or a tag that sets default consent use the Consent Initialization trigger.
  • Other tags that start early: use the regular Initialization trigger.
  • Additional check: in a tag's advanced settings you choose “Require additional consent for tag to fire”, and the tag then fires only when all specified consent types are granted.
  • Consent types: ad_storage, ad_user_data, ad_personalization and analytics_storage.

Settings in the container do not prove that scripts behave correctly on the site. The Consent Mode Checker tests that, and we describe the effect of the setup on GA4 data in the article on Consent Mode v2 and data loss.

Which mistakes in Google Tag Manager break tracking most often?

The most common GTM mistakes involve duplicate tags, publishing without a test and triggers that are too broad. Each of them can be caught before publishing or right after, if you know what to look for:

MistakeResultHow to avoid it
The same GA4 tag in the page code and in GTMEvents are sent twice, e.g. page_viewKeep one place of implementation and check the site with the GA4 Audit
Publishing without previewA tag does not fire or fires on the wrong pageWalk through the path in preview mode and check the tag order in Tag Assistant
Event trigger with the .* patternA tag reacts to every event, including system onesEnter the exact event name or a narrow pattern
dataLayer declared below the GTM snippetThe object may not exist when the container loadsDeclare the data layer above the container snippet
Advertising tags without consent settingsTags fire regardless of user consentAdd a consent requirement to the tag and use Consent Initialization for the consent tag
Publish level for everyoneAny user can push a change to the live siteGrant the lowest level that is enough for the work
Typical GTM container mistakes and how to avoid them

You will find a full measurement checklist in the article GA4 audit: checklist, and how to name campaigns so reports stay readable in the article on UTM parameters. Once the container works correctly in the browser, the next step is sometimes server-side tagging.

If you would rather hand the GTM, GA4 and event implementation to someone who does it every day, we describe the scope in our GA4 and analytics service. Our digital marketing agency also sets up measurement in the container on every new ad account.

More on Analytics and measurement

Service: GA4 Implementations →
Author
Paweł Strzelecki, co-founder of Zest
Paweł Strzelecki
Co-founder of the digital agency Zest

In Zest implementations he starts by reviewing the client's GTM container: what fires in it, when, and who outside the team can publish changes. Only then does he add new tags.

LinkedIn

Related articles

Contact

Let's talk growth

Send a brief or drop your contact. We'll reply within 24h.

Get a quote
Paweł Strzelecki and Karol Majewski, co-founders of Zest