Google Analytics for eCommerce
From NewHaven Software Wiki
Revision as of 16:04, 8 April 2010 by Malcolm lee (Talk | contribs)
Below is the code you need to track visits and sales for Google Analytics. The documentation for the Google Analytics eCommerce API is here.
If you have questions or issues please contact ecms@newhavensoftware.com. (Google Analytics is not part or the default install so any modifications will likely be billable).
Make sure you replace the tracker ID with the customer's ID (_gat._getTracker("UA-XXXXXXX-X")) and change the affiliate to the store name or leave it blank.
You will want to put this in the _bottom.tpl.
{**** Begin Google Analytics Code ****} <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try {ldelim} var pageTracker = _gat._getTracker("UA-1666866-3"); pageTracker._trackPageview(); {rdelim} catch(err) {ldelim}{rdelim}</script>
You will want to put this in the checkout_thanks.tpl.
{*** Sales Tracking Code ****} {if $view == 'checkout_thanks'} <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-1666866-3"); pageTracker._trackPageview(); pageTracker._addTrans( "{$placed.info.order_id}", // Order ID "W00t", // Affiliation "{$placed.info.totals.subtotal}", // Total "{$placed.info.totals.taxtotal}", // Tax "{$placed.info.totals.shiptotal}", // Shipping "{$placed.info.billing.billing_city}", // City "{$placed.info.billing.billing_state}", // State "{$placed.info.billing.billing_country}" // Country ); {foreach from=$placed.cart item=ditem key=dkey} {assign var="dcat" value=$ditem.cat} pageTracker._addItem( "{$placed.info.order_id}", // Order ID "{$ditem.sku}", // SKU "{$ditem.name}", // Product Name "{$categories.$dcat.name}", // Category "{$ditem.real_price}", // Price "{$ditem.qty}" // Quantity ); {/foreach} pageTracker._trackTrans(); </script> {/if} {**** End Google Analytics Code ****}