谷歌分析JavaScript的
问题描述:
这是一个谷歌Analytics(分析)代码谷歌分析JavaScript的
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20366831-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
我的客户端如何调用谷歌匿名函数?
答
这就是所谓的,因为匿名函数与()
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})(); // <--- The() calls the anonymous code
结束正如你看到的,这个代码基本上注入一个script
标签到DOM,它获取浏览器上运行。
答
该代码段已经自行调用。
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
它实际上做的是包括你的页面,这是类似这样的的ga.js:
<script src="//google-analytics.com/ga.js" />
休息取决于你向_gaq添加事件(谷歌分析tic队列)。然后该事件将自动处理。