Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics ecommerce sends only last item in transaction

I'm using Google Analytics to track page views and transactions. The problem is that the ecommerce tracking only sends the last item added.

Here's the code that 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 it only sends Product 2. Below are the requests that get sent:

enter image description here

As expected only the last item is being shown in the Google Analytics panel. The code seems right in every respect according to the Ecommerce Tracking Docs.

Any help on this would be greatly appreciated.

like image 571
Bogdan Avatar asked Nov 13 '13 12:11

Bogdan


People also ask

How does Google Analytics work with ecommerce?

With Basic ecommerce tracking in Google Analytics you get transaction and revenue data (e.g., revenue generated by your online store), while Enhanced ecommerce tracking offers additional information about visitor behavior for specific products at different stages of the purchasing process (e.g., the ratio of product ...

How does Google Analytics send data to transactions?

To send ecommerce data via measurement protocol, you would need to send one HTTP POST request for an entire transaction and one HTTP POST request for each item in the transaction. This HTTP POST request will send the payload data (which contains the transaction data) to Google Analytics.

Can Google Analytics track ecommerce?

Ecommerce Tracking is a feature of Google Analytics that tracks shopping activity on your website. You can use it to track and analyze transaction data, revenue, products you've sold, and more. Ecommerce data in Google Analytics will give you specific insights into: Products with a high (or low) number of sales.


1 Answers

Try specifying a unique SKU for each item -- with ga.js analytics, if you added multiple items with the same SKU, only the last would be recorded, just like you're seeing.

If you don't have a product SKU, use the product name.

like image 119
mike Avatar answered Sep 23 '22 01:09

mike