Installing Google Analytics 4 on a WooCommerce store
On WooCommerce, GA4 can be installed three ways: a dedicated plugin, a snippet added to functions.php, or a Google Tag Manager container. What turns a clean install into a half-reliable one is the purchase event firing more than once on the thank-you page.
The situations I handle
- GA4 shows sessions but no ecommerce data in the purchase reports
- You’re torn between a dedicated GA4 plugin and a manual addition in functions.php
- The number of orders in GA4 is consistently higher than the real number of WooCommerce orders
- A native analytics feature from your hosting is being confused with Google Analytics 4
- You want to use Google Tag Manager but aren’t sure how to feed the WooCommerce data layer
How I install GA4 on WooCommerce
-
Choosing the installation method
Depending on the site, I install a dedicated GA4 plugin that handles the WooCommerce data layer automatically, a gtag.js snippet in functions.php for a simple need, or a Google Tag Manager container when several marketing tools need to coexist.
-
Checking for an existing tag
I check the page source and the list of active plugins to make sure no other plugin is already sending data to Google Analytics alongside the planned install.
-
Building the data layer across the purchase funnel
I check that view_item, add_to_cart and begin_checkout fire with the expected parameters (items, value, currency) on the product page, the cart and the checkout page.
-
Firing the purchase event once
On WooCommerce’s thank-you page, I make sure purchase fires only once per order, with the correct transaction_id and value, even if the customer refreshes the page.
-
Testing before going live
I place a test order and check every event in Google Tag Manager’s preview mode or GA4’s DebugView before calling the install finished.
Plugin, functions.php or GTM: how I decide
A dedicated GA4 plugin usually handles the WooCommerce data layer without touching any code, which suits most shops. A gtag.js snippet in functions.php is still useful for a one-off need, but every change means editing the theme again.
Be careful not to confuse GA4 with a native analytics feature that some hosts or WordPress plugins offer under a similar name: these are separate tools that don’t replace GA4 and don’t feed the same reports.
Underneath it all, WooCommerce needs to fire GA4’s recommended ecommerce events, view_item, add_to_cart, begin_checkout, purchase, with the names and parameters Google sets so the standard reports work. The purchase event in particular should fire once per order on the thank-you page, not on every page load.
Related pages
-
Google Tag Manager on WooCommerce
The method I recommend for centralising GA4 and other marketing tools.
-
Ecommerce events that matter
The GA4 events worth tracking first on a purchase funnel.
-
Duplicate stats: the causes
Other common sources of duplication between plugins and manual tags.
-
WooCommerce, my main platform
The other WooCommerce topics I deal with day to day.
Describe your need in one minute
A few targeted questions so I can reply with an estimate rather than another questionnaire.