Google Tag Manager: complete guide
Manage all your measurement tags without relying on developers using GTM
Google Tag Manager (GTM) lets marketing teams install, manage and modify measurement tags — GA4, Google Ads, Facebook Pixel, Hotjar — without editing the website source code. This reduces dependencies, speeds up iterations and minimises errors.
But a poorly configured GTM can cause serious problems: duplicated data, phantom conversions, slower page loads or privacy regulation breaches. This guide covers proper setup from the ground up through advanced features like the data layer and consent mode.
Containers: structure and best practices
A GTM container is a code snippet installed once on the website that acts as a middle layer between the site and measurement tools. Inside the container, you create tags that fire based on rules (triggers) using site data (variables).
Each website or app should have its own container. In multi-site setups, containers can share configurations through reusable templates. GTM also supports server-side containers for greater control over data sent to third parties.
- One container per website or primary domain
- Server-side containers for advanced data control
- Workspaces for managing team changes without conflicts
- Environments to separate production, staging and testing
Tags, triggers and variables
Tags are code snippets GTM injects into the page: the GA4 script, the Facebook pixel, a Google Ads conversion code. Triggers define when they fire: on page load, on button click, on form submission.
Variables provide dynamic data to tags and triggers: the current URL, the clicked button text, a transaction value. GTM includes built-in variables and lets you create custom variables that read data from the data layer, cookies or DOM elements.
The data layer: bridge between site and GTM
The data layer is a JavaScript object (dataLayer) that acts as a structured data layer between your website and GTM. Instead of GTM scraping information from the HTML, the developer pushes data to the data layer and GTM reads it cleanly and reliably.
For ecommerce, the data layer is essential: it contains data about products viewed, added to cart and purchased in the format GA4 expects (enhanced ecommerce). Without a correct data layer, ecommerce measurement will be incomplete or inaccurate.
- Push events and data to dataLayer using window.dataLayer.push()
- Follow Google’s recommended structure for ecommerce
- Include user data (authenticated, customer type) where applicable
- Validate the data layer with the GTM extension and DebugView
Debugging and validation
GTM includes a Preview mode that lets you test changes before publishing. This mode shows which tags fire, which do not and why, with details on the triggers and variables involved.
Combine GTM Preview with GA4 DebugView to verify that events arrive correctly with expected parameters. Chrome’s Tag Assistant extension provides an additional validation layer. Publishing without debugging is the leading cause of corrupted data.
Consent mode and privacy
Google’s consent mode lets GTM adapt tag behaviour based on user consent. If the user rejects analytics cookies, GA4 can still collect aggregated and modelled data without personal identifiers.
Implementing consent mode correctly requires integrating GTM with your consent management platform (CMP): Cookiebot, OneTrust, Iubenda or others. GTM includes templates for the most popular CMPs that simplify configuration.
- Configure consent states: analytics_storage, ad_storage, ad_personalization
- Use a CMP compatible with Google’s consent framework
- Enable advanced consent mode for modelled data without cookies
- Verify tags respect consent using Preview mode
Server-side GTM: the next level
Server-side GTM runs tags on your own server (typically on Google Cloud) instead of in the user’s browser. This provides greater control over what data is sent to third parties, improves web performance and reduces reliance on third-party cookies.
Server-side implementation is more complex and has infrastructure costs, but offers significant advantages in data accuracy, performance and regulatory compliance. It is especially relevant for high-volume ecommerce and companies with strict privacy requirements.
Common GTM mistakes
The most frequent mistake is accumulating tags without order or documentation. Over time, containers fill with obsolete, duplicated or misconfigured tags that slow down the site and produce inconsistent data.
Another common error is not using workspaces or version control. GTM has built-in version history, but many teams publish directly without documenting changes, making it harder to diagnose issues when they arise.
- Duplicate tags firing the same event multiple times
- No consistent naming conventions for tags, triggers and variables
- Publishing without going through Preview mode
- Ignoring the performance impact of loading too many scripts
- Not documenting changes in each published version
Key Takeaways
- GTM lets you manage measurement tags without touching source code
- The data layer is essential for clean and reliable measurement
- Always debug in Preview mode before publishing changes
- Consent mode adapts measurement to user consent preferences
- Server-side GTM improves performance, accuracy and privacy
- Regularly document and audit your container to avoid technical debt
Does your GTM need an audit?
We review your Tag Manager setup, fix errors and optimise measurement so your data is reliable and your site is fast.