Ecommerce Tracking code for Google Analytics
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
Re: Ecommerce Tracking code for Google Analytics
What exact file are you adding this to??
Re: Ecommerce Tracking code for Google Analytics
/templates/tpl_checkout_success_default.php.
This is the correct file, isn't it?
Google Analytics registrered my first test with pre filled fields.
Now, it's a matter of getting the dynamic fields right, so product name, price, shipping, tax etc is sent to Analytics when a order is placed.
Re: Ecommerce Tracking code for Google Analytics
Try adding it to
/includes/modules/pages/checkout_success/html_header.php
Re: Ecommerce Tracking code for Google Analytics
Ok, will try that, but why?
Google registered the tracking code when I had prefilled the fields when placed in /templates/tpl_checkout_success_default.php.
So you think the fields are correct?
'.$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
'.$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
Re: Ecommerce Tracking code for Google Analytics
I only stated that you could "TRY" that file
Re: Ecommerce Tracking code for Google Analytics
Ok, then I think I'll stick with the file I already know works.
The issue I wonder about is the different fields, if these are correct.
Cheers
Re: Ecommerce Tracking code for Google Analytics
Have put the code in the tpl_footer.php and put it in a new folder called checkout_success in the templates folder, so the Analytics code doesn't appear twice on the same page. I have the ordinary tracking code set up in tpl_footer.php.
I'm still missing the different variables in the ecommerce tracking code.
I've tried to look at the Simple Analytics module and the code, but haven't figured it out yet.
Here's what I've tried with (have tried different variations of this):
\"". $order->fields['orders_id'] . "\", // order ID - required
'Sykkelsport AS', // affiliation or store name
\"". $order->fields['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
\"". addslashes($products->fields['skucode']) ."\", // SKU/code - required
\"". addslashes($products->fields['products_name']) ."\", // product name
\"". addslashes($category->fields['categories_name']) ."\", // category or variation
\"". number_format($products->fields['final_price'], 2, '.', '') ."\", // unit price - required
\"". $products->fields['products_quantity'] . "\" // quantity - required
Have also tried to find the variables from the tpl_checkout_process.php file, but only a couple of the ones required are there as far as I can see.
Any help would be greatly appriciated.
Cheers
Endre