Google跟踪功能(i,s,o,g,r,a,m)代码如何工作?

时间:2019-04-11 18:08:54

标签: javascript google-analytics

(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.js', 'ga');

我想了解这段代码(ga('create', 'UA-XXXXX-Y', 'auto');ga('send', 'pageview');之前的代码)到底是做什么的?

1 个答案:

答案 0 :(得分:1)

对于代码的工作方式,看起来像这样的细分:http://code.iamkate.com/javascript/understanding-the-google-analytics-tracking-code/