How to Setup Enhanced Ecommerce Tracking to WooCommerce

Sumit Kumar
8 Min Read

When you are running an online shopping website & getting sales from it, it is very important to track the sales you get from your online store.

Google Analytics is so powerful that help measure data from various dimensions, Enhanced eCommerce Tracking is one of them.

What is Enhanced eCommerce Tracking?

Enhanced eCommerce Tracking is a Google Analytics feature that helps online store owners to keep on track of their sales, transections, returns & users shopping behaviour.

This is a very useful feature of Google Analytics & users are taking benefits from this from a while.

Setting up Enhanced eCommerce Tracking on any online shopping website may require some development knowledge based on the CMS you use.

In this blog, we will learn about how we can set up Enhanced Ecommerce Tracking to WooCommerce using Google Tag Manager.

Step 1: Enable Enhanced eCommerce Tracking setting in Google Analytics

Before we start this, make sure you have enabled the enhanced eCommerce tracking to your Google Analytics so that you can able to see the eCommerce data in conversions tab.

To enable this, Go to Google Analytics > Admin > Ecommerce Settings

enhanced ecommerce google analytics

Once you get there, switch ON Enable Ecommerce & Enable Enhanced Ecommerce Reporting & click SAVE.

google analytics enhanced ecommerce
Google Analytics Enhanced Ecommerce Setting

Step 2: Add a JavaScript to Thank You page

The process of the enhanced eCommerce tracking is that a JavaScript is inserted in the datalayer on the thankyou page so that it will pass the information like product info, price, quantity etc. to the Google Analytics using Google Tag Manager.

Here is the script which needs to be added to the functions.php in your WordPress.

Here are the steps:

  • Login to your WordPress
  • 2. Go to Appearance > Theme Editor > functions.php

Copy the below mentioned JavaScript & page it to functions.php file:

function push_to_datalayer($order_id) {
    $order = wc_get_order( $order_id );
    <script type='text/javascript'>
        window.dataLayer = window.dataLayer || [];
                     'event' : 'transaction',
                     'ecommerce' : {
                         'purchase' : {
                             'actionField' : {
                                 'id': '<?php echo $order->get_order_number(); ?>',
                                 'affiliation': '<?php echo get_option("blogname"); ?>',
                                 'revenue' : '<?php echo number_format($order->get_subtotal(), 2, ".", ""); ?>', 
                                 'tax': '<?php echo number_format($order->get_total_tax(), 2 ,".", ""); ?>',
                                 'shipping': '<?php echo number_format($order->calculate_shipping(), 2 , ".", ""); ?>',
                                 <?php if($order->get_used_coupons()) : ?>
                                  'coupon' : '<?php echo implode("-", $order->get_used_coupons()); ?>'
                                 <?php endif; ?>
                                 'products': [
                                         foreach ( $order->get_items() as $key => $item ) :
                                            $product = $order->get_product_from_item($item);
                                            $variant_name = ($item['variation_id']) ? wc_get_product($item['variation_id']) : '';
                                        'name' : '<?php echo $item['name']; ?>',
                                        'id' : '<?php echo $item['product_id']; ?>',
                                        'price' : '<?php echo number_format($order->get_line_subtotal($item), 2, ".", ""); ?>',
                                        'brand' : '',
                                        'category' : '<?php echo strip_tags($product->get_categories(', ', '', '')); ?>',
                                        'variant' : '<?php echo ($variant_name) ? implode("-" , $variant_name->get_variation_attributes()) : ''; ?>',
                                        'quantity' : <?php echo $item['qty']; ?>,
                                        'coupon' : ''
                                <?php endforeach; ?>

add_action('woocommerce_thankyou' , 'push_to_datalayer');

Above JavaScript will help pass the order information & this will be fired on ThankYou page of the website.

Step 3: Create a trigger

Now once we create the tag, we need to create a trigger which will listen to the event which will fire at the time of successful order placement on Thank You page.

Since we have already added the event name as ‘transaction‘,  so we will create the trigger by the same name.

You can change the event name as per your requirement but as I’ve already created that JavaScript with the event name, so I advise you do not change any setting in there.

To create the trigger, follow these steps:

  1. Go to Google Tag Manager
  2. Go to Trigger > New Trigger & name it as per your requirement (I’ve named mine as Analytics – Transaction Complete Trigger)
  3. Choose Trigger Type > Custom Event
  4. Event Name > transaction (as we have named the event as the transaction in JavaScript which we already placed on functions.php file)
  5. This trigger fires on > All Custom Events
  6. Save this trigger
enhanced ecommerce tag manager
Enhanced eCommerce Trigger

Step 4: Create a Tag in Google Tag Manager

Now, once we enable the eCommerce setting in Google Tag manager, we need to create the tag which helps to interact between Google analytics & the trigger which we will create in the next step.

To create this tag, follow the steps below:

  1. Login to Google Tag Manager
  2. Go to New Tag > Name it as you want (I’ve named mine Analytics – eCommerce Event)
  3. Tag Type > Google Analytics: Universal Analytics
  4. Track Type > Event
  5. In Event Tracking Parameters, Choose Category (Choose category name)
  6. Action > (Choose category name)
  7. Non-Interaction Hit > True
  8. Google Analytics Settings > (Choose from the Google Analytics Variable)

TIP: Never override the Google Analytics tag. Always use create & use Google Analytics Variable as this will add some require features to the tag.

google tag manager enhanced ecommerce
Google Tag Manager Enhanced Ecommerce Tag

Now since we have created the tag, this needs to be fired on the trigger which we created in the last step.

Once done, you can publish all the changes & move that to tests. Once you start getting more sales, you will see the data in Google Analytics > Conversions > Ecommerce > Overview.

enhanced ecommerce woocommerce universal analytics
Enhanced Ecommerce Tracking Overview

If you navigate to some other tabs such as shopping behaviour, checkout behaviour, product performance, you will see some more data there.

By setting up enhanced eCommerce tracking, you can easily see which is your best product for sale, what is customer & product behaviour & performance etc.

Once you have this data, you can optimize your online store further.

If you think we have missed any important setup or you know any other way to set up enhanced eCommerce tracking to the WooCommerece, then let us know in comments.

If you need any assistance on your SEO campaign, you can hire us by getting a 14 Days Free SEO Trial.

Need any help or assistance in Google Analytics?

We provide SEO & Google Analytics Consulting services in the following countries:

United States | United Kingdom | Australia | Singapore | India | New Zealand | Dubai

Related Articles

How To Setup Facebook Pixel & Events (With Google Tag Manager)

How to Setup Google Ads Conversion Tracking in BigCommerce (With Order Amount & Order ID)

How to Setup Ninja Forms Event Tracking with Google Tag Manager

The Use of Artificial Intelligence (AI) in SEO – All You Need To Know

How to Setup Contact Form 7 Event Tracking with Google Tag Manager

Best Website Traffic Monitoring Tools

How To Create Custom Reports In Google Analytics

Share This Article

Leave a Reply

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