0
votes

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

1
Did you enable enhanced e-commerce in the GA admin settings? - nyuen
No, I didn't. I enable only the simple one. - carvao
Sorry, my bad, I thought you were using enhanced ecommerce. What leads you to believe that there is a problem? Is there an error message somewhere or is data not showing up after 48 hours, or ?? - nyuen
48 hours? I thought it was immediately. I buy something and it does not appear in the analytics. - carvao
You need to wait up to 48 hours for data to be processed, but typically you should see updates in even as short as 5 hours (depending on the amount of configuration in GA). You can use GA Debugger (Chrome addon) to immediately see if your hits go through to GA though. - nyuen

1 Answers

2
votes

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.