Quick answer: To set up Google Tag Manager on WordPress, create a GTM account and container, then add the two container snippets to your site: one in the <head> and one straight after the opening <body> tag. The easiest way is a plugin such as GTM4WP (Google Tag Manager for WordPress) or Google’s Site Kit. Developers can add the code through a child theme instead. Once installed, add your Universal Analytics tag inside GTM, test it with Preview mode, publish the container and remove any old tracking code so nothing is counted twice.
Why use Tag Manager on a WordPress site
Without Tag Manager, every tracking script, from Google Analytics to the Facebook pixel to an ads conversion tag, is pasted into the theme or added through its own plugin. Over time that turns into a mess of code nobody fully understands.
Google Tag Manager puts all those tags in one place:
- Add, change or remove tags without editing theme files
- Fire tags only where needed, such as a conversion tag on the thank you page
- Track clicks, form submissions, downloads and scroll depth without custom code on every page
- Test changes safely before publishing
- Keep a version history so you can roll back
For a business site with more than a couple of tags, GTM saves time and reduces mistakes. Our Google Tag Manager best practices guide covers how to keep a container tidy once it grows.
Step 1: Create your account and container
- Go to tagmanager.google.com and sign in with the Google account your business uses.
- Create an account, usually named after your company.
- Create a container named after your website, and choose Web as the target platform.
- Accept the terms. GTM shows you two code snippets.
Keep this window open, or find the snippets later under Admin, then Install Google Tag Manager. Your container ID looks like GTM-XXXXXXX.
Step 2: Add GTM to WordPress
There are three common methods. Pick one only.
Method A: GTM4WP plugin
GTM4WP, listed in the plugin directory as “Google Tag Manager for WordPress”, is a popular free plugin built specifically for this.
- Install and activate the plugin.
- Go to Settings, then Google Tag Manager.
- Paste your container ID.
- Choose the container code placement. “Codeless injection” works with most themes. If your theme supports the
wp_body_openhook, the body snippet can be placed correctly after the opening body tag. - Save.
GTM4WP can also push useful WordPress information into the data layer, such as post type, categories, author and logged-in status, and it has WooCommerce options for ecommerce tracking. That data makes it easier to build triggers and variables later.
Method B: Site Kit by Google
Site Kit is Google’s official WordPress plugin. It connects Search Console, Analytics, PageSpeed Insights and Tag Manager to your dashboard. During setup you can connect Tag Manager, and Site Kit will place the container on your site.
This suits owners who want Google’s own tool and a dashboard view of their data. Be careful not to let Site Kit place Analytics code directly as well as through GTM. More on that below.
Method C: Child theme code
Developers often prefer adding the snippets in code. Use a child theme so a theme update does not wipe your changes. In the child theme’s functions.php:
add_action( 'wp_head', function () { ?>
<!-- Google Tag Manager head snippet here -->
<?php }, 1 );
add_action( 'wp_body_open', function () { ?>
<!-- Google Tag Manager noscript snippet here -->
<?php } );
The wp_body_open hook was added in WordPress 5.2. Many current themes call it, but older themes may not. If yours does not, the body snippet will not appear, and you would need to add it to the theme’s header.php in the child theme. The head snippet does most of the work, so a missing noscript part mainly affects visitors with JavaScript disabled.
A general “insert headers and footers” plugin can also add the head snippet, but GTM4WP handles both parts more neatly.
Step 3: Add Universal Analytics through GTM
- In GTM, go to Variables, then create a new user-defined variable of type Google Analytics Settings. Enter your tracking ID, which looks like
UA-XXXXXXX-X. - Go to Tags, then New. Choose Google Analytics: Universal Analytics.
- Set Track Type to Page View and select your settings variable.
- Set the trigger to All Pages.
- Save.
If you have not set up Analytics yet, our guide to Google Analytics setup covers the property and view settings first.
Step 4: Remove old tracking code
This step is often missed. If your site already sends pageviews through a theme option, an analytics plugin or code in header.php, and you add the same property in GTM, every pageview is counted twice. Signs include a bounce rate close to zero and doubled pageviews.
Check for:
- Analytics fields in your theme settings
- Analytics plugins that insert their own tracking code
- Site Kit inserting Analytics directly
- Hard-coded snippets in theme files
Keep one source of truth: GTM.
Step 5: Test with Preview mode
- In GTM, click Preview.
- Open your website in the same browser. A debug panel appears at the bottom of the page.
- Check that your Universal Analytics tag shows under “Tags Fired” on page load.
- Open the Real-Time report in Google Analytics and confirm your visit appears.
- Click around a few pages and check the tag fires each time.
The Tag Assistant extension for Chrome can also show which Google tags are on a page and flag duplicates.
If you use a caching plugin, clear the cache after installing GTM so visitors receive the new code.
Step 6: Publish
When everything checks out, click Submit in GTM, add a version name and description such as “Universal Analytics pageview”, and publish. The container is now live.
What to track next
With the basics in place, GTM makes common tracking much easier:
- Form submissions: track contact and quote forms as events and goals. See our guide to form tracking.
- Clicks on phone and email links: use click triggers on
tel:andmailto:links. - File downloads: trigger on links ending in
.pdfand other file types. - Outbound links: see which external sites visitors leave for.
- Scroll depth: see how far visitors read long pages.
- Ads and social pixels: add Google Ads conversion tags and the Facebook pixel with triggers on the right pages.
Our guide to event tracking explains how to name events so reports stay readable.
Privacy and consent
If you serve visitors in regions with consent rules, decide which tags can fire before consent. Many consent plugins work with GTM by setting a variable or pushing an event to the data layer, which you can use in triggers. Our cookie consent guide covers the options.
FAQ
Will Google Tag Manager slow down my WordPress site?
The container script itself is small and loads asynchronously. The tags you add inside it are what affect speed, so keep only the ones you use.
Do I still need an analytics plugin?
Not for tracking. Some people keep a plugin for a dashboard view, but it must not insert its own tracking code.
Can I use GTM with any theme?
Yes. Plugin methods work with almost any theme. The body snippet placement depends on whether the theme supports wp_body_open.
Tracking you can trust
A clean GTM setup gives you accurate data and makes future tracking changes quick. If you want analytics that show what is actually working on your site, see how we help businesses know what’s working.