Tracking Third Party Shopping Carts using Google Analytics

March 28, 2008

As I wrote a few months ago Google Analytics allows you to track e-commerce transactions. I wanted to write an article to further elaborate on e-commerce tracking when it comes to Google Analytics for a while now so here it is. Because Google Analytics has changed in the last few months with the biggest change being the move from Urchin.js to GA.js, I felt that it was fitting to discuss the use Google Analytics on third party shopping carts.

Using different Web and e-commerce software together always poses a challenge to business owners looking to develop their businesses further and until Google owns the online world this will always be a problem. Different APIs working (and not working) together pose big business problems and cause them to continue to look for better solutions. That being said I am going to give you a simple and straight forward way to track third party shopping carts in Google Analytics…

  1. You are going to need to edit the html files of your e-commerce site
  2. Add the following code to your web store and shopping cart pages…

<script type=quot;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(”purewebanalytics.com”);
pageTracker._setAllowLinker(true);
pageTracker._initData();
pageTracker._trackPageview();
</script>

Note: To customize the _setDomainName function you will need to update the code with your company’s URL

If you’re website uses a third party shopping cart that is hosted by the vendor (meaning you redirect your customers from yourdomain.com to myvendorscart.com in the checkout process) you will need to customize Google Analytics tracking further in the following way. Remember that myvendorscart.com is a dummy URL I am using for the purpose of this article and it is NOT a valid third party shopping cart platform…

Add the following code to your web store and shopping cart pages (Must appear above the code mentioned 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._initData();
pageTracker._trackPageview();
</script>

Next, change the links for your web store to your vendor’s shopping cart using _link attribute and change the code on your web store from…

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

To this…

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

Notes:If you use forms on your shopping cart pages then you will need to make a change to the form itself similar to this…

<form name=”post_form” method=”post” onsubmit=”pageTracker._linkByPost(this)”>

… Your form code goes here…

</form>

If your web store pages use calls to _trackPageview(), _link(), _trackTrans(), or _linkByPost() your Google Analytics tracking code MUST be placed above these calls and the code can be placed after the <body> and before the Javascript call.

Attention: Keep in mind that this code is compatible if you are running the GA.js Google Analytics Tracking Code on your web store and that if you are using the Urchin.js version DO NOT use this code as it is only for web presences running GA.js.

I seem to be writing a number of follow-up articles lately like the one I published the other day “Using Internal Site Search in Google Analytics” because these are topics that are important to a wide number of owners of e-commerce and web presences in general. I hope that the benefit you as well in your e-commerce and web-based businesses.

Luc

Related Articles:

Comments

Got something to say?





*
To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation