I'm trying to implemetn the Ecommecre Tracking code to use in Google Analytics.
I'm not interested in installing any of the module, would like to just put the tracking code on the checkout_success.php page.
Below is what I've added to this file so far. Can someone tell me if this is correct, or point me in the right direction?
The code worked with manually filled fields, but haven't registrered any purchases with this code yet:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'.$order->fields['orders_id'].', // order ID - required
'Store Name', // affiliation or store name
'.$orders['ot_total'].', // total - required
'.$order->fields['ot_tax'].', // tax
'.$order->fields['ot_shipping'].', // shipping
'.$order->fields['city'].', // city
'.$order->fields['state'].', // state or province
'.$order->fields['country'].' // 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',
'.$order->fields['orders_id'].', // order ID - required
'.$products->fields['skucode']', // SKU/code - required
'.$products->fields['products_name'].', // product name
'.$category->fields['categories_name'].', // category or variation
'.$products->fields['final_price'].', // unit price - required
'.$products->fields['products_quantity'].' // 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>
Cheers
Endre
Bookmarks