Skip to content
🚀 Find us on Product Hunt

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.

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.

Google Tag Manager Tags list for container GTM-5NF3RF2P showing GA4 Configuration and event tags
The site's own GTM container (GTM-5NF3RF2P), Tags list — including the GA4 Configuration Google tag and GA4 event tags.
GA4 Configuration Google tag detail in GTM showing the Measurement ID variable and All Pages trigger
The GA4 Configuration tag in the site's container: a Google tag using the {{GA4 - Measurement ID}} variable, firing on All Pages before the GA4 event tags.

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:

  1. Choose WordPress as the platform and pick the tools you actually use — GA4 at minimum, then Google Ads and Meta if you run ads.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

TagManagerBuilder step 1 with WordPress selected as the website platform
Step 1 of the TagManagerBuilder flow: WordPress selected as the website platform.
TagManagerBuilder step 2 with Google Analytics 4, Google Ads and Meta Pixel selected
Step 2: Google Analytics 4, Google Ads and Meta Pixel selected as the tracking platforms.
TagManagerBuilder step 3 showing the eight selected WordPress tracking events
Step 3: the eight WordPress events selected — Form Submission, Page View, Scroll Depth, Outbound Link Click, File Download, Site Search, Video Play and Video Complete.
TagManagerBuilder step 4 with sample tracking IDs entered for GA4, Google Ads and Meta Pixel
Step 4: the tracking IDs entered — sample IDs shown (GA4, Google Ads conversion ID and label, Meta Pixel ID).
TagManagerBuilder step 6 review screen listing WordPress, three tracking platforms and eight events
Step 6, Review: WordPress, the three tracking platforms and the eight events listed before generating.
TagManagerBuilder success screen showing 11 tags, 8 triggers and 1 variable generated
The generated container: 11 tags, 8 triggers and 1 variable, ready to download as JSON.

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.

MethodBest forProsCons
GTM4WP pluginMost sites, especially with forms or a storePastes both snippets correctly and pushes post, author, category, search and form data into the dataLayer automaticallyOne more plugin to maintain; the settings screen is large at first
Site Kit by GoogleBeginners who also want Search Console and GA4 data in the dashboardOfficial Google plugin, guided setup, connects several Google products at onceNo custom dataLayer variables; easy to end up double-tagging GA4 if Site Kit also connects Analytics directly
Manual, child theme or code-snippets pluginLean sites, developers, strict performance budgetsZero plugin overhead, full control over placementNo 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.

EventFires whenWhat it tells youKey data
page_viewAny page loadsTraffic, landing pages, content performancepage location, page title
scrollA visitor scrolls past a threshold (for example 90%)Whether long posts actually get readscroll threshold, page path
form_submissionA form is sent (contact, quote, newsletter, comment)Leads that never reach a thank-you page you can count separatelyform id, form name
outbound_clickA link to another domain is clickedWhich external links earn clicks — affiliate links, partner sites, "book now" buttonsclick URL, link text
file_downloadA PDF, media file or document is downloadedWhether lead magnets and resources get usedfile name, file extension
searchA visitor searches the siteWhat people cannot find by browsing — your content gapssearch term
video_play / video_completeAn embedded video plays or finishesWhether video content holds attentionvideo 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.

Google Tag Manager Triggers list for container GTM-5NF3RF2P
Triggers in the site's container: custom event triggers for Add to Wishlist, Begin Checkout, Calendly Booking, Form Submission and View Item, plus All Pages.
Google Tag Manager Variables list for container GTM-5NF3RF2P showing ecommerce dataLayer variables
Variables in the site's container: dataLayer variables for ecommerce, ecommerce.currency, ecommerce.items, ecommerce.transaction_id and ecommerce.value, plus the GA4 Measurement ID constant.

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

ProblemWhat you seeUsual causeFix
Container loads twicePage views and events doubled in GA4GTM inserted by both the theme and a plugin, or by Site Kit and GTM4WP at onceLoad GTM once; use one install method and disable the others
GA4 counted twiceEvery page view doubledGA4 added directly (gtag.js, Site Kit Analytics, theme option) as well as through GTMPick one path: GTM owns GA4, or the direct install does — never both
Form submissions missingForms sent but no form_submission in DebugViewForm plugin integration not enabled, or the form redirects before the push firesEnable the form integration in GTM4WP for your exact form plugin; test in Preview and watch for the event
No dataLayer content dataTriggers by category or author never fireBasic data not enabled in the pluginEnable post data in GTM4WP and confirm the values appear in Preview's dataLayer tab
Scroll events never fireNo scroll events in GA4Scroll trigger thresholds not set, or the trigger is pausedAdd a Scroll Depth trigger with the thresholds you want and check it is not paused
Events stop after consent changesGA4 goes quiet for EEA trafficConsent Mode v2 defaults to denied and no consent banner update reaches GTMWire the consent banner to GTM's consent API and test with a fresh EEA session
Noscript block missingContainer works but the fallback is absentTheme predates wp_body_open and never calls itAdd 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 importWrong file, or merging into a workspace with conflicting namesRe-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

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Share with