电子商务跟踪Google Analytics(分析)

时间:2020-06-13 20:55:47

标签: google-analytics

嗨,我正在尝试使用analytics.js发送数据,但显示错误。

<head>
  <meta charset="utf-8">
  <title>GanalaticsDemo</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>

<form action="">
  <label for="gsearch">Search Google:</label>
  <input type="search" id="gsearch" name="gsearch">
  <input type="submit">
</form>


<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', 'https://www.google-analytics.com/analytics_debug.js', 'ga');
      })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
    var _gaq = _gaq || [];

_gaq.push(["_setAccount", "UA-169197862-1"]);
_gaq.push(["_setDomainName", "none"]);
_gaq.push(["_trackPageview"]);
// window.ga_debug = {trace: true}; 

ga('create', 'UA-169197862-1', 'auto');// add your tracking ID here.

ga('require','ecommerce','ecommerce.js')
ga('ecommerce:addTransaction',{

    'id':'1234',//Transaction id 
    'affiliation':'skinny jeans',
    'revenue':'28.8',
    'shipping':'10.00',
    'tax':'1.89'
});

ga('ecommerce:addItem',{

    'id':'1234',
    'name':'OKEJeans',
    'sku':'SKJ49',
    'category':'Men Jeans',
    'price':'76.65',
    'quantity':'1'
});
ga('ecommerce.send')
ga('send', 'pageview');


</script>
<a href="http://www.example.com/products/detail/product-1.html#contactsales" onclick="ga('send', 'event', 'Contact Sales', 'click');">Contact Sales</a>

</body>

开发人员工具中的错误显示:正在运行命令:ga(“ ecommerce.send”);

analytics_debug.js:25命令已忽略。未知目标:未定义,正在运行命令:ga(“ send”,“ pageview”) analytics_debug.js:25不允许的文档协议。打败了。

我在互联网上进行搜索,但很多人说要添加目标名称,但它也无法正常工作。

1 个答案:

答案 0 :(得分:0)

您正在混合_ga和_gaq代码库。不推荐使用第二个库。

相关问题