Google Analytics E-Commerce Tracking – Complete Guide


This post is the third in the series of frequently asked questions about various issues in Google Analytics.  The first post in the series was How Google Analytics Uses Cookies which talks about Google Analytics cookies in great details. The second post in the series was How Cross Domain tracking works in Google Analytics which talks about cross domain tracking in great detail.

I will start from the very basic and then go into advanced topic of how exactly e-commerce tracking code interacts with Google Analytics Server and how you can resolve various e-commerce tracking issues.  Once you have gone through this post (from start to finish) there will be (hopefully) nothing left for you to understand about e-commerce tracking in Google Analytics and you would end up becoming an E-Commerce Tracking code champion :)

 

What insight I can get from e-commerce overview report?

 ecommerce overview report

 

The e-commerce overview report provides overview of various e-commerce activities on your website like which products sell the most, your e-commerce conversion rate, total revenue generated, total products sold etc.

 

What is e-commerce conversion rate and how it is calculated?

E-commerce conversion rate is the percentage of visits which results in e-commerce transactions.

E-commerce conversion rate = (Total E-Commerce Transactions/Total visits on a website) * 100

For e.g. the e-commerce conversion rate above was calculated as:

= (3132 transactions / 262,780 visits) * 100 = 1.19%

 

What is a transaction?

Transaction (or e-commerce transaction) is a purchase order. For example 3132 transactions means 3132 purchase orders were placed on the website.  The e-commerce overview report shows the total number of transactions carried out on the website (which is 3132) in a specified time period. Each transaction is identified through a unique ID known as transaction ID.

Note: A transaction can include several products or product items as a person can buy several products or several units of a product in one transaction.

 

 

What is Total Revenue & how it is calculated?

The revenue that you see in the ‘e-commerce overview report’ is the total revenue.

Total Revenue = Total Product Revenue + Total Tax + Total Shipping

For example, the total revenue in the ‘e-commerce overview report’ was calculated as:

Total Revenue = $454,907.96 + $0.00 + $67359.46 = $522267.42

 

Note:  Your total revenue figures depend upon how your client has set up ecommerce tracking. If your client decided to exclude tax and shipping amount within the total revenue, then your total revenue and product revenue amount should be the same. If the tax information or shipping information is not supplied while setting up e-commerce tracking then Google Analytics can’t report such information in its reports and they won’t be included in the computation of total revenue.

 

What is average value and how it is calculated?

Average value or average order value (AOV) is the average value of an e-commerce transaction.

Average Value = Total Revenue/Total Transactions

For example, the AOV above was calculated as:

AOV = $522267.42 / 3132 = $166.75

 

What is unique purchase?

It is the number of product items sold in one transaction. For example a visitor can purchase 5 copies of Adobe Photoshop in one transaction.  The ‘unique purchases’ metrics that you normally see in Google analytics reports are usually either total unique purchases of a set of products or total unique purchases of a set of product items.  By default you can’t see total unique purchase of a product item.

 

 

 If you look at the total unique purchases of the first product (which is 214) you may assume that 214 product items were sold in one transaction. But this is not the case. In order to truly find out how many product items were sold in one transaction you need to add ‘transaction’ as a ‘secondary dimension in the table above and then filter out the 1st product (using advanced filter on the reporting interface):

 

 

 From the table above we can see that 8 product items were sold in one transaction with the ID ‘40625’. 6 product items were sold in the transaction with the ID ‘24751’. (Note: Transaction ids were deliberately changed to maintain confidentiality)

 

What is quantity?

It is the total number of items sold for a product or set of products.

 

 

What is Average Quantity and how it is calculated?

It is the average number of product items sold per transaction.

 

Average Quantity = Quantity / Unique Purchases

For example:

The average quantity of 1st product is calculated as:

Average QTY = 125/124 = 1.01

The average quantity of 2nd product is calculated as:

Average QTY = 115/109 = 1.06

 

What is product SKU?

Stock keeping unit or SKU is an alphanumeric number or string which is used to identify a product item. Following are some of the examples of SKU

  1. HCS3245H
  2. DB45TH
  3. R567

 

What is the difference between product and product item?

Product item is the unit of a product. For example if Nokia N90 is a product then one of the pieces of this model (which is identified through a unique ID known as SKU) is a product item.

 

What is average price?

It is the price of each product item. When reported in aggregate it is the average price of a set of product items.

 

 

What is product revenue and how it is calculated?

 It is the total revenue generated from a set of products or set of product items.

Product Revenue = No. of product items sold (i.e. quantity) * Average Price

For example the product revenue of the first product in the chart above is calculated as follows:

Product Revenue = 125 * $75.47 = $9433.75

 

 

Where I can track e-commerce metrics in Google Analytics?

You can track e-commerce metrics in various ‘E-Commerce’ reports and through the e-commerce tabs found in various reports like ‘Adwords Campaigns’ reports.

 

How I can determine the per visit value across all traffic sources?

You can determine the per visit value through ‘e-commerce’ tab in ‘All Traffic’ sources report.

 

What e-commerce data is made up of?

It is made up of transaction data and item data.

 

What is transaction Data?

Transaction Data provide details about visitor’s transactions like:

  • Transaction ID (or order ID)
  • Store or affiliation name
  • Total revenue generated from the transaction
  • Tax
  • Shipping Charges
  • Transaction City
  • Transaction State/Region
  • Transaction Country

 

What is item Data?

Item data provides details about the purchased product item like:

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

 

 

Can you give examples of popular shopping cart softwares?

OsCommerce, Zen-Cart, Magento all are popular shopping cart softwares

 

What e-commerce tracking code is made up of?

It is made up of three methods:

  1. _addTrans()
  2. _addItem()
  3. _TrackTrans()

 

What is _addTrans() method?

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

Syntax: _addTrans(orderID, storeName, total, tax, shipping, city, state, country)

Example:

 

 

Do I need to supply values for all parameters of _addTrans()?

Yes. Even if some of the parameters have empty value.

 

How I can leave the value of a parameter empty?

Just don’t add anything between the quotation marks. For example:

 

 

What is _addItem() method?

This method is used to add purchased product item to visitor’s transaction and to store all the information about each unique product item (product SKU).

Syntax: _addItem(orderID, Product-SKU, Product-Name, Product-Category, Product-Price, Quantity)

Example:

 

 

Do I need to supply values for all parameters of _addItem()?

Yes. Even if some of the parameters have empty value.

 

Which parameter of _addItem() method associates a product item with a transaction?

‘orderID’

 

Which parameters I can’t leave empty in _addItem() method?

There are 4 parameters which you can’t leave empty:

  1. OrderID
  2. Product SKU
  3. Product Price
  4. Product Quantity

 

 

What is the advantage of supplying value to ‘product name’ parameter in _additem() method?

By supplying the value you can associate revenue with a product name. If you don’t supply this value then you won’t be able to see revenue generated by the sale of a particular product item in Google Analytics Product Performance report.

 

What is _trackTrans() method?

This method is used to send all the e-commerce data to Google Analytics server. The data is sent via invisible _utm.gif file. This file is requested once for each visitor’s transaction and once for each unique item (product SKU) in the transaction. So if there are 4 unique items in a visitor’s transaction (i.e. the person has bought 4 unique product items in one transaction) then there will be 5 requests for _utm.gif file.

Syntax:  _gaq.push([‘_trackTrans’]);

Note: The _trackTrans() method should always be called after: _trackPageView(), _addTrans() and _addItem() methods.

 

 

Example of an E-Commerce Tracking Code

_gaq.push([‘_addTrans’,

‘1234’,

‘skinny jeans’,

’28.8’,

‘1.89’,

’10.00’,

‘Los Angeles’,

‘California’,

‘USA’

]);

 

_gaq.push([‘_addItem’,

‘1234’,

‘SKJ49’,

’OKE Jeans’,

‘Men Jeans’,

’76.75’,

‘1’,

]);

_gaq.push([‘_trackTrans’]);

 

 

When E-Commerce Data in E-Commerce Tracking can cause problem?

It can cause problem if you supply currency identifier (like $, £, € etc) or comma (to separate numbers) in the numeric fields of _addTrans() or _addItem() methods. For example:

 

 

What is the difference between Google Analytics Tracking code (GATC) and E-Commerce Tracking code?

GATC sends page view data to Google Analytics server (via invisible _utm.gif file). Whereas e-commerce tracking code sends the ecommerce data to Google Analytics server (via invisible _utm.gif file)

 

Where do I add the e-commerce tracking code on a web page?

You add the e-commerce tracking code immediately after the following line in the Google Analytics tracking code:

_gaq.push([‘_trackPageView’]);

 

How I can use e-commerce reporting in Google Analytics?

Step-1: Configure your shopping cart software so that it can send e-commerce data to Google Analytics server.

Step-2: Add Google analytics tracking code, E-commerce tracking code and some server side script like (PHP, ASP etc) to your shopping cart receipt page (generally the ‘thank you’ page).

Step-3: Enable e-commerce reporting in your Google Analytics Profile. More details here.

 

How E-commerce Tracking Works?

 

 

 

Step-1: A visitor completes a transaction.

Step-2: Your sever processes the transaction (verify credit card details, sends confirmation mail etc)

Step-3: Your sever creates a receipt page

Step-4: Your server inserts e-commerce data into Google Analytics’ javascript of the receipt page

Step-5: Your server sends receipt page to visitor’s browser

Step-6:  As soon as the page is loaded into the visitor’s browser, GATC calls the following methods one after the other:

1. GATC calls the _trackPageView() method to send page view data to Google Analytics server.

2. GATC calls the _addTrans() method to retrieve all the information about visitor’s transaction.

3. GATC calls the _addItem() method to retrieve all the information about each unique product item in the visitor’s transaction.

4. GATC finally calls the _trackTrans() method to send all the e-commerce data (transaction data+ item data) to the Google Analytics Server via invisible _utm.gif file.

 

 

How my web server inserts e-commerce data into Google Analytics Javascript?

To insert e-commerce data you need to add a server side script (like PHP) to your shopping cart receipt page. This script should automatically retrieve ecommerce data from your shopping cart software and populate the fields of _addTrans() and _addItem() methods with it. For example, here is what your actual ecommerce tracking code may look like if you use PHP script:

<?php

If($_SERVER[SCRIPT_NAME]==/thank-you.php”) {

?>

_gaq.push([‘_addTrans’,

‘<? = $orders[‘order_id’]?>’,

‘<? = $orders[‘store_name’]?>’,

‘<? = $orders[‘total’]?>’,

‘<? = $orders[‘tax’]?>’,

‘<? = $orders[‘shipping’]?>’,

‘<? = $orders[‘city’]?>’,

‘<? = $orders[‘region’]?>’,

‘<? = $orders[‘country’]?>’,

]);

<?php

for ($i=0;$n=sizeof($products_array);$i<$n;$i++) {

?>

_gaq.push([‘_addItem’,

‘<? = $orders[‘order_id’] ?>,

‘<? =$products_array[$i][‘sku’] ?>’,

‘<? =$products_array[$i][‘name’] ?>’,

‘<? =$products_array[$i][‘category’] ?>’,

‘<? =$products_array[$i][‘price’] ?>’,

‘<? =$products_array[$i][‘quantity’] ?>’,

]);

Note: Don’t use this e-commerce tracking code on your website. It is just an example and is not even a complete code.

 

Whenever your server processes a transaction, your server side code populates the fields of _addTrans() method with the transaction data retrieved from your shopping cart software. For each unique product item (i.e. product SKU) in your visitor’s transaction, your server side code populates the fields of _addItem() method with the item data retrieved from your shopping cart software.

 

Do I need to add any special e-commerce tracking code for secure web pages (https://)?

No if you are using ga.js tracking code.

Note: the standards GATC can automatically detect when the ‘https’ protocol is being used.

 

Can Google Analytics track data from a shopping cart on other domain or sub-domain?

Yes. For more details refer to the post How cross domain tracking works in Google Analytics.

 

Where I can get more details about the various e-commerce tracking code issues?

Check out this help article.

 

 

If you like this post then you should subscribe to my blog and follow me on twitter.

 

Other Posts you may find useful:

 

 

Himanshu Sharma About the Author: is the founder of seotakeaways.com which provides SEO Consulting, PPC Management and Analytics Consulting services to medium and large size businesses. He holds a bachelors degree in ‘Internet Science’, is a member of 'Digital Analytics Association', a Google Analytics Certified Individual and a Certified Web Analyst. He is also the founder of EventEducation.com and EventPlanningForum.net.

My business thrives on referrals, so I really appreciate recommendations to people who would benefit from my help. Please feel free to endorse/forward my LinkedIn Profile to your clients, colleagues, friends and others you feel would benefit from SEO, PPC or Web Analytics.

 

 

  • https://www.thesslstore.com Kalpesh Patel

    This is really awesome…I badly needed this. It very much clear my mind about my queries regarding Google Analytics Thanks a Lot Himanshu.

  • http://www.kewl.in sanjeev

    Thanks for this detailed information on setting up conversion tracking in ecommerce. it’s more helpfull. I believe I can update my site with conversion tracking without any prb.

  • http://www.stream20.com Russell McAthy

    Very Nice post – always good to educate people on what each field is and how its calculated.

    I think its important to note than when you combine the Goal Funnels and Goal conversion rate it wont always match the e-commerce conversion rate depending on the way the e-comm funnel works on each site.

    Again thanks for an awesome post!

    • http://www.seotakeaways.com/ Himanshu

      Hi Russell! Thank you for your comment. Goal conversion rate and e-commerce conversion rate are fundamentally different metrics.

      • http://justeat.in Byomkesh Kumar

        Hi Himanshu, really helpful and detailed post. Has helped me a lot in getting the ecommerce fundamentals clear.
        Are you planning to post similar articles on goals, funnels and conversion, conversion tracking?

        • http://www.seotakeaways.com/ Himanshu

          May be :)

  • zubair

    Hey Himanshu ……thanks a lot …..believe it or not I went through a hell lot of sites just to understand how the tracking code dynamically captures the transaction values from the payment gateway. And just by the end of the day I saw ur linkedin update.

    Cheers!!!!

    • http://www.seotakeaways.com/ Himanshu

      Thanks Zubair. Glad you find the post useful.

  • Dan Richardson

    Another brilliant post from Himanshu. Fantastic stuff.
    Would love to see more on how to insert the PHP code to receipt page, without getting too deep into programming, as without this part (unless your ecomm s/w does it for you), you can’t track it. Not enough made of this imo.
    Bookmarked! Dan

    • http://www.seotakeaways.com/ Himanshu

      Thanks Dan. Unfortunately if i go any deep into PHP coding for e-commerce tracking then i first need to explain all the PHP programming concepts from the very beginning otherwise it won’t make sense for most of the non web developers readers. I would suggest you to take the help of a web developer for this task.

      • Dan Richardson

        Yes…what i meant was lots of guides/howtos make this sound easy, whereas dynamically pulling/writing php/javascript/whatever (i’m not a programmer in case you hadn’t guessed…) isn’t.
        (Wasn’t expecting you to tell us how to write the php Himanshu) :)
        Dan

  • Yari Montalbetti

    Thanks for your great post!

    • http://www.seotakeaways.com/ Himanshu

      Thanks Yari. Glad you find the post useful.

  • https://www.thesslstore.com Kalpesh Patel

    Himanshu… I have one question.
    We have multiple products in our website, All products detail page go to single checkout and thankyou page. My question is how can I create perfect funnel for each product wise. Currently I have setup product wise funnel but all go to single checkout and single thanksyou so in funnel for product 1 it shows 50 visitor land on this page 200 have gone to checkout and 120 have gone to thankyou.
    50 – > 200 -> 120 and that is wrong.

    • http://www.seotakeaways.com/ Himanshu

      You are setting up and interpreting the funnel visualization reports in a wrong way. You don’t need to set up product wise funnels. If you really want to look at the navigation path then check the ‘navigational summary report’ under Site content > All pages report.

  • Nimue

    perfect post. Thank you!

  • Nimue

    perfect post. Thank you!

    • seohimanshu

      Glad you like it.

  • yulia

    Hi! My code works. However, please help me to avoid the Google Analytic eCommerce double or triple-counting the revenue in my report. Do you think that the reason is because Customer and Vendor have access to the receipt page? How would you explain that this sometimes happens as well as when I refresh my Google Analytic Report?

    • seohimanshu

      If people can access your receipt page without making a purchase on the website then you need to talk to your web developer and request him to display the page only when someone make a purchase on the website. Send a copy of the receipt to your customers and vendors via email. Don’t let them access your receipt pages directly via a bookmark or a link.

  • Eric Erlebacher

    How can the total be less than the unit price?

    • seohimanshu

      where?

      • Eric Erlebacher

        In your examples, the product price is 76.65, but the total is 28.8.

        • seohimanshu

          common man. It is made up data and not even complete.

          • Eric Erlebacher

            Ok, but that’s my question here. I have a case where a unit price is normally $80, but we are running a sale for 50% off. The Total was listed as $40, but the Unit Price was $80. As a result, product revenue was over-reported by 100%. I want to tell the dev that the Total should never be less than the Unit Price, but I need to be sure first.

            • seohimanshu

              If you are running a sale for 50% off then the product revenue is going to be $40. In fact your unit price should also be $40.

  • raju krishna

    Can i use GA to manually frame a http ecommerce post with protocol fields. If i run in browser will it work. I can see data in realtime but not updated in reports later. My query looks Like

    http://www.google-analytics.com/collect?payload_data&z=123456&tid=UA-33585811-1&cid=5555&t=pageview&dp=billo&v=1&ta=trivium&tr=50.00&ti=OD564&ts=3.50&tt=11.20&ip=3.50&iq=4&in=Shoe&ic=x1&in=recorder&ec=finished&cs=tradus&cm=web&cn=automotosaled

    • seohimanshu

      I can’t see your query. The URL you have posted doesn’t work for me.

  • Jo Fabigal

    I have implemented e-commerce tracking and i have set up a URL goal for my purchase journey, however the total number of transactions and completed goals are different – can anyone explain why?

    Just to clarify only 1 item can be purchased at a time. The data I am seeing is as follows:

    Unique purchases = 13

    Quantity = 13

    Transactions = 16

    Goal purchase funnel completions = 12 (visitors finished)

    • seohimanshu

      Hi! Goals and ecommerce transactions are tracked differently in Google Analytics. Only one goal conversion is recorded per visitor session. For example if one of your goal is a file download and a visitor download 5 files in one web sessions then Google Analytics will record only one goal conversion. Similarly if one of your goal is a completed ecommerce transaction and a visitor carries out 3 transactions in one web session then Google analytics will record only one goal conversion. However Google Analytics will record three e-commerce transactions because transactions are tracked and recorded differently. So it is likely that you will see higher number of transactions than the number of goal conversions.

  • Shubh

    I want to remove my test orders from my ecommerce , test orders are made in mirror site . i want my standard reporting to be filtered and test orders are not visible in ecommerce transaction.. what i have to do.?

    • seohimanshu

      You can’t remove the data from reports once it is sent to the GA server. You can create a new profile with a different tracking code (different from the one on mirror site). In this way the test orders made on the mirror site won’t be recorded in your profile. If you don’t want to create a new profile than you can keep a note of the test orders you made and discount them from your final reporting. The other thing you can do is make changes to the e-commerce tracking code so that it labels the test orders as test orders in your report. Always use a different tracking code for your test/mirror site to avoid corrupting your original data.

  • nagarajan

    My code is perfect(meaning I used debugger and made sure the tracktrans, additem … are executes). But I could not see the values physically in the browser through firebug. Can we access the results only in GA.
    Thanks for the help

    • seohimanshu

      you can access the results only in GA

  • Qualli

    Unique Purchase: ” filter out the 1st product ” Why do i have to filter out the first product and how do i do that?

    • seohimanshu

      Sorry but your question is missing the context. Can you please elaborate your question.

      • Qualli

        Yeah.

        Here you write about unique purchases: ” If you look at the total unique purchases of the first product (which is 214) you may assume that 214 product items were sold in one transaction. But this is not the case. In order to truly find out how many product items were sold in one transaction you need to add ‘transaction’ as a ‘secondary dimension in the table above and then filter out the 1st product (using advanced filter on the reporting interface):”

        I dont understand why i have to filter out the first product and how i do that (what filter do i use?). I just don’t understand your context either. No offense but that’s what i want to understand ;)

        • Qualli

          And another question: I use ecommerce tracking for clickout generation to shopping sites. I have many products on the website. and i want to track every different clickout as its own conversion (transaction?). But if someone clicks on the same product two times (or more) it only should count as one clickout. Example: User clicks on Product A 2 times, then he clicks on Product B 1 time. That should be 2 conversions. Which metric do i use to find out how many different conversion a person did without the duplicated clicks on one product? Do you understand what i mean?

        • seohimanshu

          If you don’t filter out a product (whose unique purchases you want to see) then you will see unique purchases of a product item scattered throughout the report. I used the advanced filter available on the reporting interface.

  • vimal kumar

    Awesome Post.

  • mohitdxb

    Great post Himanshu! Very well described easy to read post.

  • Joyal George

    let me know all Parameters in _trackTrans() function is required?

    • seohimanshu

      we don’t pass any parameter in _trackTrans() method

  • Adrian Bereziuk

    Hi Himanshu

    Excellent and very relevant post thank you. Would you be kind enough to give me your opinion on the following question please?

    On my e-commerce site, I’m keen to show and report a more accurate conversion figure using GA and I want to filter out traffic from my conversions from visitors who have come on looking only for our store information so – would I be correct in using my ‘goal 2 conversion rate’ metric and then filtering out search traffic showing words relating to store locations?

    I’ve tried it and there is a really significant difference (far more that I’d have thought – around 7.5k%) between the two conversion rate figures after I filter this specific visitor traffic out. I’m obviously delighted about this but as there is such a difference, before I go and report on this, I’d like to have confirmation that I’m doing the right thing.

    Appreciate your comments.

    Thanks

    Adrian

    • seohimanshu

      If you are absolutely sure that the visitors looking for store information are not converting. Generally such visitors convert sooner or later or may be offline. If i were you I won’t filter out such visitors.

    • Adrian Bereziuk

      Hi Himanshu

      Many thanks for the reply.

      Because of the locations of the stores, I know there is a propensity for visitor checks to be made on locations, opening times etc and I need to take these into account which is why I have only specified visitors with store locations inside search terms. Some will of course convert online over time but as store and web business is treated as separate, I need a metric on which I can report on both over time.

      All the best

      Adrian

      • seohimanshu

        In order to track offline conversions, consider issuing a coupon on your website (with some special offer) and tracking number which can be redeemed offline at the store counter. Place this coupon on the store locations page. Once the coupon is redeemed offline you can track the visitors who came to the store via your website.

        You need to call the store manager to get this data once a month. In this way you can determine visitors who are looking for store locations on your website but making a purchase offline at the store. Calculate conversion rate of such visitors and report on it separately. Now remove these visitors from your online conversion rate calculations before you report on it.

  • hans

    Hello Himanshu, it is an excellent post regarding the Google Analytics and the code . However , I was just wandering as how do I imply this code to the tracking code. As through the codes.google.com , I have figure out to track your e-commerce transaction, you need to put these three methods , so should I paste this code in my main website coding snippets first or how do alter the tracking code to put those three methods over there. Because when I go to the tracking code it does not allow me to alter anything .

    Thank you in anticipation , Your help would be greatly appreciated.

    • seohimanshu

      Hi Hans! You need to take help of your web developer to add e-commerce tracking code to your order confirmation page. The actual e-commerce tracking code contains script specific variables.

  • Narendra

    Hi,
    This is perfect post for web analytics. I am following the same way, but still the revenue is showing/tracking as “zero”. Except revenue everything else is tracking fine. Can you help me in this.

    • seohimanshu

      Check your e-commerce tracking code and make sure that:

      1. _addTrans() method is passing the ‘total revenue’ value to the Google Analytics server.

      2. _addItem() method is passing the ‘product price’ value to the Google Analytics server.

      Take help of your web developer here who manage the shopping cart of your website.

  • http://www.facebook.com/mohitsareen Mohit Sareen

    Hi
    I have implemented e-commerce tracking on my website. However, it only captures about 50% of the transactions in the e-commerce section. At the same time it is tracking all the goal completions correctly and accurately.

    What could be the possible reason for that.

    • seohimanshu

      How you are so sure that it is tracking only 50% of the transactions?