If you use Google Analytics on your site then you can track purchases and monitor where customers come from - tons of useful info actually.
To do this you need to add some extra javascript to your “order success” page.
I have a single order_info template that contains a conditional that will show different messages depending on whether the order was successful or not.
To track purchase info, in the “approved” part of this conditional I added the following within the {exp:weblog:entries} tag pair that is outputting the order information.
(be sure to add your Analytics Account ID - it’s normally something like: UA-123456789-1
script opening tag here - the forum won't let me include it
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'{title}', // order ID - required
'Amano Direct Web Shop', // affiliation or store name
'{order_total}', // total - required
'{order_tax}', // tax
'{order_shipping}', // shipping
'', // city
'', // state or province
'UK' // 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
{order_items}
_gaq.push(['_addItem',
'{title}', // order ID - required
'{item:entry_id}', // SKU/code
'{item:title}', // product name
'{item:item_option}', // category or variation
'{item:price}', // unit price - required
'{item:quantity}' // quantity - required
]);
{/order_items}
_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';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
script closing tag here - the forum wont let me include it
My products don’t have unique product codes/SKU so I am using the entry_id but you can use whatever you wish
I’m also not using product options so at this stage I can’t confirm whether that is going to work as is, but the principle is the same.
