Skip to content
PHP security alert Two critical PHP flaws (php2shell) were fixed on 21 October. Is your site's PHP patched? Check in a minute →
OvKit
Menu
Download free

Set Up WooCommerce Conversion Tracking for GA4 and Meta Pixel

Track WooCommerce purchases in Google Analytics 4 and Meta Pixel without a bloated plugin. Here's the clean GTM-based approach.

You’re running Google Ads and Meta (Facebook) campaigns for a WooCommerce store. Traffic is flowing. But you have no idea which clicks turn into purchases because conversion tracking isn’t set up.

Without conversion tracking, you’re flying blind. Your ad platforms can’t optimize for purchases, you can’t calculate ROAS, and you’re guessing which campaigns work. Setting this up correctly is the difference between profitable ads and wasted budget.

What is conversion tracking?

Conversion tracking fires a signal to your analytics and advertising platforms when a customer completes a purchase. For WooCommerce, that means sending purchase data (order value, products, transaction ID) to Google Analytics 4 and/or Meta Pixel when the “thank you” page loads.

The clean way to do this: use Google Tag Manager (GTM) to manage all tracking in one place, with a WooCommerce data layer that pushes purchase information to GTM on the order confirmation page.

Why GTM instead of plugins?

One container, all platforms. GTM holds your GA4 tag, Meta Pixel, Google Ads conversion tag, LinkedIn Insight, TikTok Pixel — all managed from one interface.

No plugin bloat. Tracking plugins (MonsterInsights, PixelYourSite, etc.) add their own JavaScript, admin pages, and database queries. GTM is one script that manages everything.

Accuracy. Plugins that inject tracking via PHP sometimes fire on cached pages or miss AJAX-based checkouts. GTM fires client-side, ensuring the data layer event matches the actual user experience.

The setup

Step 1: Add the WooCommerce data layer

Add this to your theme’s functions.php or a site-specific plugin:

// Push WooCommerce purchase data to GTM data layer
add_action( 'woocommerce_thankyou', function( $order_id ) {
    if ( ! $order_id ) return;
    $order = wc_get_order( $order_id );
    if ( ! $order ) return;

    $items = [];
    foreach ( $order->get_items() as $item ) {
        $product = $item->get_product();
        $items[] = [
            'item_name' => $item->get_name(),
            'item_id'   => $product ? $product->get_sku() : '',
            'price'     => round( (float) $item->get_total() / max( $item->get_quantity(), 1 ), 2 ),
            'quantity'  => $item->get_quantity(),
        ];
    }

    $data = [
        'event'          => 'purchase',
        'transaction_id' => (string) $order->get_order_number(),
        'value'          => (float) $order->get_total(),
        'currency'       => $order->get_currency(),
        'items'          => $items,
    ];

    echo '<script>window.dataLayer = window.dataLayer || [];
    dataLayer.push(' . wp_json_encode( $data ) . ');</script>';
});

Step 2: Create GA4 purchase tag in GTM

In GTM, create a new tag: Tag Type → GA4 Event. Event Name: purchase. Trigger: Custom Event → purchase. Map the data layer variables (transaction_id, value, currency, items) to GA4 parameters.

Step 3: Create Meta Pixel purchase event in GTM

In GTM, create a Custom HTML tag with the Meta Pixel purchase event, triggered by the same purchase custom event. Pass the order value and currency.

Step 4: Test with GTM Preview mode

Use GTM’s Preview mode and place a test order. Verify the purchase event fires on the thank-you page with correct data.

The one-click solution

Ovanap Admin Toolkit includes WooCommerce conversion tracking under Admin Toolkit → Tracking (shown when WooCommerce is active). It sends view_item, add_to_cart and purchase events, with the purchase on the order-received page. In Auto mode it pushes them to the data layer when GTM (set up in the toolkit) or Google Site Kit is present, so you map them to GA4, Meta Pixel or Google Ads tags in GTM; otherwise it calls GA4 (gtag) and Meta Pixel (fbq) directly, using the IDs from Tracking & analytics codes. No code needed.

What happens after you fix this?

  • GA4 records purchase events with transaction ID, value, and products
  • Meta Pixel fires Purchase events for campaign optimization
  • Google Ads can optimize for purchases instead of clicks
  • ROAS calculation becomes possible — you know which campaigns make money

FAQ

Will this work with WooCommerce’s AJAX checkout?

The code above hooks into woocommerce_thankyou, which fires on the thank-you page — after checkout, regardless of whether AJAX was used. It works with standard, AJAX, and block-based checkouts.

Do I need both GA4 and Meta Pixel?

Only if you advertise on both platforms. If you only run Google Ads, GA4 tracking is sufficient. If you only run Meta ads, the Pixel is what you need. Most e-commerce stores benefit from both.

This seems complex — can’t I just use a plugin?

You can. Plugins like PixelYourSite and MonsterInsights handle this with a GUI. The trade-off is additional JavaScript, admin overhead, and potential conflicts with caching. The GTM approach is cleaner and more flexible, but requires GTM knowledge.


Related reads: