Google Analytics Ecommerce only sends the last item in a transaction

I use Google Analytics to track pageviews and transactions. The problem is that ecommerce tracking only sends the last item added.

Here is the code I'm using:

<script type="text/javascript"> (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-XXXXXXXX-1'); // fake code here ga('send', 'pageview'); ga('require', 'ecommerce', 'ecommerce.js'); ga('ecommerce:addTransaction', { 'id': '31887', 'revenue': '152.80', 'shipping': '15.00', 'currency': 'RON' }); ga('ecommerce:addItem', { 'id': '31887', 'name': 'Product 1 ', 'price': '94.90', 'quantity': '1' }); ga('ecommerce:addItem', { 'id': '31887', 'name': 'Product 2 ', 'price': '57.90', 'quantity': '1' }); ga('ecommerce:send'); </script> 

The code above should send 2 items, but only sends Product 2 . The following are the requests that are sent:

enter image description here

As expected, only the last item is displayed in the Google Analytics panel. The code seems to be correct in every way in accordance with the Electronic Commerce Tracking Documentation .

Any help on this would be greatly appreciated.

+6
source share
1 answer

Try to specify a unique SKU for each element - with ga.js analytics, if you add several elements with the same SKU, only the last one will be written, as you see.

If you do not have a SKU product, use the product name.

+18
source

Source: https://habr.com/ru/post/957991/


All Articles