Setup & site building · Guide
How to Add Google Tag Manager to WordPress
Short answer
To add Google Tag Manager to WordPress, create a free Tag Manager account and container, then install it with the Site Kit by Google plugin or the free GTM4WP plugin by entering your container ID. Both plugins place the code for you, so you do not need to edit theme files. After that, add your Google Analytics 4 tag inside Tag Manager, preview it, and publish the container.
Key takeaways
- Google Tag Manager is free, and you manage tags inside it instead of editing your site's code.
- Each container has an ID starting with “GTM”, and you need one container per website.
- Site Kit by Google places the Tag Manager code for you and needs WordPress 5.2 or newer.
- GTM4WP has more than 700,000 active installs and fills the data layer with WordPress page and user data.
- The data layer must be created before Tag Manager loads, and its name is case-sensitive.
- Preview your container with Google Tag Assistant before you publish a named version.
What is Google Tag Manager?
Google Tag Manager is a free tool that lets you add and update tracking tags without editing your site's code.
Google describes Tag Manager as a free tag management system that lets you add and update tags, HTML and code snippets on your website without directly editing the site's code (Site Kit). It also lets you configure and deploy tags from Google products and third parties (Google Support).
Instead of pasting a new code snippet for every tool, you paste the Tag Manager container once and manage the rest inside Tag Manager. That is the whole point of the tool: one install, many tags.
How do you create a Tag Manager account and container?
Create an account for your company, then one container for each website.
Google's setup guide says to create a Google Tag Manager account that represents the top level of organisation for your company, then create one container for each of your company's websites and apps (Google Support). Go to tagmanager.google.com, sign in, open the Accounts tab and click Create Account.
Enter the account name and country, then name the container.
For a website, use the top-level URL, such as www.example.com, and choose the Web container type. You do not need a container for each page. The other container types are iOS, Android, AMP and Server.
Each container gets an ID that starts with “GTM”, for example GTM-AB12CDE3. You will need that ID when you connect WordPress, so copy it from the Workspace tab, where clicking the container ID opens the install dialog (Google Support).
How do you install Tag Manager with Site Kit?
Site Kit by Google is the official Google plugin, and it places the Tag Manager code for you.
Site Kit is the official WordPress plugin from Google for insights about how people find and use your site, and it is free and open source (WordPress.org). It supports Search Console, Analytics, AdSense, PageSpeed Insights, Tag Manager, Sign in with Google, Reader Revenue Manager and Ads.
The plugin version 1.192.0 was updated 16 November 2026 and holds a 4.2 out of 5 rating from 1,016 reviews. It needs WordPress 5.2 or newer, PHP 7.4 or newer, a publicly accessible site and a working REST API (WordPress.org).
To connect Tag Manager, go to Site Kit > Settings > Connect More Services > Set up Tag Manager.
Pick an existing account and container, or set up a new container, then complete the setup. A “Let Site Kit place code on your site” toggle controls whether Site Kit places the code (Site Kit).
Site Kit also offers automatic code snippet placement, so you never touch a theme file.
Site Kit recommends connecting Analytics through its own Analytics module rather than through a Tag Manager tag. Follow that advice when you set up both, so you do not count the same visit twice.
How do you install Tag Manager with GTM4WP?
GTM4WP is a free plugin that places the container code and fills the data layer for you.
GTM4WP, short for Google Tag Manager for WordPress, is a free open-source plugin with more than 700,000 active installations on WordPress.org (GTM4WP).
It holds a 4.5 out of 5 rating from 155 reviews and was updated 5 November 2026, and it needs WordPress 6.3 or newer and PHP 8.0 or newer.
Install it from Plugins > Add New, or with WP-CLI using wp plugin install duracelltomi-google-tag-manager --activate. After activation, open Settings > Google Tag Manager and add your container ID (GTM4WP).
The plugin places the container code snippets on your site so you do not add them by hand, and it pushes page data into the data layer.
That data includes post and page titles, dates, category and tag slugs, author ID and name, post and page ID, post types, logged-in status, role and user ID, site search data, plus browser, operating system and device data (WordPress.org).
GTM4WP also supports multiple containers, each with its own environment settings, custom domain and custom path. Its integrations include WooCommerce, Contact Form 7, Easy Digital Downloads, WPML and Polylang, plus Google Consent Mode v2 and a tag allowlist and blocklist for security.
Which plugin should you choose: Site Kit or GTM4WP?
Choose Site Kit for a simple Google setup, and GTM4WP for deeper Tag Manager control.
| Feature | Site Kit by Google | GTM4WP |
|---|---|---|
| Price | Free | Free |
| Active installs | Official Google plugin | 700,000+ |
| Minimum WordPress | 5.2 | 6.3 |
| Minimum PHP | 7.4 | 8.0 |
| Places the code | Yes | Yes |
| Data layer | Basic | Full page and user data |
| Other Google tools | Search Console, Analytics, AdSense | Tag Manager only |
| WooCommerce events | No | Yes, GA4 e-commerce events |
Site Kit is the better pick when you also want Search Console and Analytics in one dashboard. GTM4WP is the better pick when you want detailed data layer values, WooCommerce purchase events, media-player events and scroll tracking (WordPress.org).
Do not install both for Tag Manager. Two plugins placing the same container ID will load the container twice and double-count your events. Before you install either plugin, check it with our guide on how to check a plugin for vulnerabilities.
How do you add the code by hand instead?
Paste the current snippet as high in the head tag as possible.
Google's current install page shows one code block to paste as high in the head tag as possible: an async script that loads gtm.js with your container ID, plus a script that sets up the data layer and calls gtag (Google Support).
The page also offers a CMS integration path for WordPress, Shopify and Wix before the manual install.
The previous snippet had two parts: a script placed as high in the head as possible, and a noscript iframe placed just after the opening body tag as a fallback when JavaScript is off.
Google says that if your site already uses the previous snippet, you do not need to retag it, and the container will keep working (Google Support).
In a WordPress theme, the head snippet belongs where wp_head() runs. The Theme Handbook says wp_head() goes at the end of the head element in the theme's header.php file, and wp_body_open() goes at the start of the body element in the same file (WordPress Developer Resources).
The second snippet only lands in the right place if your theme supports wp_body_open(), which needs WordPress 5.2 or newer.
Edit theme files only as a last resort. A plugin survives a theme update; a hand edit in header.php does not.
What is the data layer and why does it matter?
The data layer is an object that passes information from your site to Tag Manager.
Google defines the data layer as an object used by Google Tag Manager and gtag.js to pass information to tags, and it must be created before Tag Manager loads (Google Developers). The code is window.dataLayer = window.dataLayer || [];.
Events are pushed with dataLayer.push({'event': 'event_name'});, for example 'login', 'purchase' or 'search', and variables with dataLayer.push({'variable_name': 'variable_value'});. Tag Manager processes those messages first in, first out.
Three rules matter. Do not overwrite window.dataLayer, the name is case-sensitive, so dataLayer is not the same as datalayer, and variable names must stay consistent across pages (Google Developers). GTM4WP handles most of this for WordPress sites by pushing page and user data into the layer automatically.
How do you add a Google Analytics 4 tag in Tag Manager?
Create a Google tag in Tag Manager and point it at your GA4 property.
To set up Google Analytics 4 in Tag Manager, you configure a Google tag, which sends data from your website to Google Analytics (Google Support). You need a GA4 account and property with a web data stream, plus an Editor role or above on the GA4 account.
In Tag Manager, go to Tags > New > Tag Configuration > Google Analytics > Google Analytics, enter the Tag ID in the Tag ID field, and set the trigger to Initialization - All Initialization Events (Google Support).
The other method is the “Google Tag” tag type with the same Tag ID and the same trigger.
Do not also paste the GA4 snippet directly on your site. Tag Manager loads the Google tag for you, and loading it twice counts every pageview twice. If you use Site Kit, connect Analytics through its Analytics module instead.
How do you test and publish your container?
Preview the container first, check the tags fire, then publish a named version.
Open the Workspace tab and click Preview at the top right to launch Google Tag Assistant in a new tab. Enter your website URL and click Connect, then browse your site and watch which tags fire (Google Support).
When the tags fire correctly, click Submit at the top right of the Workspace tab. Choose “Publish and Create Version” to publish, or “Create Version” to save without publishing. Enter a name and description for the version, review the activity history, then click Publish (Google Support).
Name each version after what changed, such as “Added GA4 tag” or “Fixed purchase event”. A clear version history is the fastest way to undo a bad change later.
How does consent mode work with Tag Manager?
Consent mode controls data collection based on what the visitor agreed to.
Google says consent mode lets you control data collection based on user consent for advertising and analytics purposes (Google Developers). You set the default consent state before the visitor chooses, then update it after they interact with your consent banner.
A common default denies all four settings: ad_storage, ad_user_data, ad_personalization and analytics_storage. After consent, you update those same settings to granted.
For consent tools that load slowly, wait_for_update, for example 500 milliseconds, delays tags until the tool responds (Google Developers).
GTM4WP supports Google Consent Mode v2, and it lets you exclude specific user roles from tracking and limit the container to production sites through WP_ENVIRONMENT_TYPE (WordPress.org). Use those settings so your own visits and your staging site do not pollute your data.
What mistakes should you avoid?
Avoid installing two Tag Manager plugins, because the container will load twice.
Do not paste the GA4 snippet by hand when Tag Manager already loads it. Double loading is the most common cause of doubled pageviews after a Tag Manager install.
Do not publish without previewing. A tag with the wrong trigger can fire on every page or never fire at all, and a named version lets you roll back in one click.
Do not forget consent mode when your site shows a cookie banner. Tags that fire before consent can collect data you have no right to hold.
Set the default state to denied and update it only after the visitor agrees.
If you want to compare analytics options first, read our guide to Google Analytics vs privacy-friendly analytics for WordPress.
If you want to track AI traffic through Analytics, read our guide on how to track ChatGPT traffic in Google Analytics.
Frequently asked questions
Is Google Tag Manager free?
No. Tag Manager itself is free, and both Site Kit by Google and GTM4WP are free plugins. You only pay if you add a paid tool through Tag Manager, such as a premium analytics or marketing service. There is no paid tier of Tag Manager itself.
Do I still need two code snippets to install Tag Manager?
Yes, if your theme supports wp_body_open(), which needs WordPress 5.2 or newer. The classic install uses two snippets: a script in the head and a noscript iframe just after the opening body tag. Google's current install page shows a single head snippet instead, and says sites already using the old snippet do not need to retag.
What is the data layer in Google Tag Manager?
The data layer is an object that passes information from your site to Tag Manager, such as the page title, post type and logged-in status. GTM4WP fills it automatically with WordPress data. You only need to push custom events yourself, such as a purchase or a form submission, when the plugin does not cover them.
How do I know if Tag Manager is working?
Use Preview in the Workspace tab to open Google Tag Assistant, enter your site URL and connect. Browse your site and watch which tags fire. If the GA4 tag fires on each page, publish the container. If it does not fire, check the Tag ID and the trigger before you publish anything.
Do I need to edit theme files to add Tag Manager?
No. Site Kit places the Tag Manager code for you and connects Analytics through its own module. GTM4WP also places the code and fills the data layer. Editing theme files is only needed when no plugin fits your setup, and a hand edit in header.php is lost when the theme updates.
Does Tag Manager work with cookie consent banners?
Yes. Consent mode sets the default consent state to denied and updates it to granted only after the visitor agrees. GTM4WP supports Consent Mode v2, and you can also set region-specific defaults in Tag Manager. Without it, tags may collect data before consent is given.
Sources
- Tag Manager in Site Kit Site Kit
- Set up and install Google Tag Manager Google Support
- Install Google Tag Manager Google Support
- GTM4WP download GTM4WP
- Google Tag Manager for WordPress (GTM4WP) WordPress.org
- Site Kit by Google WordPress.org
- The data layer Google Developers
- Set up Google Analytics 4 in Tag Manager Google Support
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
