All posts
Blog

Google Tag Manager: What It Is and How to Set It Up (Step by Step)

By Dakshesh13 min read

  • google tag manager
  • GA4
  • analytics tracking
  • tag management
Continue with GoogleFree plan · No credit card required

AI Overview

Google Tag Manager is a free tool for adding and managing tracking tags like GA4 and ad pixels without editing site code. Create a container, add its two snippets to every page, add the Google tag, test in Preview mode, then publish.

Key takeaways

  • Google Tag Manager is a free tag management system that loads tracking tags like GA4, Google Ads and ad pixels from one container.
  • Install the script snippet high in the head of every page and the noscript snippet right after the opening body tag.
  • Add GA4 with the Google tag and your G- measurement ID, and never install the same measurement ID directly and through GTM.
  • Test every change in Preview mode with Tag Assistant and GA4 DebugView, then publish it as a named version you can roll back.
  • Theme updates, plugin conflicts and migrations often remove the GTM snippet silently, so monitor that the script is still loading.

Summarize with AI

Opens the assistant in a new tab with a link to this post.

On this page

Google Tag Manager is one of those tools almost every marketing site ends up using, and almost nobody sets up the same way twice. Done well, it gives you one tidy place to manage analytics, ad pixels and conversion tracking without editing your site's code. Done badly, it double counts every page view, fires tags before consent, or quietly disappears after a theme update while your reports drift toward zero.

This guide explains what Google Tag Manager is, how it differs from GA4 and gtag.js, how to set it up step by step, how to add a GA4 tag, how to test and publish safely, and how to make sure it keeps working.

What is Google Tag Manager?#

Google Tag Manager (GTM) is a free tag management system from Google. You add one container snippet to your website, and from then on you add, edit and remove tracking tags in the GTM web interface instead of in your site's code.

A tag is a snippet of code that sends data somewhere: the Google tag for GA4, a Google Ads conversion tag, a Meta Pixel, a LinkedIn Insight Tag, a heatmap script. GTM loads those tags for you, based on rules you define.

GTM is built from four parts:

PartWhat it doesExample
TagsCode that sends data to a toolGoogle tag (GA4), Google Ads conversion, Meta Pixel
TriggersRules for when a tag firesAll pages, a click on the "Book a demo" button, a form submission
VariablesValues tags and triggers readPage URL, click text, a measurement ID, an order value
Data layerA JavaScript object your site uses to pass data to GTMdataLayer.push({event: 'purchase', value: 49})

The data layer deserves a closer look, because it's what separates a reliable setup from a fragile one. Instead of having GTM scrape button text or CSS classes (which change when the design changes), your site pushes clean events and values into window.dataLayer, and GTM listens for them. A redesign can then change every button on the page without breaking your conversion tracking.

Containers, workspaces and versions#

All of this lives in a container, which is identified by an ID that starts with GTM-. Inside the container you work in a workspace (a draft of your changes), test it in Preview mode, and then publish it as a version. Every published version is saved, so you can roll back to any earlier one in a couple of clicks.

Google Tag Manager vs GA4 vs gtag.js#

People mix these up constantly, partly because Google's naming has changed several times. Here's how they relate:

Google Tag ManagerGoogle Analytics 4gtag.js (the Google tag)
What it isA tag management systemAn analytics platformA JavaScript library that sends data to Google products
ID formatGTM-XXXXXXXMeasurement ID G-XXXXXXXXXXG-, AW- or GT- IDs
What it does on its ownNothing: it loads the tags you configureStores and reports data, but needs a tag on the site to collect itSends data to GA4, Google Ads and other Google products
Best forSites with several tags, marketing teams who want to change tracking without a developerReporting and analysisSimple sites that only need GA4 or Google Ads
Script URLgoogletagmanager.com/gtm.js(no script of its own)googletagmanager.com/gtag/js

The short version: GA4 is where your data goes, and either gtag.js or GTM is how it gets there. You can install the Google tag directly in your site's code, or you can install GTM and add the Google tag inside it. Pick one route for each measurement ID, not both. That mistake is covered below.

How to set up Google Tag Manager#

Step 1: Create an account and a container#

  1. Go to tagmanager.google.com and sign in with your Google account.
  2. Click Create Account. Enter an account name (usually your company name) and your country.
  3. Under Container Setup, enter a container name (Google suggests your site's domain, such as www.example.com) and choose Web as the target platform.
  4. Click Create and accept the terms of service.

Use one account per company and one container per website. Agencies should create accounts under the client's Google account, or ask the client to add them as a user, so the client keeps ownership when the engagement ends.

Step 2: Install the two container snippets#

After you create the container, GTM shows you two snippets of code:

  • The script snippet goes as high in the <head> of every page as possible.
  • The noscript snippet goes immediately after the opening <body> tag. It's a fallback iframe for browsers with JavaScript turned off.

The head snippet looks like this, with your own container ID in place of GTM-XXXXXXX:

<!-- Google Tag Manager -->
<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>
<!-- End Google Tag Manager -->

Put it in a shared template (a header include, a layout component) so it appears on every page, including templates that are easy to forget, like checkout steps, landing pages and the 404 page.

Step 3: Platform specific notes#

WordPress. Don't paste the snippet into a parent theme's header.php: the next theme update overwrites it. Instead use a header and footer code plugin, Google's own Site Kit plugin (which can place the GTM container for you), or a child theme. Pick one method and remove any others, so the container isn't loaded twice.

Shopify. Adding GTM to your theme's theme.liquid covers storefront pages, but Shopify's checkout doesn't run theme code. For checkout and purchase events, Shopify uses its Customer events feature (custom pixels) or the Google and YouTube app. Plan purchase tracking around that, and remember that switching or duplicating a theme can leave the snippet behind in the old one.

Next.js, React and other JavaScript frameworks. Load the container once in the root layout, not inside individual pages. In single page apps, page views don't trigger full page loads, so use GTM's History Change trigger or push a page view event to the data layer on each route change.

Try it on your site · free

See which scripts your page loads

Analytics, tag managers, pixels and every other third-party script on the page.

Open the full tool

How to add GA4 to Google Tag Manager#

With the container installed, you can add Google Analytics 4. Since September 2023, the old "GA4 Configuration" tag is simply called the Google tag in GTM.

  1. In GA4, go to Admin, then Data streams, open your web stream and copy the Measurement ID (it starts with G-).
  2. In GTM, click Tags, then New, then Tag Configuration, and choose Google tag.
  3. Paste the measurement ID into Tag ID.
  4. Under Triggering, choose Initialization - All Pages, so the Google tag loads before other tags that depend on it. (All Pages also works for simple setups.)
  5. Name the tag clearly, such as "Google tag - GA4 - G-XXXX", and save.

To track specific actions, add Google Analytics: GA4 Event tags. For example, a generate_lead event that fires on a form submission trigger, or a purchase event that reads the order value from the data layer.

If you have visitors in the European Economic Area or the UK, you need consent mode. It tells Google's tags whether a visitor has granted consent for analytics and advertising storage, and the tags adjust their behavior. Google's tags, including the Google tag, have consent checks built in. In practice that means setting default consent states (usually denied) before GTM loads, then sending an update when the visitor accepts in your cookie banner. Most consent management platforms offer a GTM template that handles this for you.

Check consent first when GA4 shows suspiciously low numbers after a cookie banner change. Our guide to Google Analytics not tracking walks through the other causes.

How to test with Preview mode and Tag Assistant#

Never publish untested changes. Click Preview in the top right of your workspace. GTM opens Tag Assistant, asks for your site's URL and loads your site in a new tab connected to the debugger.

In Tag Assistant you can see:

  • Which tags fired and which didn't, on each event (Container Loaded, DOM Ready, Window Loaded, clicks, form submissions, custom events).
  • Why a tag didn't fire, by checking which trigger conditions passed or failed.
  • The data layer at every step, so you can confirm your site is pushing the values you expect.
  • Variable values, such as the click text or page path GTM read at that moment.

Then confirm the data arrives at the other end. In GA4, open Admin, then DebugView: your preview session's events should appear within seconds.

Publishing and versions#

When the preview looks right, click Submit. Give the version a descriptive name and a short description ("Add GA4 purchase event with order value"), then click Publish.

Good habits that save you later:

  • Name versions properly. "Version 47" tells you nothing six months from now.
  • Use workspaces for separate pieces of work, so one half finished change doesn't block another.
  • Roll back fast. If something breaks after publishing, go to Versions, open the last good version and publish it again.
  • Limit publish rights. Give most users Edit or Approve permission and keep Publish for a few people.

Common Google Tag Manager mistakes#

MistakeWhat happensFix
GA4 installed with gtag.js and through GTMEvery page view is counted twiceKeep one route per measurement ID; remove the other
Container installed twice (theme plus plugin)Tags fire twice, data layer events duplicateSearch the page source for your GTM- ID; it should appear once in the head
Snippet in a parent theme fileA theme update deletes it and tracking stopsUse a plugin, child theme or shared layout
Snippet missing from some templatesLanding pages or checkout steps go untrackedLoad the container from a shared template on every page
Tags fire before consentPrivacy compliance risk, and data may be modeled or lostSet consent defaults before GTM loads; use consent mode
Triggers based on CSS classes or button textA redesign silently breaks conversion trackingPush events to the data layer instead
Wrong container ID after copying a siteData goes to another site's container, or nowhereCheck the ID in the source matches your container
Unpublished changesEverything works in Preview but not for real visitorsSubmit and publish after testing

The double tracking mistake is the most common one we see, and it's hard to spot in reports: traffic simply looks healthier than it is, and engagement rates look worse.

How to check if Google Tag Manager is installed#

There are four quick ways to confirm GTM is on a page and working:

  1. View the page source (Ctrl+U or Cmd+Option+U) and search for GTM-. You should find your container ID in the head snippet, once.
  2. Use a free checker. The MyKavo Analytics Tag Checker reads a live page and lists the GA4 measurement IDs, GTM containers, Google Ads tags and other analytics tools it finds. It also flags pages that have both a direct GA4 tag and a GTM container, so you can check for double counting. If GA4 is configured only inside GTM, it won't be in the HTML, and the checker tells you so.
  3. Use Tag Assistant at tagassistant.google.com to connect to the page and watch which tags fire.
  4. Check the network. In your browser's developer tools, open the Network tab and filter for gtm.js. A 200 response means the container loaded.

To see every third party script a page loads, not only analytics, run it through the free Script Detector, or read our guide on how to see what scripts a website uses.

Keep Google Tag Manager from disappearing#

A GTM container rarely breaks on the day you set it up. It breaks later, when something else changes: a theme update overwrites header.php, a developer swaps the layout component, a plugin conflict stops the header code from printing, or a site migration ships without the snippet. Nothing errors. Pages load fine. You find out weeks later, when someone asks why conversions fell off a cliff.

MyKavo loads your monitored pages in a real browser on a schedule and records every external script against an approved baseline. Google Tag Manager, Google Analytics, Meta Pixel, Stripe, Hotjar, Intercom and HubSpot are recognized by name. If one of them disappears from a page, you get a high severity alert titled, for example, "Google Tag Manager script disappeared", with the page it vanished from. If an unknown third party script appears, you get a medium alert, which also helps you catch tags someone added without telling you.

Frequently asked questions

What is Google Tag Manager used for?

Google Tag Manager is used to add and manage tracking tags, such as GA4, Google Ads conversions and ad pixels, from one web interface instead of editing your website's code each time.

Is Google Tag Manager free?

Yes. The standard version of Google Tag Manager is free. Google also offers Tag Manager 360 as part of its paid Google Marketing Platform for large enterprises.

Do I need Google Tag Manager if I have Google Analytics?

Not always. If you only need GA4, installing the Google tag directly works fine. GTM is worth it when you run several tags or want marketers to change tracking without a developer.

Where do I put the Google Tag Manager code?

Put the script snippet as high in the head of every page as possible, and the noscript snippet immediately after the opening body tag. Use a shared template so every page gets both.

Why is my data counted twice after installing GTM?

Usually because GA4 is also installed directly with gtag.js, or the GTM container is loaded twice by a theme and a plugin. Keep one installation route per measurement ID.

How do I know if Google Tag Manager is working?

Use Preview mode and Tag Assistant to see which tags fire, check GA4 DebugView for incoming events, and search the page source for your GTM container ID.

The bottom line#

Google Tag Manager gives you one place to manage every tracking tag on your site. Set it up with one container per site, install both snippets from a shared template, add GA4 through the Google tag, build triggers on data layer events rather than page design, and always test in Preview before you publish. Then watch for the quiet failures: double tracking, missing consent defaults, and a container that disappears after the next theme update or deploy.

Check what's installed on any page right now with the free Analytics Tag Checker, then start free with MyKavo to get alerted the moment Google Tag Manager or your analytics script goes missing.

Share this post

Get alerted when your site breaks. Free, no card.

Start free