我已使用“Better Google Analytics JavaScript that doesn’t block page downloading”动态加载 Google Analytics,这样它就不会阻止 HTML/页面呈现。
但是,有时我的 HTML 页面会阻止在 Firefox 3.0 (WinXP) 状态消息上呈现:
“从 www.google-analytics.com 传输数据”
对于如何以不会阻止 HTML/页面呈现的方式加载 Google Analytics JavaScript 有什么想法吗?
最佳答案
您可以使用 Google Analytics [跟踪代码的异步加载][1]。以下代码段应该有所帮助:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_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);
})();
</script>
关于javascript - Google Analytics - 阻止 HTML/页面呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/905353/