Hi All,
I have been looking around for ways to add The Google Analytics Ecommerce tracking code into SwipeStripe for the last couple of days.
I have had no success, but was wondering if I was going about this the right way.
I have been editing the Order.php file in the "Swipestripe/Code/Order" Directory, as I believe this is the page displayed when the user finishes purchasing items.
Can someone please let me know if the following looks correct, or if there is anything I should be doing?
The following has been added to Order.php:
class Order_Controller extends ContentController {
public function init() {
parent::init();
Requirements::insertHeadTags("<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{
var pageTracker = _gat._getTracker('UA-CODE-1');
pageTracker._trackPageview();
pageTracker._addTrans(
'#$ID', // transaction ID - required
'Company Name', // affiliation or store name
'$Total.Nice', // total - required
'6.00' // shipping
);
// 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
pageTracker._addItem(
'#$ID', // transaction ID - necessary to associate item with transaction
'#$ID', // SKU/code - required
'$Item.Object.Title', // product name
'$Item.UnitPrice.Nice', // unit price - required
'$Item.Quantity' // quantity - required
);
pageTracker._trackTrans(); //submits transaction to the Analytics servers
} catch(err) {}
</script>");
}
}
Hopefully someone can point me in the right direction.
Thanks
-helenclarko