I recently updated the tracking code on a website to the new analytics.js and everything seems to be working fine except for the conversion aspect. The site is built on Big Commerce platform which limits my ability to modify server-side scripts, but this is the code they are currently using:
<script type="text/javascript">
$(document).ready(function() {
if(typeof(pageTracker) != 'undefined') {
pageTracker._addTrans(
'358',
'Backyard Toy Company ',
'0.01',
'0.00',
'0.00',
'Lakewood',
'New Jersey',
'United States'
);
pageTracker._addItem(
'358',
'1336',
'test',
'',
'0.01',
'1'
);
pageTracker._trackTrans();
}
});
</script>
After some modifications, I have updated the client-side code to the following:
ga('require', 'ecommerce', 'ecommerce.js'); // Load the ecommerce plug-in.
// START CUSTOM CODE
function old2new() {
// define object that can route old methods to new methods
this._addTrans = addTrans;
this._addItem = addItem;
this._trackTrans = trackTrans;
}
function addTrans(orderID,store,total,tax,shipping,city,state,country) {
// remap _addTrans
ga('ecommerce:addTransaction', {
'id': orderID,
'affiliation': store,
'revenue': total,
'tax': tax,
'shipping': shipping,
});
}
function addItem(orderID,sku,product,variation,price,qty) {
// remap _addItem
ga('ecommerce:addItem', {
'id': orderID,
'sku': sku,
'name': product,
'category': variation,
'price': price,
'quantity': qty
});
}
function trackTrans() {
ga('send', 'ecommerce');
}
// instantiate converter using name of old Google tracking object
// bigcommerce code will use this and be none the wiser
var pageTracker = new old2new();
// END CUSTOM CODE
Apologies for being new to this, but despite my efforts, I haven't been able to identify the reason why it's not functioning properly.