Google Analytics(分析)跟踪代码如何工作? (异步方法调用?) [英] How is the Google Analytics Tracking code working? (async method call?)
本文介绍了Google Analytics(分析)跟踪代码如何工作? (异步方法调用?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码是Google Analytics(分析)跟踪代码.由于ga方法未得到改进,怎么不会出错?
This code is the Google Analytics tracking code. How is not make an error because of undifened ga method?
(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-XXXX-Y', 'auto');
ga('send', 'pageview');
推荐答案
展开后,脚本如下所示:
Expanded, the script looks like this:
(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-XXXX-Y', 'auto');
ga('send', 'pageview');
您会注意到,'ga'
是传递给该函数的第五个参数,而window
是第一个传递给该函数的参数.在初始化内部,前几行将i[r]
(也称为window['ga']
)设置为一个函数.然后你就走了!
You'll notice that 'ga'
is the fifth parameter passed to the function, and window
is the first. Inside the initialization, the first couple lines set i[r]
, aka window['ga']
to a function. And there you go!
这篇关于Google Analytics(分析)跟踪代码如何工作? (异步方法调用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文