为什么我需要使用:
<script type="text/javascript" charset="utf-8">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push( ['_setAccount', 'xxxxxxxxxx'] );
_gaq.push( ['_trackPageview'] );
_gaq.push( ['_trackPageLoadTime'] );
(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 );
})();
//]]>
</script>
而不是
<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
<script type="text/javascript" charset="utf-8">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push( ['_setAccount', 'xxxxxxxxxx'] );
_gaq.push( ['_trackPageview'] );
_gaq.push( ['_trackPageLoadTime'] );
//]]>
</script>
答案 0 :(得分:2)
因此它可以与页面的其余部分异步加载。以前,GA代码会阻止其他内容加载,因为JavaScript下载和解析时会阻止页面的其余部分加载。当它是异步时,它不会这样做。结果是更快的页面加载速度和更准确的跟踪。