Google Analytics 的异步操作
目前很多网站都使用了 Google Analytics 来跟踪各个页面的访问情况,但经常会出现页面过慢,JS 执行错误等问题,导致统计的结果不准确。现在 Google 提供了一个新的功能─异步跟踪:
- Faster tracking code load times for your web pages due to improved browser execution
- Enhanced data collection and accuracy
- Elimination of tracking errors from dependencies when the JavaScript hasn't fully loaded
JS 代码片段:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
Comments (0)
