Google Tag Manager

How to Install Google Tag Manager on Your Website

Create a Google Tag Manager account, install the container code on your site, and verify it's working. About 10 minutes on WordPress, Shopify, or any website.

9 min read
Quick answer

Create a free account at tagmanager.google.com, then copy the two code snippets from Admin > Container > Install Google Tag Manager into your site: the first goes high in the head section, the second right after the opening body tag. Your container ID looks like GTM-XXXXXXX, and the whole setup takes about 10 minutes.

By the end of this tutorial, you’ll have Google Tag Manager installed on your website and ready to manage all your tracking codes from one place. The setup takes about 10 minutes. The GTM side is identical on every platform; the only thing that changes is where you paste the code, whether you’re on WordPress, Shopify, Squarespace, or a hand-coded site.

What is Google Tag Manager (and why use it)?

Google Tag Manager (GTM) is a free tool that lets you add and manage tracking codes on your website without editing your site’s code every time. Those tracking codes are called tags. Here’s what that means: a tag is a small piece of code that sends data to a tool like Google Analytics, Google Ads, or Meta.

In plain English: instead of pasting a new tracking code into your site’s HTML every time you want to measure something, you install Google Tag Manager once. From then on, you add, edit, and remove tags from GTM’s web interface. No developer required for most changes.

GTM and Google Analytics do different jobs, and mixing them up is the most common point of confusion. GA4 collects and reports your data. GTM is the delivery system that puts GA4 (and any other tracking tool) on your site. If you’re new to analytics in general, start with our GA4 beginner’s guide. And once you finish the install below, our Google Tag Manager tutorial explains tags, triggers, and variables in depth.

Before you start

What you need

Three things: a Google account, admin access to your website (or the ability to edit its code), and about 10 minutes.

Already have GA4 installed directly on your site? That’s fine, and you don’t need to undo anything today. Follow our Google Analytics installation guide if you’re not sure how it was set up. You can move that setup into GTM later; we cover the handoff at the end of this tutorial.

Step 1: Create your GTM account and container

1

Open Tag Manager

Go to tagmanager.google.com and sign in with your Google account. Click Create Account.

2

Fill in the setup form

GTM asks for a few details:

  • Account Name: your company name (for example, “Acme Coffee”).
  • Container Name: your website URL (for example, “acmecoffee.com”). A container is the bucket that holds every tag for one website.
  • Target platform: choose Web.
3

Create and accept the terms

Click Create. GTM shows its Terms of Service; review and accept them to continue.

You should now see

the GTM workspace for your new container, with your container ID in the top bar. It follows this format:

Container ID
GTM-5FJ2K8Q

Every container gets an ID that starts with GTM- followed by letters and numbers. You’ll paste this ID into plugins and platform settings, so keep it handy.

Screenshot placeholder
Tag Manager › Workspace: the container ID sits in the top bar

Step 2: Get the GTM code snippets

Right after you create the container, GTM opens a popup with two code snippets. If you closed it, click your container ID in the top bar, or find it any time here:

Admin Container Install Google Tag Manager

The two snippets do different jobs:

  • The first snippet goes as high in the <head> section of every page as you can place it. This is the code that loads GTM.
  • The second snippet goes right after the opening <body> tag. It’s a fallback (a <noscript> iframe) that keeps GTM working for the rare visitor whose browser has JavaScript turned off.

Here’s what they look like, with GTM-XXXXXXX standing in for your real container ID:

Snippet 1: goes in <head>
<!-- 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 -->
Snippet 2: goes after opening <body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
Order matters

Put each snippet where it belongs: the first in <head>, the second right after the opening <body> tag. If they’re swapped, GTM loads late or unreliably instead of as soon as the page starts loading. Copy each one from GTM (not from this page) so it carries your real container ID.

Screenshot placeholder
Tag Manager › Admin › Install Google Tag Manager

Google’s own Install a web container guide covers edge cases like server-side setups if you need them later.

Step 3: Install the code on your platform

How you add those snippets depends on where your site lives:

PlatformInstallation methodTime
WordPressGTM4WP plugin or manual code5 min
ShopifyEdit theme.liquid5 min
SquarespaceCode Injection settings3 min
Custom HTMLPaste into template2 min

WordPress

Option A: use a plugin (recommended). The GTM4WP plugin places both snippets for you.

  1. Go to Plugins > Add New Plugin and search for “GTM4WP”. The plugin you want is by Thomas Geiger.
  2. Click Install Now, then Activate.
  3. Go to Settings > Google Tag Manager.
  4. Paste your container ID (the GTM-XXXXXXX value) into the Google Tag Manager ID field.
  5. Leave the container code placement setting at its default and click Save Changes.

Site Kit by Google works too. It connects to your Google account and sets up Tag Manager without any pasting, though it gives you fewer placement controls than GTM4WP.

Screenshot placeholder
WordPress › Settings › Google Tag Manager

Option B: paste the code manually. A code-snippet plugin like WPCode (formerly Insert Headers and Footers) gives you a header box for snippet 1 and a body box for snippet 2. You can also edit your theme’s header.php directly, but a plugin survives theme updates; direct edits don’t unless you use a child theme (a safe copy of your theme that survives updates).

Shopify

  1. From your Shopify admin, go to Online Store > Themes.
  2. On your current theme, click the three-dot menu > Edit code.
  3. Open theme.liquid in the Layout folder.
  4. Paste snippet 1 right after the opening <head> tag, so it sits as high in the head as possible.
  5. Paste snippet 2 right after the opening <body> tag.
  6. Click Save.

One note: code in theme.liquid doesn’t run on Shopify’s checkout pages. Tracking checkout requires a custom pixel set up through customer events, which is beyond this tutorial.

Squarespace

Code Injection requires a plan that includes it: the current Core, Plus, or Advanced plans, or the legacy Business and Commerce plans. Personal plans don’t have it.

  1. Go to Website > Website Tools > Code Injection (some older accounts show Settings > Developer Tools > Code Injection instead).
  2. Paste snippet 1 into the Header box.
  3. Paste snippet 2 into the Footer box.

One thing to know: Squarespace doesn’t let you place code right after the opening <body> tag, so the Footer box is the closest available spot for snippet 2. That’s a Squarespace limitation, and it’s fine in practice. Snippet 2 is only a fallback for browsers without JavaScript.

Custom HTML site

Paste snippet 1 into the <head> of your page template and snippet 2 right after the opening <body> tag. If your site doesn’t use a shared template, add both snippets to every page you want to track.

Step 4: Verify GTM is installed correctly

Don’t skip this part. A broken install fails silently, and you won’t find out until weeks of data are missing.

Method 1: Preview mode (the best check). In your GTM workspace, click Preview in the top right. A tool called Tag Assistant opens. Enter your website’s URL and click Connect. Your site opens in a new window with a Tag Assistant badge in the corner.

You should now see

“Connected!” in the Tag Assistant tab, and a Container Loaded event in the debug pane on the left. That means GTM is live on your page.

Screenshot placeholder
Tag Manager › Preview › Tag Assistant: Connected

Method 2: the Tag Assistant Chrome extension. Install the Tag Assistant Companion extension from the Chrome Web Store. It helps Preview mode connect reliably and shows which Google tags fire on any page you visit.

Method 3: check the page source. Right-click any page on your site and choose View Page Source. Press Ctrl+F (Cmd+F on Mac) and search for GTM-. Your container ID should appear twice: once for each snippet.

If none of these checks pass, jump to the troubleshooting section below.

Step 5: Publish your container

This is the step most tutorials gloss over, and it’s where most installs quietly stall. GTM uses a draft-and-publish workflow: changes you make in the workspace don’t go live until you publish them.

1

Click Submit

In the top right of your workspace, click Submit.

2

Name the version

Give the version a name like “Initial setup”. A short description helps future-you remember what changed.

3

Publish

Click Publish in the top right.

You should now see

a summary screen for Version 1. Open the Versions tab at the top of GTM and you’ll see it listed in your container’s version history.

Screenshot placeholder
Tag Manager › Versions: Version 1 is live

Troubleshooting: GTM installed but not working?

These four mistakes cause almost every failed GTM install.

1. The code is in the wrong place. Snippet 1 must be in <head>, not <body>. Snippet 2 goes right after the opening <body> tag. If they’re swapped or both sitting in the footer, GTM loads late or not at all. Re-check placement against Step 2.

2. You never published. Installing the code on your site is only half the job. Until you click Submit > Publish in GTM, no tags fire. Many people install GTM, add tags, and wonder why nothing tracks: the container is still in draft. Check your Versions tab; if it’s empty, that’s the problem.

3. A caching plugin is serving old pages. On WordPress, plugins like WP Super Cache and W3 Total Cache keep copies of your pages from before you added GTM. Clear the cache after installing, then re-run the page source check.

4. GA4 is installed twice. If you previously added the GA4 tag directly to your site and later add GA4 through GTM as well, every visitor gets counted twice and your traffic numbers double overnight. When you move GA4 into GTM, remove the direct GA4 code from your site.

What to do next

Your GTM container is installed, verified, and published. Right now it’s also empty: it isn’t tracking anything yet. A container with no tags is like wiring with nothing plugged in.

Your first tag should almost certainly be Google Analytics. Our guide to adding GA4 through Google Tag Manager walks you through it, including how to retire a direct GA4 install without double-counting.

From there, work through the Google Tag Manager tutorial to learn triggers and variables, the two building blocks behind tracking button clicks, form submissions, and everything else your boss will eventually ask about.

Frequently asked questions

What's the difference between Google Tag Manager and Google Analytics?
Google Analytics 4 collects and reports data about your visitors. Google Tag Manager doesn't collect anything itself; it's the container that loads GA4 and other tracking codes on your site. You can tell them apart by their IDs: GA4 uses a Measurement ID that starts with G-, while GTM uses a container ID that starts with GTM-.
Do I need Google Tag Manager if I already have GA4 installed?
No. GA4 works on its own if you installed its tag directly on your site. GTM earns its keep when you manage more than one tracking tool, or when you want to track things like button clicks without editing code. If you do move GA4 into GTM, remove the direct GA4 code first, or every visitor gets counted twice.
Will Google Tag Manager slow down my website?
Not in a way most visitors would notice. The GTM container script loads asynchronously, meaning it doesn't block your page from rendering. The total impact depends on how many tags you add through it, not on GTM itself. Slowdowns come from loading dozens of heavy third-party tags, not from the container.
Can I use Google Tag Manager on multiple websites?
Yes. One GTM account can hold many containers, and Google recommends one container per website. To add another site, go to Admin and click the plus icon at the top of the Container column. The new container gets its own GTM-XXXXXXX ID, and you install that ID's snippets on the new site.
I installed GTM but Preview mode says "not connected." What's wrong?
First check that the code is actually on the page: right-click your site, choose View Page Source, and search for GTM-. If your container ID isn't there, the snippets didn't save, or a caching plugin is serving an old copy of the page, so clear your site cache. If the ID is there, an ad blocker or privacy extension is usually what's blocking Tag Assistant. Turn those off and run Preview again.

Keep learning