GTM Tracking Setup for WooCommerce
Configure GA4, Google Ads, Meta, TikTok and more for WooCommerce and generate a ready-to-import Google Tag Manager container.
- Google Analytics 4 for WooCommerce
GA4 configuration and ecommerce event tracking via a native Google tag.
- Google Ads for WooCommerce
Conversion tracking tags using Google Ads' native GTM tag type.
- Meta Pixel for WooCommerce
Facebook/Instagram Pixel base code and standard events, generated as Custom HTML.
- TikTok Pixel for WooCommerce
TikTok Pixel base code and standard events, generated as Custom HTML.
- Pinterest Tag for WooCommerce
Pinterest base tag and standard events, generated as Custom HTML.
- LinkedIn Insight Tag for WooCommerce
LinkedIn Insight Tag base code, generated as Custom HTML.
- Microsoft Advertising (UET) for WooCommerce
Universal Event Tracking base tag and standard events, generated as Custom HTML.
- X (Twitter) Pixel for WooCommerce
X Pixel base code and standard events, generated as Custom HTML.
Quick answer
To track a WooCommerce store with Google Tag Manager, you need three things working together: a dataLayer that describes what shoppers do (view a product, add to cart, check out, buy), a GTM container with a Google tag plus one GA4 event tag per ecommerce event, and a test order that proves a purchase event with transaction_id, value, currency and an items array lands in GA4. The recipes on this page generate the container part for you — tags, triggers and variables for GA4, Google Ads, Meta and the other tools — so you import it instead of building every tag by hand. The dataLayer itself usually comes from the free GTM4WP plugin, which outputs WooCommerce events in GA4 format.
How WooCommerce 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 product was viewed, what was added to the cart, what the order was worth.
On a WooCommerce store that chain has four links, and a break in any one of them means missing or wrong data:
- The store pushes events to the dataLayer. The usual route is the GTM4WP plugin (Google Tag Manager for WordPress), which outputs GA4-style ecommerce events for product, cart, checkout and order pages, including AJAX add to cart. The alternative is custom code on WooCommerce hooks in a child theme or a small plugin.
- GTM listens with triggers. A custom event trigger fires when the dataLayer event name matches — view_item, add_to_cart, begin_checkout, purchase and the rest.
- Tags send the data on. A Google tag loads the GA4 library on every page; a GA4 event tag fires per ecommerce event and reads the product and transaction data from dataLayer variables.
- The destination receives it. GA4 DebugView and its Monetisation reports, Google Ads conversions, Meta Events Manager — each one confirms the same events from its own side.
If you only see page views in GA4 and no revenue, the first link is usually the broken one: the dataLayer has no ecommerce events at all. Check with GTM Preview mode on a product page — if no view_item event appears in the left-hand event list, nothing downstream can work.
Build your WooCommerce container with TagManagerBuilder
Building the container by hand means creating a Google tag, a GA4 event tag for every ecommerce event, dataLayer variables for transaction_id, value, currency and items, custom event triggers 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 WooCommerce 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 the full ecommerce set: view_item, view_item_list, add_to_cart, begin_checkout and purchase. Add page_view and form_submission if you want content and lead tracking in the same container.
- 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.
- Publish, then test with a real order — never trust an import until a test purchase appears in GA4 DebugView with the right value and transaction ID.
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.
Which WooCommerce events matter — and why
Not every event deserves the same attention. These are the ones that drive reporting and ad optimisation, in the order a shopper meets them:
| Event | Fires when | What it tells you | Key data |
|---|---|---|---|
| page_view | Any page loads | Traffic, landing pages, content performance | page location, page title |
| view_item_list | A category or shop archive loads | Which lists get seen (category, search results, related products) | item list id, items |
| view_item | A product page is viewed | Product interest before any cart action | item_id, item_name, price, category |
| add_to_cart | A product is added, including AJAX add to cart | Real buying intent; the top of your funnel | items, quantity, value |
| begin_checkout | Checkout starts | Where checkout drop-off begins | items, value, coupon |
| purchase | Order received (thank-you) page, once | Revenue, conversion rate, return on ad spend | transaction_id, value, tax, shipping, currency, items |
| form_submission | A form is sent (contact, newsletter, quote) | Leads that never reach checkout | form id, form name |
Two events do most of the commercial work. add_to_cart shows intent you can retarget — someone who added a product but never checked out is the highest-value audience most stores have. purchase is the only event that proves money changed hands, and it feeds GA4 revenue reports, Google Ads conversion value and Meta purchase optimisation. If you track nothing else, track those two properly, with value and currency on every hit.
view_item_list is the one most stores skip and later regret. Without it you cannot tell whether a category page is failing because nobody sees the products or because nobody clicks them — the difference decides whether you fix merchandising or pricing.
The dataLayer: what GTM actually reads
Every event above arrives as a dataLayer.push(). This is what a purchase push looks like on the order-received page — the shape the generated container expects:
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'WC-4821',
value: 89.97,
tax: 14.99,
shipping: 4.95,
currency: 'GBP',
items: [
{
item_id: 'SKU-114',
item_name: 'Leather Weekend Bag',
price: 84.99,
quantity: 1
}
]
}
});
An add_to_cart push follows the same pattern, with the event name changed and the cart contents in items. The critical rules are the same for every event: the event name must match the trigger exactly (purchase, not Purchase or order_complete), value must be a number rather than a formatted string, and items must be an array of objects with item_id and price.
GTM4WP produces these pushes for you once you enable its WooCommerce integration and the GA4 events you need. If you build the dataLayer yourself with WooCommerce hooks, the purchase push needs one extra safeguard: store a flag in the order meta after the first push, and only push again if the flag is absent. That is what stops the thank-you page sending a second purchase every time a customer refreshes it.
Importing the container into GTM
- In GTM, open Admin → Import Container and choose the JSON file you downloaded.
- Pick the workspace the store uses. If you already have tags in that workspace, choose Merge and Rename conflicting tags, triggers, and variables — overwriting deletes whatever is already there.
- Open Tags and check the Google tag carries your GA4 Measurement ID, then open Variables and confirm the dataLayer variables point at ecommerce.transaction_id, ecommerce.value, ecommerce.currency and ecommerce.items.
- Click Preview, load the store, and walk through view → add to cart → checkout → test purchase. Each event should appear in Preview and fire its GA4 event tag.
- Only then click Submit → Publish. Publishing an untested container is how duplicate or missing purchase events reach production.
One container per store, and load it exactly once. If GTM is already inserted manually in the theme or through another plugin, set GTM4WP's container code to Off so the plugin feeds the dataLayer without inserting a second copy of the container. A doubled container doubles every event and page view in GA4.
Here is what an imported container looks like inside Google Tag Manager, from our own live container:
Sending the same events to Google Ads and Meta
The same purchase 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 purchase trigger, with value, transaction ID and currency. Add the Conversion Linker tag on All Pages so clicks are attributed. If you collect customer email and phone at checkout, enable Enhanced Conversions so Google can match conversions that cookies miss. The transaction ID is what lets Google deduplicate — the same ID arriving twice counts once.
Meta: add the Meta Pixel base code through GTM and a Purchase event on the same purchase trigger, passing value and currency. 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 purchases.
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 WooCommerce 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 | Load GTM once; set GTM4WP container code to Off if the snippet is already in the theme |
| Purchase counted twice | Two purchase events per order in GA4 | Thank-you page reloaded, or browser + server both sending | Order-meta flag on the dataLayer push; matching eventID for browser/server pairs |
| Purchase missing entirely | Checkout works but no purchase in DebugView | Payment gateway redirects the customer away and back | Add gateway domains (PayPal, Stripe) to GA4's unwanted referrals list; confirm the thank-you page fires the push |
| add_to_cart never fires | Products added but no event | Theme uses AJAX add to cart and the plugin setting is off | Enable AJAX add-to-cart tracking in GTM4WP, or push the event from the added_to_cart JavaScript event |
| No value on events | Events arrive with no revenue | Variable points at the wrong dataLayer path | Variable must read ecommerce.value (a number), and the tag must pass it as the event value |
| Wrong currency | Revenue in the wrong currency in GA4 | currency missing or hardcoded | Read ecommerce.currency from the dataLayer on every event tag |
| 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 |
| 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 import-error case is worth a note of its own: if GTM rejects the file, do not edit the JSON by hand. Re-download it from the builder and import into a new workspace — a hand-edited container file is the fastest way to create triggers that point at variables that no longer exist.
How to test before you publish
- GTM Preview mode: connect to the store, walk the full journey, and confirm each event appears and fires its tags. 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 purchase shows transaction_id, value, currency and the items array. A purchase without an items array will not appear in product revenue reports.
- A real test order: place an order with a test payment method and refund or cancel it afterwards. A test order is the only check that covers the payment gateway redirect — the step where most purchase tracking actually breaks.
- Meta Test Events / Google Ads diagnostics: confirm the same purchase arrived on the ad platforms, not just in GA4. One platform receiving the event while another misses it points at a tag configuration problem, not a dataLayer problem.
- 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. The two do different jobs; using both is the standard setup, and you should never run two dataLayer plugins at once.
Why is my WooCommerce purchase event not firing in GA4?
Work backwards: does the thank-you page push a purchase event to the dataLayer (check in GTM Preview)? Does a custom event trigger match that exact name? Does the GA4 event tag read ecommerce variables that exist? And did the payment gateway return the customer to the thank-you page at all — a redirect that drops the customer elsewhere means the push never runs.
Why are my WooCommerce purchases counted twice?
Usually the thank-you page fires purchase again on refresh, or the container loads twice, or browser and server both send the event without a shared deduplication ID. Fix the dataLayer flag first — it is the most common cause — then check for a doubled container, then check server-side deduplication.
Can I track Google Ads and Meta purchases from the same container?
Yes. Add one conversion tag per platform on the same purchase trigger, all reading the same value, currency and transaction_id. That keeps every platform's numbers tied to the same order, which is what makes return-on-ad-spend figures comparable.
Which events should a new store set up first?
page_view, view_item, add_to_cart, begin_checkout and purchase, in that order. Those five give you the full funnel: who looked, who intended to buy, who started checkout and who paid. Add view_item_list and form_submission once the funnel is verified.