Google Analytics eCommerce Tracking

Here is the script that needs to be added to the receipt or confirmation page, after the user has completed the sale. You will just need to add php inside of the script so that the content can be created dynamically per customer. One tip is to use a PHP loop. Here is the code:

<script type="text/javascript">



ξ var _gaq = _gaq || [];

ξ _gaq.push(['_setAccount', 'UA-XXXXX-X']);

ξ _gaq.push(['_trackPageview']);

ξ _gaq.push(['_addTrans',

ξ ξ '1234', ξ ξ ξ ξ ξ // order ID - required

ξ ξ 'Acme Clothing', ξ// affiliation or store name

ξ ξ '11.99', ξ ξ ξ ξ ξ// total - required

ξ ξ '1.29', ξ ξ ξ ξ ξ // tax

ξ ξ '5', ξ ξ ξ ξ ξ ξ ξ// shipping

ξ ξ 'San Jose', ξ ξ ξ // city

ξ ξ 'California', ξ ξ // state or province

ξ ξ 'USA' ξ ξ ξ ξ ξ ξ // country

ξ ]);



ξ ξ// add item might be called for every item in the shopping cart

ξ ξ// where your ecommerce engine loops through each item in the cart and

ξ ξ// prints out _addItem for each

ξ _gaq.push(['_addItem',

ξ ξ '1234', ξ ξ ξ ξ ξ // order ID - required

ξ ξ 'DD44', ξ ξ ξ ξ ξ // SKU/code - required

ξ ξ 'T-Shirt', ξ ξ ξ ξ// product name

ξ ξ 'Green Medium', ξ // category or variation

ξ ξ '11.99', ξ ξ ξ ξ ξ// unit price - required

ξ ξ '1' ξ ξ ξ ξ ξ ξ ξ // quantity - required

ξ ]);

ξ _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers



ξ (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>
error

Enjoy this blog? Please spread the word :)