Reputation: 23
I don't know why Google Analytics is not reading my code. I don't know where it is my mistake. the code that is generate when I do a transaction is this:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-1', 'auto');
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '195', // Transaction ID. Required.
'affiliation': 'Company name', // Affiliation or store name.
'revenue': '18.00', // Grand Total.
'shipping': '0.00', // Shipping.
'tax': '3.12', // Tax.
'currency': 'EUR'
});
ga('ecommerce:addItem', {
'id': '761', // Transaction ID. Required.
'name': 'Agus y los monstruos 3. La canción del parque ESP.', // Product name. Required.
'sku': 'xxxxx', // SKU/code.
'category': 'Primeres novel·les', // Category or variation.
'price': '9.00', // Unit price.
'quantity': '2' // Quantity.
});
ga('ecommerce:send');
ga('send', 'pageview');
</script>
I write this in the header. I don't know if something is missing or if I should load a library previously.
Thanks
Upvotes: 0
Views: 295
Reputation: 598
Your code looks fine although the ID in Item and transaction should be the same. Have you enabled ecommerce tracking in google analytics. Do you see any errors in the console?
Hope this helps,
Cheers Analytics ML.
Upvotes: 2