Google Analytics News

Google Checkout and Google Analytics
November 3, 2010

Since, October of 2006, Google Checkout users have been able to track transactions within Google Analytics.

The problem is that since 2006, the basic Google Analytics code has changed THREE times, from urchin.js to ga.js to the asynchronous version of ga.js.

Unfortunately, the Google Checkout integration is one whole version behind. Seriously, the extensive documentation found here doesn't even mention the asynchronous code (as of 11/1/2010).

Well, hopefully we here at ROI Revolution can help with this problem until a more integrated solution comes out. The best part is this solution is pretty simple.

As with any Google Analytics / Google Checkout integration, there are basically two steps.

Check after the jump for the complete instructions!

Step 1: Add a hidden field to your Google Checkout buttons.

This step hasn't changed from previous integrations, so if you've done this before, you should be all set.

Basically, each Google Checkout button on the page needs to have a hidden field added with the name "analyticsdata", like this:

<input type="hidden" name="analyticsdata" value="">

If you're feeling fancy, you can even add this code dynamically using JavaScript.

Previous versions of the code also require you to add an onsubmit event. With the asynchronous Google Analytics code, this is no longer necessary. In fact, if you have the onsubmit event that calls the function setUrchinInputCode, you must remove it.

Step 2: Add some code after the asynchronous Google Analytics code on the site.

Your asynchronous Google Analytics code should look something like this:

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Simply add this code below the Google Analytics script - and AFTER any forms on the page that use Google Checkout:

<script src="http://checkout.google.com/files/digital/ga_post.js" type="text/javascript">
</script>
<script>
_gaq.push(function () {
var pageTracker = _gat._getTrackerByName();
setUrchinInputCode(pageTracker);
});
</script>

An important thing to note here if your site uses a secure protocol (https://), then you'll need to update the src of ga_post.js to this:

https://checkout.google.com/files/digital/ga_post.js

Again, if you have an older version of the Google Analytics code, you can find the instructions for integrating Google Analytics.