简体   繁体   中英

Ecommerce tracking google analytics

HI i am trying to send data using analytics.js but show error.

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

The error in developer tools says: Running command: ga("ecommerce.send");

analytics_debug.js:25 Command ignored. Unknown target: undefined and Running command: ga("send", "pageview") analytics_debug.js:25 Unallowed document protocol. Aborting hit.

I searched in internet but many said to add targetname but it is also not working.

You are mixing _ga and _gaq code library. The second library is deprecated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM