WooCommerce Tracking Options
WooCommerce, as an open-source WordPress plugin, gives you more flexibility for ecommerce tracking than hosted platforms like Shopify — but this flexibility also means more implementation complexity. There are three main approaches.
Approach 1: Plugin-Based Tracking
Several WordPress plugins handle GA4 ecommerce tracking automatically:
Analytify (GA4 plugin): Installs GA4 tracking tag and sends basic GA4 ecommerce events (purchase, begin_checkout) automatically. The free version covers basic events; the premium version adds full funnel events (add_to_cart, view_item, etc.) and GTM integration.
GTM4WP: A GTM container plugin that also includes WooCommerce data layer support. It pushes ecommerce events to the data layer in the correct GA4 format, allowing you to configure the actual GA4 tags in GTM. This is the recommended approach for teams using GTM, as it provides the data layer without requiring custom development.
Datalayer for WooCommerce (by Elevar or Stape): Specialist data layer plugins that push comprehensive ecommerce data to the GTM data layer. More complete than GTM4WP in terms of parameters, and more customisable.
Approach 2: GTM with Custom Data Layer (Developer Required)
For the most control and customisation, have a developer implement the GA4 ecommerce data layer directly in WooCommerce PHP/JavaScript. This approach:
- Uses WooCommerce hooks (woocommerce_single_product_summary, woocommerce_add_to_cart, woocommerce_thankyou) to trigger data layer pushes at the right moments
- Populates the data layer with full GA4 ecommerce data including all items, categories, variants, and custom fields
- GTM reads the data layer and sends events to GA4
Example: WooCommerce purchase event hook
// In functions.php or a custom plugin
add_action('woocommerce_thankyou', 'push_ga4_purchase_event', 10, 1);
function push_ga4_purchase_event($order_id) {
if (!$order_id) return;
$order = wc_get_order($order_id);
if ($order->get_meta('_ga4_tracked')) return; // Prevent duplicates
$items = [];
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$items[] = [
'item_id' => $product->get_sku() ?: $product->get_id(),
'item_name' => $item->get_name(),
'price' => $item->get_total() / $item->get_quantity(),
'quantity' => $item->get_quantity()
];
}
// Output to page
echo '';
$order->update_meta_data('_ga4_tracked', true); // Mark as tracked
$order->save();
}
Approach 3: Headless WooCommerce with Custom Events
For headless WooCommerce (React/Next.js frontend with WooCommerce API backend): implement GA4 events directly in the frontend JavaScript on each relevant user action, using WooCommerce's REST API responses to populate item data.
Key WooCommerce-Specific Issues
- Caching and purchase deduplication: if WooCommerce pages are cached (LiteSpeed Cache, W3 Total Cache), the thank-you page may be served from cache and trigger the purchase event multiple times. Always check for the ga4_tracked meta field and avoid firing purchase events on cached page serves.
- Multiple currencies: WooCommerce multi-currency plugins may need special handling to ensure the correct currency code is passed to GA4.
- Variable products: ensure the item_variant parameter correctly reflects the selected variation (colour, size) for variable products.
Summary
For most WooCommerce stores, GTM4WP plugin or Datalayer for WooCommerce + GTM is the recommended approach — it provides the full ecommerce data layer without heavy custom development. For complex stores with custom product types or business-specific parameters, a custom data layer implementation using WooCommerce hooks gives the most control.
See our Enhanced Ecommerce Tracking service for WooCommerce implementation.
Need WooCommerce ecommerce tracking set up? Contact Adslytics.
Need expert tracking setup?
Our Google Tag Manager experts have delivered 500+ tracking setups with a 98% success rate.
Get a Free Consultation →