Google Analytics电子商务仅发送交易中的最后一项

时间:2013-11-13 12:41:44

标签: google-analytics

我正在使用Google Analytics跟踪网页浏览量和交易。问题是电子商务跟踪仅发送最后添加的项目。

这是我正在使用的代码:

<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>

上面的代码应该发送2个项目,但它只发送Product 2。以下是发送的请求:

enter image description here

正如预期的那样,只有最后一项显示在Google Analytics面板中。根据{{​​3}},代码似乎在各方面都是正确的。

对此的任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:23)

尝试为每个项目指定唯一的SKU - 使用ga.js分析,如果您添加了多个具有相同SKU的项目,则只会记录最后一个,就像您所看到的那样。

如果您没有产品SKU,请使用产品名称。