Looking at adding Google Analytics E-commerce tracking to a website running on a closed source e-commerce platform. Google have given us this code as an example in their help system:
<html>
<head>
<title>Receipt for your clothing purchase from Acme Clothing</title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'1234', // transaction ID - required
'Acme Clothing', // affiliation or store name
'11.99', // total - required
'1.29', // tax
'5', // shipping
'San Jose', // city
'California', // state or province
'USA' // 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',
'1234', // transaction ID - required
'DD44', // SKU/code - required
'T-Shirt', // product name
'Green Medium', // category or variation
'11.99', // unit price - required
'1' // 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>
</head>
<body>
Thank you for your order. You will receive an email containing all your order details.
</body>
</html>
Would this just be placed onto the final sale page or would I need to do anything to the data? Unsure as have never done this before, the site is running on php/mysql scripts.
To implement GA ecommerce tracking, you'll need to know your cart variable names (orderTotal, orderArray, etc - varies for every cart platform) and how to insert them into the script when the thank-you page is rendered, so that the customer's order has correct details.
Generally, you'd insert all of the addTrans variables, then perform a loop (one pass for each item in the cart) for addItem. But, the details of this really depend on your cart, so I can't be much more specific than that.
Depending on the size/savvy of your cart's community, you may be able to find a pre-cooked example that you can drop onto your thank-you page template, or it may even have this built in as a module.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.