How to Set Up Conversion Tracking for WooCommerce: Google Ads, GA4, and Reddit Pixel

Codeable.io

How to Set Up Conversion Tracking for WooCommerce: Google Ads, GA4, and Reddit Pixel

Tracking conversions is essential for any successful eCommerce business. Without proper conversion tracking, you’re flying blind—unable to measure ROI, optimize ad campaigns, or understand customer behavior. In this comprehensive guide, I’ll show you how to implement conversion tracking for WooCommerce using Google Ads, Google Analytics 4, and Reddit Pixel.

Why WooCommerce Conversion Tracking Matters

WooCommerce conversion tracking allows you to monitor every purchase, add-to-cart action, and customer interaction on your online store. This data helps you understand which marketing channels drive sales, which products perform best, and how to allocate your advertising budget effectively.

With proper conversion tracking in place, you can:

  • Measure the ROI of your advertising campaigns
  • Optimize your Google Ads and Reddit Ads for better performance
  • Understand customer purchasing behavior
  • Make data-driven decisions about your marketing strategy

Prerequisites for WooCommerce Conversion Tracking

Before implementing conversion tracking, ensure you have:

  • A WordPress site with WooCommerce installed
  • Active Google Ads and Google Analytics 4 accounts
  • A Reddit Ads account with pixel access
  • Basic understanding of WordPress functions.php or a custom plugin

Implementing Google Ads and GA4 Global Tags

The first step in WooCommerce conversion tracking is adding the global site tags. These tags load on every page and initialize tracking for both Google Ads and Google Analytics 4.

Add the following code to your theme’s functions.php file or create a custom plugin. Replace the placeholder IDs with your actual tracking IDs from Google Ads (AW-XXXXXXXXX) and Google Analytics 4 (G-XXXXXXXXXX).

The global tag function uses the wp_head action hook to inject the necessary JavaScript code into your site’s header. This ensures the tracking script loads before any user interactions occur, capturing all relevant data.


/**
 * Add Google Ads and Analytics 4 Global Tracking
 * Add this to your theme's functions.php or custom plugin
 */
add_action('wp_head', 'add_google_ads_global_tag');
function add_google_ads_global_tag() {
    ?>
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=AW-XXXXXXXXX"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      
      // Google Ads Configuration
      gtag('config', 'AW-XXXXXXXXX');
      
      // Google Analytics 4 Configuration
      gtag('config', 'G-XXXXXXXXXX');
    </script>
    <?php
}

Setting Up Reddit Pixel Base Code

Reddit Pixel enables conversion tracking for your Reddit advertising campaigns. The base code initializes the pixel and tracks page visits automatically.

Replace the pixel ID (a2_XXXXXXXXXXXXX) with your actual Reddit Pixel ID found in your Reddit Ads dashboard. The code includes important configuration options like opt-out functionality and decimal currency support for accurate value tracking.


/**
 * Initialize Reddit Pixel Tracking
 * Tracks page visits automatically
 */
add_action('wp_head', 'add_reddit_pixel_base');
function add_reddit_pixel_base() {
    ?>
    <!-- Reddit Pixel -->
    <script>
    !function(w,d){
        if(!w.rdt){
            var p=w.rdt=function(){
                p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments)
            };
            p.callQueue=[];
            var t=d.createElement("script");
            t.src="https://www.redditstatic.com/ads/pixel.js",t.async=!0;
            var s=d.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(t,s)
        }
    }(window,document);
    
    rdt('init','a2_XXXXXXXXXXXXX', {
        "optOut":false,
        "useDecimalCurrencyValues":true
    });
    rdt('track', 'PageVisit');
    </script>
    <!-- End Reddit Pixel -->
    <?php
}

Tracking WooCommerce Purchase Conversions

The most critical aspect of WooCommerce conversion tracking is capturing completed purchases. This implementation tracks conversions across Google Ads, Google Analytics 4, and Reddit Pixel simultaneously.

The code hooks into the WooCommerce order confirmation page using is_wc_endpoint_url('order-received'). It retrieves order details including total value, currency, and transaction ID. To prevent duplicate tracking, the system checks for a custom meta field before firing tracking events.

For Google Ads, the conversion event includes the conversion label specific to your purchase conversion action. Google Analytics 4 receives enhanced eCommerce data with individual product items, quantities, and prices. Reddit Pixel tracks the purchase with transaction details for attribution.

The update_post_meta function marks each order as tracked, ensuring conversions aren’t reported multiple times if a customer refreshes the thank-you page.


/**
 * Track WooCommerce Purchase Conversions
 * Fires on order confirmation page for Google Ads, GA4, and Reddit
 */
add_action('wp_footer', 'google_ads_conversion_tracking');
function google_ads_conversion_tracking() {
    // Check if we're on the order confirmation page
    if ( is_wc_endpoint_url( 'order-received' ) ) {
        global $wp;
        $order_id = absint( $wp->query_vars['order-received'] );
        
        if ( $order_id ) {
            // Prevent duplicate tracking
            $tracked = get_post_meta( $order_id, '_google_ads_tracked', true );
            
            if ( $tracked ) {
                return;
            }
            
            $order = wc_get_order( $order_id );
            
            if ( $order ) {
                $order_total = $order->get_total();
                $currency = $order->get_currency();
                $transaction_id = $order->get_order_number();
                
                // Get order items for enhanced tracking
                $items = array();
                foreach ( $order->get_items() as $item ) {
                    $product = $item->get_product();
                    $items[] = array(
                        'id' => $product->get_sku() ? $product->get_sku() : $product->get_id(),
                        'name' => $item->get_name(),
                        'quantity' => $item->get_quantity(),
                        'price' => $item->get_total()
                    );
                }
                ?>
                <script>
                  // Google Ads Conversion Event
                  gtag('event', 'conversion', {
                      'send_to': 'AW-XXXXXXXXX/XXXXXXXXXXXXX',
                      'value': <?php echo $order_total; ?>,
                      'currency': '<?php echo esc_js($currency); ?>',
                      'transaction_id': '<?php echo esc_js($transaction_id); ?>'
                  });
                  // Google Analytics 4 Purchase Event
                  gtag('event', 'purchase', {
                      'transaction_id': '<?php echo esc_js($transaction_id); ?>',
                      'value': <?php echo $order_total; ?>,
                      'currency': '<?php echo esc_js($currency); ?>',
                      'items': <?php echo json_encode($items); ?>
                  });
                  // Reddit Conversion Event
                  rdt('track', 'Purchase', {
                      'currency': '<?php echo esc_js($currency); ?>',
                      'value': <?php echo $order_total; ?>,
                      'transactionId': '<?php echo esc_js($transaction_id); ?>'
                  });
                </script>
                <?php
                
                // Mark order as tracked
                update_post_meta( $order_id, '_google_ads_tracked', true );
            }
        }
    }
}

Enhanced Tracking with Product Data

Enhanced conversion tracking includes detailed product information for each order. The code loops through order items, extracting SKUs (or product IDs if SKUs aren’t available), product names, quantities, and prices.

This granular data enables advanced reporting in Google Analytics 4, showing which specific products drive revenue and how customers combine products in their purchases.


/**
 * Track Add to Cart Events in Google Analytics 4
 * Helps identify products with high interest
 */
add_action('woocommerce_add_to_cart', 'track_add_to_cart', 10, 6);
function track_add_to_cart($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
    $product = wc_get_product($product_id);
    ?>
    <script>
      gtag('event', 'add_to_cart', {
          'currency': '<?php echo get_woocommerce_currency(); ?>',
          'value': <?php echo $product->get_price() * $quantity; ?>,
          'items': [{
              'id': '<?php echo $product->get_sku() ? $product->get_sku() : $product_id; ?>',
              'name': '<?php echo esc_js($product->get_name()); ?>',
              'quantity': <?php echo $quantity; ?>,
              'price': <?php echo $product->get_price(); ?>
          }]
      });
    </script>
    <?php
}

Implementing Add-to-Cart Tracking

Beyond purchase conversions, tracking add-to-cart events provides valuable insights into customer intent and product interest. This implementation fires a Google Analytics 4 event whenever a customer adds a product to their cart.

The woocommerce_add_to_cart action hook captures the product details and sends them to GA4. This data helps identify products with high add-to-cart rates but low purchase completion, indicating potential checkout issues.

Preventing Duplicate Conversion Tracking

Duplicate tracking inflates conversion numbers and skews your data. The implementation prevents this by storing custom post meta fields (_google_ads_tracked and _reddit_pixel_tracked) for each order.

Before firing any tracking events, the code checks whether these meta fields exist. If they do, the function returns early without executing tracking scripts. This approach works even if customers refresh the order confirmation page multiple times.

Testing Your WooCommerce Conversion Tracking

After implementing the code, thorough testing ensures everything works correctly:

  1. Place a test order on your WooCommerce store
  2. Check the browser console for tracking scripts firing
  3. Verify conversions appear in Google Ads (within 24 hours)
  4. Confirm purchase events in Google Analytics 4 real-time reports
  5. Check Reddit Ads dashboard for conversion data

Use browser developer tools to inspect the page source and confirm tracking scripts load properly with correct values.

Common WooCommerce Conversion Tracking Issues

If conversions aren’t tracking properly, check these common issues:

  • Incorrect tracking IDs or pixel codes
  • JavaScript conflicts with other plugins
  • Caching plugins preventing scripts from loading
  • Ad blockers interfering with tracking pixels
  • Missing WooCommerce hooks in customized themes

Always clear cache after making changes and test in an incognito browser window to avoid browser extension interference.

Conclusion

Implementing comprehensive WooCommerce conversion tracking gives you the data foundation needed for successful eCommerce growth. By tracking purchases across Google Ads, Google Analytics 4, and Reddit Pixel, you gain complete visibility into your marketing performance and customer behavior. Follow this guide to set up robust conversion tracking and start making data-driven decisions for your online store.

Leave a Reply

Your email address will not be published. Required fields are marked *