How to Install Google Tag Manager and Verify It With Tag Assistant

By the Mayab Media Team · Level: Beginner · Time: 45 minutes

You pasted the Google Tag Manager code into your site, but Tag Assistant says it can't find the container. Or GTM works on some pages and not others. Or GA4 now counts every page view twice. All of these come from the same place: how and where the container was installed.

Google Tag Manager (GTM) is a container that loads your other tags, such as GA4, Google Ads and Meta. You install it once, with two small snippets, and then manage tags from the GTM interface instead of editing the site each time. Getting that first install right matters, because every tag you add later depends on it.

This guide walks through creating the container, placing the code on a custom site, WordPress, Shopify and Squarespace, adding your first tag, and verifying everything with Tag Assistant before and after you publish.

Quick answer

  1. Create a Web container at tagmanager.google.com and copy the two install snippets.
  2. Paste the first snippet as high in the <head> as possible and the <noscript> snippet right after the opening <body> tag, on every page.
  3. Remove any other copies of GTM or hard-coded GA4 tags that would duplicate data.
  4. Add a Google Tag in GTM with your GA4 ID, triggered on all pages.
  5. Click Preview, connect Tag Assistant to your site, and confirm the container and tag show up.
  6. Click Submit > Publish, then check the live site again with Tag Assistant.

Before you start

You need:

  • A Google account with permission to create a GTM account, or Publish access to an existing container.
  • Access to edit your site's code, theme or code injection area.
  • Your GA4 measurement ID (it starts with G-) if you plan to add GA4 now.
  • Chrome, plus the Tag Assistant extension if you want the smoothest preview connection.

Check two things first.

Is there already a container? Open your site, right-click and choose View page source. Search for googletagmanager.com/gtm.js. If you find a GTM ID, find out who owns it before you add a new one. Two containers often mean double tracking.

Is GA4 hard-coded? Search the source for gtag/js?id=G-. If GA4 is already installed directly and you plan to move it into GTM, you'll remove the old code in Step 3.

Back up your theme or copy the current header code into a text file before you edit anything.

Step 1: Create the account and container

Go to tagmanager.google.com and click Create Account. Fill in:

  • Account name: your company name.
  • Country.
  • Container name: usually your domain, like example.com.
  • Target platform: choose Web.

Click Create and accept the terms. GTM opens the new container's workspace and shows the install code.

tagmanager.google.com/#/admin/accounts/createTag ManagerAdd a new accountAccount nameExample StudioCountryUnited StatesContainer nameexample.comTarget platformWebiOSAndroidServerCreate1
Figure 1. Pick Web for a website container. Server is a different setup for server-side tagging. Illustration of the screen. Labels can differ slightly in your account.
  1. Web is the right choice for a normal website.

If the account already exists, open it and click Create Container instead.

Step 2: Copy the install code

The Install Google Tag Manager dialog opens after you create the container. To open it later, click your container ID (it looks like GTM-XXXXXXX) at the top of the Workspace tab. You'll also find Install Google Tag Manager in the Admin tab.

tagmanager.google.com/#/container/accounts/1/containers/2/workspaces/3Tag ManagerInstall Google Tag ManagerCopy the code below and paste it onto every page of your website.Paste this code as high in the <head> of the page as possible:<!-- 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'});...})(window,document,'script','dataLayer','GTM-XXXXXXX');</script><!-- End Google Tag Manager -->Additionally, paste this code immediately after the opening <body> tag:<!-- 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>Test your websitehttps://example.comTestOK12
Figure 2. Two snippets: the script for the head and the noscript iframe for right after the body tag. Illustration of the screen. Labels can differ slightly in your account.
  1. The main snippet. It loads the container asynchronously and goes high in the <head>.
  2. The <noscript> snippet. It only matters for visitors with JavaScript turned off, and it goes right after <body>.

Copy the code from your own dialog. The ID inside must be your container's ID, in both snippets.

Step 3: Install the snippets on your platform

The rule is the same everywhere: every page gets the head snippet once, and the body snippet once. Here's how that looks on common platforms.

Custom or hand-coded sites

Edit the shared header template, not individual pages:

<head>
  <meta charset="utf-8">
  <!-- Google Tag Manager -->
  <script>(function(w,d,s,l,i){ /* your GTM snippet */ })(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
  <!-- End Google Tag Manager -->
  <title>Example</title>
  ...
</head>
<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>
  ...

If you use a consent management platform (CMP) that must set Consent Mode defaults first, follow its instructions for order. Usually the CMP's script or the consent default command goes just before the GTM snippet.

WordPress

You have three common options. Pick one, not several.

  • A header and footer code plugin (for example WPCode or similar). Paste the head snippet in the header box and the noscript snippet in the "body" box.
  • Site Kit by Google. It can connect Tag Manager and place the container for you.
  • A child theme. Add the snippets with the wp_head and wp_body_open hooks in functions.php. Don't edit the parent theme's header.php, because updates overwrite it.
add_action('wp_head', function () { ?>
  <!-- GTM head snippet here -->
<?php }, 1);
add_action('wp_body_open', function () { ?>
  <!-- GTM noscript snippet here -->
<?php });

After you install, clear any caching plugin and your CDN cache. Cached pages may still serve the old HTML without GTM.

Shopify

Shopify has two areas that behave differently.

  • Storefront pages (home, collections, products, cart): add the snippets to your theme's theme.liquid file. Open Online Store > Themes, click the three dots > Edit code, and paste the head snippet right after <head> and the noscript after <body>. Duplicate the theme first.
  • Checkout and thank-you pages: theme code doesn't run there. Shopify uses Customer events (custom pixels) under Settings for checkout tracking. A GTM container loaded inside a custom pixel runs in a sandbox, so Preview mode and many built-in triggers don't work the usual way.

For Google Ads and GA4 on Shopify, many practitioners use the Google & YouTube app for purchase tracking and keep GTM for other tags. Decide this before you install so you don't count purchases twice.

Squarespace

Use Code Injection. On current Squarespace versions it's under Website > Pages > Custom code > Code Injection (older menus put it under Settings > Advanced). It isn't available on every plan.

example.squarespace.com/config/pagesWebsite builderPagesDesignCommerceCUSTOM CODECode InjectionCustom CSSCode InjectionHeader code is inserted inside the head of every pageHeader<!-- Google Tag Manager --><script>(function(w,d,s,l,i){ ... })(window,document,'script','dataLayer','GTM-XXXXXXX');</script>FooterSave1
Figure 3. Paste the GTM script in Header. The builder has no slot right after the body tag. Illustration of the screen. Labels can differ slightly in your account.
  1. The GTM head snippet goes in Header.

Squarespace doesn't give you a slot right after <body>. Don't paste the noscript iframe into the Header box, because an iframe inside <head> is invalid and can break the page head. Skipping the noscript part only affects visitors without JavaScript. Squarespace also has a built-in Google Analytics field. If you load GA4 through GTM, leave that field empty.

Remove duplicates

Now remove anything that would double up:

  • An old hard-coded gtag.js GA4 snippet, if GA4 will now run from GTM.
  • A plugin or platform setting that also adds GA4 with the same ID.
  • A second GTM container nobody uses.

Step 4: Add your first tag (Google tag for GA4)

In GTM, go to Tags > New. Click Tag Configuration and choose Google Tag. Paste your GA4 measurement ID (G-XXXXXXXXXX) in Tag ID.

Under Triggering, choose Initialization - All Pages. This fires the Google tag early, before most other tags. Name the tag something clear, like "Google tag - GA4", and click Save.

tagmanager.google.com/#/container/.../tags/newTag ManagerGoogle tag - GA4Tag ConfigurationTag type: Google TagTag IDG-XXXXXXXXXXConfiguration settings · Shared event settingsTriggeringInitialization - All PagesInitializationSave12
Figure 4. The Google tag with your GA4 ID, firing on Initialization - All Pages. Illustration of the screen. Labels can differ slightly in your account.
  1. Your GA4 measurement ID from Admin > Data streams in GA4.
  2. The built-in Initialization - All Pages trigger.

If your site uses a consent banner, make sure Consent Mode defaults are set before this tag fires. That's a separate setup, but test it in the next step.

Step 5: Preview and debug with Tag Assistant

Nothing goes live until you publish. Preview lets you test first.

  1. In the GTM workspace, click Preview (top right). Tag Assistant opens in a new tab.
  2. Enter your site's URL and click Connect. Your site opens in a new window.
  3. A small badge in the corner of your site says Tag Assistant is Connected.
  4. Go back to the Tag Assistant tab and click Continue.
tagassistant.google.com/#/?source=TAG_MANAGER&id=GTM-XXXXXXXTag AssistantSummaryConsentInitializationContainer LoadedDOM ReadyWindow LoadedGTM-XXXXXXXConnected to https://example.com/TagsVariablesData LayerConsentErrorsTags FiredGoogle tag - GA4Google Tag - Fired 1 timeTags Not FiredForm submit - GA4 eventGoogle Analytics: GA4 Event12
Figure 5. Tag Assistant lists the container, the event timeline on the left and which tags fired. Illustration of the screen. Labels can differ slightly in your account.
  1. Your Google tag should be under Tags Fired on the first page.
  2. Tags waiting for a specific action stay under Tags Not Fired until that action happens.

Click around your site. Each page and action adds events to the left timeline, like Container Loaded, DOM Ready and Window Loaded. Click an event to see which tags fired at that moment.

Check the Consent tab if you use Consent Mode. It shows the default and updated states for ad_storage, analytics_storage, ad_user_data and ad_personalization.

If you need to test on a device or with a colleague, use Share from the Tag Assistant menu to send a preview link.

Step 6: Publish and check the live site

Back in GTM, click Submit. Add a Version name like "Install GTM + Google tag GA4" and a short description. Click Publish.

Now check the live site without preview:

  1. Open tagassistant.google.com, click Add domain, enter your URL and connect. It should find your container and Google tag.
  2. Open the page source and confirm the GTM snippet is there, once.
  3. In Chrome DevTools, open Network, reload, and filter for gtm.js. You should see one request with your container ID.
  4. In GA4, open Reports > Realtime and confirm you show up as an active user.

If GA4 still shows nothing, our guide on troubleshooting GA4 with Realtime and DebugView goes through every cause.

Still not working? Common causes

Symptom Likely cause Fix
Tag Assistant says no container found Snippet missing, wrong ID, or page served from an old cache View source, check the ID, clear site and CDN caches
Tag Assistant won't connect in Preview Ad blocker, pop-up handling, or debug parameter breaks the page Disable blockers, install the Tag Assistant extension, or untick Include debug signal in the URL
Container loads on some pages only Snippet in one page template, not the shared header Move it to the global header template or site-wide injection
GA4 page views counted twice GA4 hard-coded and also in GTM, or two containers Keep one source of GA4 and remove the other
Works in Preview, not live Changes were never published, or wrong environment Click Submit > Publish; check Versions for the live version
gtm.js blocked in the console Content Security Policy doesn't allow googletagmanager.com Add GTM and Google domains to the CSP allowlist
Shopify purchases not tracked via GTM Checkout doesn't run theme code Use the Google & YouTube app or a custom pixel in Customer events
Page layout broken at the top noscript iframe pasted into the head Move it after <body>, or omit it where the platform has no body slot
Tags fire before consent GTM loads before the consent default is set Load the CMP or consent defaults before GTM and test in the Consent tab
Tag Assistant shows two containers Old agency or plugin container still installed Confirm ownership and remove the unused one

Caching and page builders

Caching plugins and CDNs often keep serving HTML from before you added GTM. Purge everything after installing. Some page builders also have their own "header scripts" field. Use only one place for the snippet.

Server-side and first-party setups

If someone set up server-side tagging, the snippet may load from your own domain instead of googletagmanager.com. That's fine. Verify it the same way in Tag Assistant, and don't add a second standard snippet next to it.

How to confirm it's fixed

You're done when all of these are true:

  1. Page source shows one GTM head snippet with your ID, on every template you checked (home, a blog post, a product or service page, a form page).
  2. Tag Assistant, connected without Preview, finds the container and the Google tag.
  3. GTM Versions shows your published version as Live.
  4. GA4 Realtime shows your visit within a minute or two.
  5. There are no duplicate page view events in GA4 DebugView or Realtime.

Check again after any theme update or redesign. Theme changes are the most common way GTM disappears.

Once the container is in place, you can add more tags. Next steps that usually come right after: setting up Consent Mode v2 in GTM and tracking form submissions.

FAQ

Do I need the noscript snippet?

It only runs for visitors with JavaScript turned off, which is rare. Most JavaScript tags, including GA4, don't run there anyway. Add it where your platform allows, and skip it where it would land inside <head>.

Can I use GTM and gtag.js at the same time?

You can, but don't send the same GA4 data from both. Pick one place for each tag. Duplicates are the most common reason for doubled page views.

Will GTM slow down my site?

The container loads asynchronously, so it doesn't block the page by itself. What you put inside it can. Remove unused tags and check Core Web Vitals after big changes.

Who should own the GTM account?

The business should. Create it under a company Google account and give agencies or freelancers user access. That way you never lose access when people change.

Is Tag Assistant Companion still needed?

Google merged the Companion into the main Tag Assistant extension. Install the current Tag Assistant extension for the smoothest preview connection.

Stuck on this one? We fix these for clients every week. Book a free audit

Sources

Previous
Previous

GA4 Not Showing Data? Fix It With Realtime, DebugView and Tag Assistant

Next
Next

How to Add Schema Markup (JSON-LD) and Test It