Saturday, March 6, 2010

Google Analytics Ecommerce Tracking Not Working?

When it comes to tracking ecommerce transaction in Google Analytics, people usually have complaint that they have problem in tracking ecommerce transactions or data is not tracked properly. In this post I have tried to answer the following.

1. How to track e-commerce transactions?
2. How to track a 3rd-party shopping cart?

First step for tracking ecommerce transactions is generating Ecommerce tracking pixel in the prescribed format and placing it at the right place.

The actual ecommerce code to be placed on the thank you page of the website would be.
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
pageTracker._addTrans(“”,””,””,””,””,””,””,””);
pageTracker._addItem(“”,””,””,””,””,””);
pageTracker._trackTrans();
} catch(err) {}
</script>


Below is the brief explanation of generating the above code.
For the normal analytics code, you will have call 2 functions “_addTrans() and _addItem()” after pageTracker._trackPageview(); We need to call the _addTrans() functions. (details are explained below)
<script type="text/javascript">


var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._trackPageview();
pageTracker._addTrans(
"1234", // Order ID
"Mountain View", // Affiliation
"18.28", // Total

"1.29", // Tax
"5", // Shipping
"San Jose", // City
"California", // State
"USA" // Country
);

pageTracker._addItem(

"1234", // Order ID
"DD44", // SKU
"T-Shirt", // Product Name
"Green Medium", // Category
"11.99", // Price
"1" // Quantity
);
pageTracker._trackTrans();
} catch(err) {}</script>

If your website initiates a purchase checkout process on a different subdomain (for example, if you send customers from www.bangaluru.com to shoppingcart.bangaluru.com):
Add the following line (in bold) to your tracking code on both your store site and your shopping cart pages:

Google Analytics can track data from a shopping cart on your own domain, or even on other domains, with the addition of some code. If your store site is on a different subdomain or domain than your main site, follow the instructions below to configure your pages.

If your website initiates a purchase checkout process on a different subdomain (for example, if you send customers from

www.mystore.com to shoppingcart.mystore.com):

Add the following line (in bold) to your tracking code on both your store site and your shopping cart pages:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._setDomainName("mystore.com");
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
</script>


If your website initiates a purchase checkout process on a separate store site (for example, if you send customers from http://www.mystore.com/ to www.securecart.com):

  1. Add the following lines to your tracking code on both your store site and your shopping cart pages. This code must occur above the code in Step 2.


    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-xxxxxx-x");
    pageTracker._setDomainName("none");
    pageTracker._setAllowLinker(true);
    pageTracker._trackPageview();
    </script>

  2. Change the links from the main site to the secure site to use_link as follows. Please note that your analytics tracking
    code and calls to _gat._getTracker (shown in Step 1) must be placed on the page above the call to_link. If your current links look like:

<a href="https://www.securecart.com/?store=parameters"> Purchase Now </a>

change them to:

<a href=" https://www.securecart.com/?store=parameters" onclick="pageTracker._link(this.href); return false;">Purchase Now</a>

No comments: