How to Install Google Tag Manager on WordPress: The Right Way

April 10, 2026
by Cherry Rose

GTM4WP carries over 2 million active WordPress installations — making it the most common entry point into WooCommerce tracking, and the most common source of silent tracking errors (WordPress.org, 2025). Most stores install GTM correctly enough for the plugin to show green. Wrong enough to lose data from day one.

This guide covers how to install Google Tag Manager on WordPress the right way — not just the steps, but what actually breaks if each step is skipped or done out of order.

Plugin vs Manual: Which Install Method to Use

You have two options: install GTM via a plugin, or add the container snippet manually to your theme. The right choice depends on how your site is maintained.

Plugin Install (Recommended for Most Stores)

GTM4WP is the de facto standard for WordPress GTM installation. It handles both required snippet placements automatically, supports WooCommerce dataLayer events out of the box, and survives theme updates because the configuration lives in the WordPress database — not your theme files.

Install it from WordPress Plugins → Add New → search “Google Tag Manager for WordPress.” The only setting you need to configure on first use is your GTM Container ID (format: GTM-XXXXXXX), found in your GTM account under Admin → Container Settings.

Manual Install (Theme functions.php)

Some developers prefer adding the GTM snippet directly to functions.php via wp_head() and wp_body_open() hooks. This works — until the theme is updated or switched, at which point the snippet disappears with no warning. If you install GTM manually, your tracking goes silent every time you change themes. If you go this route, use a child theme or a code snippets plugin to protect the code from theme updates.

The manual approach also requires you to handle both snippet placements yourself. Most tutorials show only one. Google’s documentation requires both.

The Two-Snippet Rule — and Why It Matters

Google’s GTM documentation specifies two placements for the container snippet (Google Tag Manager documentation, 2025):

Snippet 1 (JavaScript): Immediately after the opening <head> tag. This is the primary container load — it fires all your GTM tags via JavaScript.

Snippet 2 (noscript fallback): Immediately after the opening <body> tag. This is an <iframe> fallback that fires for visitors with JavaScript disabled.

Manual installs frequently skip the noscript fallback. GTM4WP handles both automatically when configured correctly. The consequence of missing the <body> snippet is complete tracking failure for users with JavaScript disabled — a small but non-zero slice of every audience, and a compliance gap in some contexts.

More critically: placing the head snippet in the wrong position — lower in the page, after other scripts, or before closing </head> rather than immediately after opening — delays GTM container load and can cause tags to miss early page events entirely.

You may be interested in: When Does WooCommerce Fire Your Conversion?

The dataLayer Declaration Order Problem

This is the mistake almost no installation guide mentions — and it cascades into every downstream tracking problem.

The dataLayer is a JavaScript array (window.dataLayer) that acts as the communication channel between your website and the GTM container. Your WooCommerce store pushes events to this array — purchase data, add-to-cart events, form submissions. GTM reads from it.

Here’s the order that must be respected:

  1. The dataLayer array must be declared and populated with any page-level data
  2. Then the GTM container snippet loads and reads from it

If GTM loads before the dataLayer is initialised — or if a plugin pushes events to the dataLayer before the array itself has been declared — those events fire into a void. GTM misses them. No error appears anywhere. Your tags look fine in Preview mode on empty sessions but fail in production when real WooCommerce events fire.

GTM4WP handles dataLayer initialisation correctly. Manual installs frequently get this backwards, especially when WooCommerce event plugins are added later and their load order is not audited.

How to Verify Your GTM Install Is Working

Do not trust a green checkmark in a plugin settings page. Verify the actual container load using these three checks:

GTM Preview Mode

In your GTM account, click Preview and enter your WordPress site URL. Your site opens in a debug panel. If the GTM container is loading correctly, you’ll see a “Tag Assistant Connected” confirmation and a list of events firing as you browse. If nothing appears, the container is not loading — check your Container ID and snippet placement.

Browser Network Tab

Open Chrome DevTools (F12) → Network tab → filter by “gtm.js”. Reload your page. You should see a 200 response for googletagmanager.com/gtm.js?id=GTM-XXXXXXX. A blocked or missing request means the snippet didn’t load — or an ad blocker caught it.

Tag Assistant Chrome Extension

Google’s Tag Assistant extension shows GTM container status directly in the browser. It flags incorrect installations, missing snippets, and container ID mismatches. Worth installing for any site where tracking is business-critical.

You may be interested in: WooCommerce Says 50 Orders, GA4 Says 32, Facebook Claims 18

The Structural Ceiling You Need to Know About

A correct GTM install is the necessary foundation. It’s not the complete solution.

GTM is a web container — it runs in the visitor’s browser via JavaScript. That means it is exposed to everything that runs in browsers: ad blockers, privacy settings, and browser-enforced restrictions. 31.5% of users globally run ad blockers (Statista, 2024). Ad blockers do not selectively block individual GTM tags — they block the GTM container script URL (googletagmanager.com/gtm.js) entirely. When the container doesn’t load, no tags fire at all — not Google Ads, not GA4, not Facebook Pixel (Seresa, 2025).

WordPress powers 43.4% of all websites globally (W3Techs, 2025), and most of those sites are relying on a web GTM install as their primary data collection layer. A correctly installed GTM container is the best version of that approach. But it still only captures what browsers allow through.

If your WooCommerce order count and GA4 purchase events consistently diverge, the install is the right place to start — but it may not be where the gap ends. Transmute Engine™ is a first-party Node.js server that runs on your subdomain (e.g., data.yourstore.com). The inPIPE WordPress plugin captures WooCommerce conversion events at the server level via PHP hooks and sends them via API to Transmute Engine — which routes them simultaneously to GA4, Google Ads, and Facebook CAPI without touching the browser. No GTM required. No ad blocker exposure.

Key Takeaways

  • Use GTM4WP over manual installation — it survives theme changes, handles both snippet placements, and manages dataLayer initialisation correctly.
  • GTM requires two snippet placements: JavaScript immediately after <head>, and noscript immediately after <body>. Missing either creates tracking gaps.
  • dataLayer must be declared before the GTM snippet loads — events pushed before this order is respected fire into a void with no visible error.
  • Verify with GTM Preview mode, not plugin settings — Preview mode shows you what’s actually firing on real page loads.
  • A correct install is necessary but not sufficient — 31.5% of users run ad blockers that block the GTM container URL entirely, regardless of install quality.
What is the correct way to install Google Tag Manager on WordPress without breaking my tracking?

Use the GTM4WP plugin from the WordPress plugin directory. Enter your GTM Container ID (format: GTM-XXXXXXX) in the plugin settings. GTM4WP automatically places both required snippets — the JavaScript snippet immediately after the opening head tag, and the noscript fallback after the opening body tag — and handles dataLayer initialisation in the correct order. Verify the install works using GTM Preview mode before adding any tags or triggers.

Do I need a plugin or can I add GTM manually to my WordPress theme?

You can do either, but the plugin approach is safer for most stores. Manual installation via functions.php is lost whenever you switch or update your theme, causing complete tracking failure with no warning. If you install manually, use a child theme or a code snippets plugin so the GTM code is protected from theme updates. Either way, the dataLayer array must be declared and populated before the GTM container snippet loads — a detail most manual install guides skip.

Where exactly does the GTM snippet go in WordPress?

Google’s documentation requires two placements: the main JavaScript snippet immediately after the opening head tag (as high as possible), and a noscript iframe fallback immediately after the opening body tag. GTM4WP handles both placements automatically. Manual installs frequently only add the head snippet and miss the body fallback, which causes tracking to fail for visitors with JavaScript disabled and can create compliance gaps in certain regulatory contexts.

Does GTM slow down my WordPress site?

The GTM container script adds a network request to every page load, which has a minor performance cost. In practice, the container itself is lightweight — the performance impact comes from the tags loaded inside it. A GTM container with 30 tags loading on every page has a measurable impact; a lean container with 5-8 tags does not. GTM4WP uses async loading by default, which prevents the container from blocking page render.

If your WooCommerce and GA4 numbers have never agreed, start with the GTM install — then check what the install structurally cannot capture. Seresa.io covers both layers.

Share this post
Related posts