GTM Tracking Setup for WordPress
Configure GA4, Google Ads, Meta, TikTok and more for WordPress and generate a ready-to-import Google Tag Manager container.
- Google Analytics 4 for WordPress
GA4 configuration and ecommerce event tracking via a native Google tag.
- Google Ads for WordPress
Conversion tracking tags using Google Ads' native GTM tag type.
- Meta Pixel for WordPress
Facebook/Instagram Pixel base code and standard events, generated as Custom HTML.
- TikTok Pixel for WordPress
TikTok Pixel base code and standard events, generated as Custom HTML.
- Pinterest Tag for WordPress
Pinterest base tag and standard events, generated as Custom HTML.
- LinkedIn Insight Tag for WordPress
LinkedIn Insight Tag base code, generated as Custom HTML.
- Microsoft Advertising (UET) for WordPress
Universal Event Tracking base tag and standard events, generated as Custom HTML.
- X (Twitter) Pixel for WordPress
X Pixel base code and standard events, generated as Custom HTML.
Quick answer
To track a WordPress site with Google Tag Manager, create a Web container at tagmanager.google.com, place its two snippets on every page — the script as high in <head> as possible and the <noscript> block immediately after the opening <body> tag — then add a Google tag with your GA4 Measurement ID on the Initialization trigger. The recipes on this page generate the container part for you: the Google tag plus GA4 event tags, triggers and dataLayer variables for the events a WordPress site actually needs (page views, form submissions, scrolls, outbound clicks), using the real IDs you type in. What the container cannot do on its own is describe your content — that comes from the dataLayer, which on WordPress usually comes from the GTM4WP plugin or a small amount of custom code.
How WordPress tracking works with Google Tag Manager
Google Tag Manager does not track anything on its own. It is a delivery system: it loads tags (GA4, Google Ads, Meta Pixel and the rest) and decides when each one fires, based on triggers that listen to the dataLayer. The dataLayer is a small JavaScript object on the page that describes what just happened — which post was viewed, which form was sent, what a visitor searched for. On a WordPress site that chain has four links, and a break in any one of them means missing or wrong data: (1) WordPress pushes information to the dataLayer — usually the GTM4WP plugin, which can push post type, author, category, tags, search terms and logged-in status, plus form and WooCommerce events; the alternative is custom code on WordPress hooks in a child theme or a small plugin. (2) GTM listens with triggers — a trigger fires when the dataLayer event name matches: page_view, form_submission, scroll, outbound_click and the rest, optionally filtered by a variable, for example only on posts in a certain category. (3) Tags send the data on — a Google tag loads the GA4 library on every page; a GA4 event tag fires per event and reads the values from dataLayer variables. (4) The destination receives it — GA4 DebugView and its reports, Google Ads conversions, Meta Events Manager, each confirming the same events from its own side. If you only see page views in GA4 and no form submissions, the first link is usually the broken one: the dataLayer has no form events at all. Check with GTM Preview mode on a page with a form — if no form_submission event appears in the left-hand event list after you submit it, nothing downstream can work.
Build your WordPress container with TagManagerBuilder
Building the container by hand means creating a Google tag, a GA4 event tag for every event, dataLayer variables for the values each event needs, and a trigger for each event name, plus the equivalent tags for Google Ads and Meta. It is repetitive work and one mistyped variable name silently breaks an event. The builder on this site generates that container for you:
- Choose WordPress as the platform and pick the tools you actually use — GA4 at minimum, then Google Ads and Meta if you run ads.
- Pick the events you want to track — start with page_view and form_submission, the two that matter on almost every WordPress site, then add scroll, outbound click and file-download events if you publish content you want measured.
- Enter your real IDs — your GA4 Measurement ID, Google Ads conversion ID and label, Meta Pixel ID. The builder uses the IDs you type, not placeholders, so the container it generates is ready to import.
- Download the container JSON and import it into GTM (Admin → Import Container). Choose Merge and rename on conflict if the container already has tags; choose Overwrite only on a fresh, empty container.
- Install the container on WordPress, then test — never trust an import until a form submission and a page view appear in GA4 DebugView with the right values.
The recipe links below the builder take you to the same setup broken down per tool and event, so you can check exactly what each generated tag does before you import it.
Installing the container on WordPress: three ways
The builder gives you the container. Getting its two snippets onto every WordPress page is a separate step, and there are three honest ways to do it. Pick one — never two at once, or the container loads twice and every event doubles.
| Method | Best for | Pros | Cons |
|---|---|---|---|
| GTM4WP plugin | Most sites, especially with forms or a store | Pastes both snippets correctly and pushes post, author, category, search and form data into the dataLayer automatically | One more plugin to maintain; the settings screen is large at first |
| Site Kit by Google | Beginners who also want Search Console and GA4 data in the dashboard | Official Google plugin, guided setup, connects several Google products at once | No custom dataLayer variables; easy to end up double-tagging GA4 if Site Kit also connects Analytics directly |
| Manual, child theme or code-snippets plugin | Lean sites, developers, strict performance budgets | Zero plugin overhead, full control over placement | No automatic dataLayer; a theme update wipes edits made to a parent theme — always use a child theme |
GTM4WP (recommended for most sites)
Install "Google Tag Manager for WordPress" from Plugins → Add New, open its settings, paste the container ID and save. In the Integration and Basic data tabs, enable only what you will actually use: post data, search data, and your form plugin. Choose the container code placement your theme supports — Codeless injection works on most modern themes.
Site Kit
Install Site Kit by Google, connect your Google account and enable the Tag Manager module. Decide up front whether Site Kit or GTM owns GA4: if Site Kit connects Analytics directly and your GTM container also contains a GA4 tag, every page view is counted twice. Pick one path.
Manual
Never paste code into a parent theme file — a theme update will wipe it. In a child theme's functions.php, hook the head snippet to wp_head and the noscript block to wp_body_open (WordPress 5.2 and later; most modern themes call it immediately after the opening <body> tag). Define the container ID once as a constant and let both functions read it, so the two snippets can never disagree. A code-snippets plugin works the same way, set to run on the front end only.
Which WordPress events matter — and why
A content site is not a store: there is no purchase at the end of the funnel. The events that matter are the ones that prove someone read, engaged, or got in touch.
| Event | Fires when | What it tells you | Key data |
|---|---|---|---|
| page_view | Any page loads | Traffic, landing pages, content performance | page location, page title |
| scroll | A visitor scrolls past a threshold (for example 90%) | Whether long posts actually get read | scroll threshold, page path |
| form_submission | A form is sent (contact, quote, newsletter, comment) | Leads that never reach a thank-you page you can count separately | form id, form name |
| outbound_click | A link to another domain is clicked | Which external links earn clicks — affiliate links, partner sites, "book now" buttons | click URL, link text |
| file_download | A PDF, media file or document is downloaded | Whether lead magnets and resources get used | file name, file extension |
| search | A visitor searches the site | What people cannot find by browsing — your content gaps | search term |
| video_play / video_complete | An embedded video plays or finishes | Whether video content holds attention | video title, percent played |
Two events do most of the commercial work on a WordPress site. form_submission is the lead: a contact or quote form sent is the closest thing a service site has to a conversion, so it should feed GA4 and your ad platforms as a conversion, not sit as an uncounted event. scroll at 90% is the honest read metric — a page view only proves the page loaded, a deep scroll proves somebody read it, and it is the signal that separates genuinely useful posts from pages that rank but do not satisfy. The search event is the one most site owners skip and later regret. The search terms visitors type into your own site search are a list of content they wanted and could not find by browsing — it is the cheapest content research you will ever get.
The dataLayer: what GTM actually reads
Every event above arrives as a dataLayer.push(). This is what a form_submission push looks like — the shape the generated container expects:
dataLayer.push({ event: 'form_submission', form_id: 'contact-form-1', form_name: 'Contact form', page_path: '/contact/' });
GTM4WP produces pushes like this for you once you enable its form integration for your form plugin (WPForms, Contact Form 7, Gravity Forms and others are supported). If you build the dataLayer yourself, the same rules apply as for every event: the event name must match the trigger exactly (form_submission, not FormSubmit or form-sent), and values must be plain strings or numbers, not formatted text. WordPress adds one thing other platforms do not: content context on every page view. With GTM4WP's basic data enabled, the dataLayer also carries the post type, author, categories and tags for the page being viewed. That lets you build triggers such as "fire this tag only on posts in the Pricing category, by a logged-out visitor" without writing a line of code — useful when a lead magnet or a conversion tag should only run on part of the site.
Sending the same events to Google Ads and Meta
The same form_submission event should feed every ad platform you use — that is the point of routing it through GTM rather than installing each platform's code separately. Google Ads: add a Google Ads Conversion Tracking tag on the form_submission trigger, with the conversion ID and label from your Google Ads account. Add the Conversion Linker tag on All Pages so clicks are attributed. Mark the form submission as a conversion in Google Ads so it feeds bidding. If you collect email or phone in the form, Enhanced Conversions can match conversions that cookies miss. Meta: add the Meta Pixel base code through GTM and a Lead event on the same form_submission trigger. Check it in Meta Events Manager with Test Events. If you later add server-side tracking, send the same eventID from browser and server so Meta deduplicates the pair instead of counting two leads. TikTok, Pinterest, LinkedIn and the others follow the same pattern in the generated container: one event tag per platform on the same trigger, reading the same dataLayer variables. Adding a platform later means adding its tag, not rebuilding the dataLayer.
Common WordPress GTM errors — and how to fix them
| Problem | What you see | Usual cause | Fix |
|---|---|---|---|
| Container loads twice | Page views and events doubled in GA4 | GTM inserted by both the theme and a plugin, or by Site Kit and GTM4WP at once | Load GTM once; use one install method and disable the others |
| GA4 counted twice | Every page view doubled | GA4 added directly (gtag.js, Site Kit Analytics, theme option) as well as through GTM | Pick one path: GTM owns GA4, or the direct install does — never both |
| Form submissions missing | Forms sent but no form_submission in DebugView | Form plugin integration not enabled, or the form redirects before the push fires | Enable the form integration in GTM4WP for your exact form plugin; test in Preview and watch for the event |
| No dataLayer content data | Triggers by category or author never fire | Basic data not enabled in the plugin | Enable post data in GTM4WP and confirm the values appear in Preview's dataLayer tab |
| Scroll events never fire | No scroll events in GA4 | Scroll trigger thresholds not set, or the trigger is paused | Add a Scroll Depth trigger with the thresholds you want and check it is not paused |
| Events stop after consent changes | GA4 goes quiet for EEA traffic | Consent Mode v2 defaults to denied and no consent banner update reaches GTM | Wire the consent banner to GTM's consent API and test with a fresh EEA session |
| Noscript block missing | Container works but the fallback is absent | Theme predates wp_body_open and never calls it | Add the wp_body_open() call to the theme (or child theme) right after the opening <body> tag |
| Import fails | "Invalid container" or missing tags on import | Wrong file, or merging into a workspace with conflicting names | Re-download from the builder, import into a fresh workspace first, then merge with rename on conflict |
The double-tagging case is worth a note of its own: before adding anything, search the theme and plugins for gtag.js, fbq(, and any older GTM- snippet. Remove or disable them first. A WordPress site that has collected tracking snippets over the years almost always has at least one leftover, and it is the single most common cause of doubled numbers.
How to test before you publish
- GTM Preview mode: connect to the site, load a post, scroll to the bottom, and submit a test form. Each event should appear in Preview and fire its GA4 event tag. Anything that fires on the wrong trigger is visible here before a single real visitor is affected.
- GA4 DebugView: with Preview running, open DebugView and confirm the test form submission shows form_id and form_name. A form event without an identifier cannot be tied back to the form that sent it.
- A real test submission: send a form yourself and confirm it arrives in GA4 as a conversion and, if you run ads, in Google Ads and Meta. A test submission is the only check that covers the form plugin's redirect or confirmation step — the point where most form tracking actually breaks.
- Tag Assistant or a tag debugger: confirm googletagmanager.com/gtm.js loads exactly once per page.
Frequently asked questions
Do I still need the GTM4WP plugin if I use the builder?
Yes, for the dataLayer. The builder generates the GTM container — tags, triggers and variables. GTM4WP (or equivalent custom code) generates the dataLayer events the container listens to, and installs the container snippets. The two do different jobs; using both is the standard setup, and you should never run two dataLayer plugins at once.
Why are my WordPress form submissions not showing in GA4?
Work backwards: does submitting the form push a form_submission event to the dataLayer (check in GTM Preview)? Is the form plugin's integration enabled in GTM4WP? Does a trigger match that exact event name? And does the form redirect to a thank-you page before the push runs — a redirect that fires first means the push never happens.
Why is my GA4 data doubled on WordPress?
Usually GA4 is installed twice: once directly (through Site Kit, a theme option, or a pasted gtag.js snippet) and once through GTM. Remove the direct install and keep the GTM route, then confirm in Tag Assistant that gtag.js loads once.
Can I install GTM on WordPress without a plugin?
Yes. Add the two snippets through a child theme's functions.php — head snippet on wp_head, noscript block on wp_body_open — with the container ID defined once. It keeps the site lean, but you get no automatic dataLayer, so form and content events need custom code.
Which events should a new WordPress site set up first?
page_view, form_submission and scroll, in that order. Those three give you traffic, leads and genuine reads. Add outbound clicks, file downloads and site search once the first three are verified.