By continuing to use our website, you consent to the use of cookies. Please refer our cookie policy for more details.

    How to Customize Shopify eCommerce Tracking Using Google Analytics

    Shopify is one of the most popular eCommerce platforms with a whopping $50 billion worth of merchandise sold through its 600,000 stores last year. Marketers are spending billions of dollars to acquire this traffic!

    Google Analytics will provide you with insights into your Shopify store’s traffic. But to effectively target this traffic, you need to customize eCommerce tracking using Google Analytics.

    Shopify eCommerce Tracking

    But why do you need Google Analytics for your Shopify store?

    By using Google Analytics eCommerce tracking, you can correlate sales data with website usage data such as –

    • Sessions
    • Bounce rate
    • Traffic source/medium
    • Landing pages

    Such type of correlation analysis is required to understand the performance of your website landing pages and marketing campaigns.

    eCommerce tracking would trigger once a user “purchases” any products. The user’s purchase information is sent to the web server, which carries out the transaction.

    If successful, the server redirects the user to a “Thank You” page. You can use the analytics.js or gtag.js library to send the eCommerce data from the “Thank You” page to Google Analytics.

    There are multiple types of eCommerce data you can send using Google analytics JS. Such as:

    • Impression data
    • Product data
    • Promotion data/medium
    • Action data

    How eCommerce tracking works in Google Analytics

    eCommerce Data

    The eCommerce data is made up of transaction data and item data.

    1. Transaction Data

    Transaction Data provide details about users’ transactions like:

    • Transaction ID (or order ID)
    • Store or affiliation name
    • Total revenue generated from the transaction (can also include shipping cost and taxes)
    • Total tax associated with the transaction
    • Total shipping cost associated with the transaction

    2. Item Data

    Item data provides details about a purchased product like:

    • Transaction ID (same as in the transaction data)
    • Product SKU (or product code)
    • Product Name
    • Product Category
    • Product Price
    • Product Quantity

    Anatomy of eCommerce Tracking Code

    The eCommerce tracking code is made up of the following four commands:

    1. ecommerce
    2. ecommerce:addTransaction
    3. ecommerce:addItem
    4. Ecommerce:send

    1. ‘ecommerce’ command

    This command is used to load the ecommerce plugin.

    Syntax: ga(‘require’, ‘ecommerce’);

    The plugin contains the functionality for e-commerce tracking in GA. You have to load this plugin, otherwise your ecommerce tracking won’t work.

    Note: The ‘ecommerce’ command should always be called after you have created the tracker object and before following commands are executed: ecommerce:addTransaction, ecommerce:addItem and ecommerce:send.

    2. ‘ecommerce:addTransaction’ command

    This command is used to create visitor’s transaction and to store all the information about the transaction.

    3. ‘ecommerce:addItem’ command

    This command is used to add a product to the visitor’s transaction and to store all the information about the purchased product.

    4. ‘ecommerce:send’ command

    This command is used to send all of the eCommerce data to Google Analytics server.

    Syntax: ga(‘ecommerce:send’);

    Note: without using the command, you can’t send eCommerce data to Google Analytics.

    Most Useable eCommerce Platforms

    All eCommerce platforms have their advantages and disadvantages. It is important for businesses to evaluate the various platforms based on their own specific needs and use cases.

    Here are the most popular eCommerce platforms:

    • BigCommerce
    • Magento
    • Volusion
    • Demandware
    • WooCommerce
    • 3dcart
    • Shopify
    • Kibo
    • Prestashop
    • Squarespace
    • Big Cartel

    Let us take a look at customizing Shopify eCommerce tracking and where custom js needs to be added.

    How to generate actual revenue figures for Shopify eCommerce platform excluding shipping and taxes from the original reports?

    In Shopify we do not have the authority to edit the eCommerce tracking, to overcome that part we need to write a custom JS and add it on the website to track the purchase of the products.

    Shopify has a default option for eCommerce tracking, so you just need to add the “Google Analytics Tracking Id” and check the “Use Enhanced eCommerce” option.

    Shopify eCommerce Tracking

    Default eCommerce tracking would start automatically in Google Analytics so make sure you have enabled the “Enhanced Ecommerce Reporting” in Google Analytics view settings.

    What is the current challenge in the existing eCommerce tracking reports inside Google Analytics?

    Exclude “Tax” and “Delivery” charges from the “Revenue” metric. Currently “Tax” and “Delivery” charges are included in the “Revenue” metric. Also “Tax” and “Delivery” charges should appear separately in Google Analytics.

    Shopify eCommerce Tracking

    What is the solution?

    The following steps are required to exclude the “Tax” and “Delivery” charges from the Revenue metric in Google Analytics.

    Step 1:-

    Make a list of data fields which you want to track in Google Analytics, such as:

    Add Transaction List:

    • id
    • affiliation
    • revenue
    • coupon
    • tax
    • shipping
    • currency

    Add Item List:

    • id
    • sku
    • name
    • list_name
    • brand
    • category
    • variant
    • list_position
    • quantity
    • currencyCode
    • price

    Step 2:-

    Corresponding to the fields above, collect variables from the Shopify store and map accordingly.

    Add Transaction

    • “id”: {{order_name|handleize}}, // Transaction ID. Required.
    • “affiliation”: ‘store name’, // Affiliation or store name.
    • “revenue”: {{order.subtotal_price|money_without_currency}},
    • “coupon”: “{{ line_item.quantity }}”,
    • “tax”: “{{ order.tax_price|money_without_currency }}”,
    • “shipping”: “{{ order.shipping_price|money_without_currency }}”,
    • “currency”: “{{shop.currency }}”

    Add Item

    • “id”: {{order_name|handleize}}, // Transaction ID. Required.
    • “sku”: “{{ line_item.sku }}”,
    • “name”: “{{line_item.title}}”,
    • “list_name”: “Search Results”,
    • “brand”: “Brand Name”,
    • “category”: “{{ line_item.product.collections[0].title }}”,
    • “variant”: “{{line_item.variant}}”,
    • “list_position”: “1”,
    • “quantity”: “{{ line_item.quantity }}”,
    • “currencyCode”: “{{shop.currency }}”,
    • “price”: “{{ line_item.line_price | money_without_currency}}”

    Step 3:-

    In Revenue field “revenue”: {{order.subtotal_price|money_without_currency}}” we added the subtotal of the transaction (Excluded Tax and Shipment/Delivery charges).

    You can make changes in the below script according to your requirements. And then add this script into the Shopify Settings > Checkout > Additional Scripts section. Make sure to uncheck the “Enhanced Ecommerce Reporting” option in Shopify.

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    
    ga('create', 'UA-xxxxxxx-x', 'auto');
    ga('require', 'ecommerce');
    
    ga('ecommerce:addTransaction', {
    "id": {{order_name|handleize}}, // Transaction ID. Required.
    "affiliation": 'store name', // Affiliation or store name.
    "revenue": {{order.subtotal_price|money_without_currency}},
    "coupon": "{{ line_item.quantity }}",
    "tax": "{{ order.tax_price|money_without_currency }}",
    "shipping": "{{ order.shipping_price|money_without_currency }}",
    "currency": "{{shop.currency }}"
    });
    {% for line_item in line_items %}
    {% assign list_position = forloop.index + 1 %}
    {% assign product_category = '' %}
    ga('ecommerce:addItem', {
    "id": {{order_name|handleize}}, // Transaction ID. Required.
    "sku": "{{ line_item.sku }}",
    "name": "{{line_item.title}}",
    "list_name": "Search Results",
    "brand": "Brand Name",
    "category": "{{ line_item.product.collections[0].title }}",
    "variant": "{{line_item.variant}}",
    "list_position": "1",
    "quantity": "{{ line_item.quantity }}",
    "currencyCode": "{{shop.currency }}",
    "price": "{{ line_item.line_price | money_without_currency}}"
    });
    {% endfor %}
    ga('ecommerce:send');

    You can see in the screenshot below that “Tax” and “Delivery” charges are excluded from the “Revenue” metric.

    Shopify eCommerce Tracking

    Customize Shopify eCommerce tracking using Google Analytics

    Grazitti has expertise in Google Analytics and Google Tag Manager custom integrations for all the eCommerce tracking platforms. To know more, send us an email at [email protected].