Adam Stevens Adam Stevens - 1 year ago 123
Javascript Question

Google Analytics Ecommerce Tracking Data Issue

The Google Analytics example code for tracking ecommerce in the new analytics.js instead of ga.js gives data in the fields where I have $product['name'] etc.

The code below currently doesn't work and I'm not 100% sure it's pulling the correct information onpage as this is what is shown in the page source instead of 'id': '{1455}', it's showing 'id': '{$order_query['order_id']}',. We're using Opencart

Is this the correct code?
Are the $price, $product['name'] sections correct?

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-21397982-1', 'auto');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');

ga('ecommerce:addTransaction', {
'id': '{$order_query['order_id']}',
'revenue': '{$price}',
ga('ecommerce:addItem', {
'id': '$order_query['order_id']',
'name': '{$product['name']}',
'sku': '{$product['model']}',
'price': '{$product['price']}',
'quantity': '{$product['quantity']}',
'currency': 'GBP'


Answer Source

your raw php code should be echoing out the values in to the JavaScript

'id': '{<?php echo $order_query['order_id']; ?> }',

what you are sending to Google Anlayitcs now is the

id of "{$order_query['order_id']}" which is a text string and not going to work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download