Google Analytics电子商务跟踪功能无法使用 - 使用analytics.js

时间:2014-08-21 22:13:11

标签: javascript 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');

//Add Console log like below
console.log("Entering the Analytics code tracking");

ga('require', 'ecommerce', 'ecommerce.js'); 
//Add Console log like below
console.log("Loaded ecommerce.js");

ga('create', 'UA-XXXXXXX-X', 'auto');
ga('send', 'pageview');

//Add Console log like below
console.log("Adding Transaction");

ga('ecommerce:addTransaction', {
    'id': '<%=intNewOrdrID%>',                 // Transaction ID. Required.
    'affiliation': 'OTG',       // Affiliation or store name.
    'revenue': '<%=strGrandTotal%>',             // Grand Total.
        'shipping': '<%=strShipping%>',             // Shipping.
    'tax': '<%=strTax%>'                    // Tax.
});

    <%for (int i = 0; i < dtOrderDetails.Rows.Count; i++)
      {%>
ga('ecommerce:addItem', {
    'id': '<%=intNewOrdrID%>',                 // Transaction ID. Required.
    'name': '<%=dtOrderDetails.Rows[i]["ProductName"].ParseString().Replace("'", "\\'")%>', // Product name. Required.
    'sku': '<%=dtOrderDetails.Rows[i]["SKU"].ParseString()%>',                // SKU/code.
    'category': 'OTG Product',        // Category or variation.
    'price': '<%=dtOrderDetails.Rows[i]["DiscountedPrice"].ParseString()%>',               // Unit price.
        'quantity': '<%=dtOrderDetails.Rows[i]["Quantity"].ParseString()%>'               // Quantity.
});
<%}%>

//Add Console log like below
console.log("About to send transaction details");
ga('ecommerce:send');
</script>

我已经检查了几乎所有东西,但是已经没有想法;有人可以扫描并检查吗? 谢谢, -dev

1 个答案:

答案 0 :(得分:0)

我认为您将其与所有<%=intNewOrdrID%>清理数量相混淆,例如应该是一个不是<%=dtOrderDetails.Rows[i]["Quantity"].ParseString()%>的数字

 ga('ecommerce:addTransaction', {
  'id': '1408689736',                     // Transaction ID. Required.
  'affiliation': 'Item Data Send Test',   // Affiliation or store name.
  'revenue': '11.99',               // Grand Total.
  'shipping': '5',                  // Shipping.
  'tax': '1.29'                     // Tax.
});  
  ga('ecommerce:addItem', {
  'id': '1408689736',                     // Transaction ID. Required.
  'name': 'All Values Sent',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});
 ga('ecommerce:send');