admin管理员组文章数量:1208155
I have used the "Better Google Analytics JavaScript that doesn’t block page downloading" to load Google Analytics dynamically so that it will not block HTML / page rendering.
However, it appears occassionaly that my HTML page will block rendering on the Firefox 3.0 (WinXP) status message states:
"Transferring data from www.google-analytics"
Any ideas on how to load the Google Analytics JavaScript in a way in which it will not block HTML/page rending?
I have used the "Better Google Analytics JavaScript that doesn’t block page downloading" to load Google Analytics dynamically so that it will not block HTML / page rendering.
However, it appears occassionaly that my HTML page will block rendering on the Firefox 3.0 (WinXP) status message states:
"Transferring data from www.google-analytics.com"
Any ideas on how to load the Google Analytics JavaScript in a way in which it will not block HTML/page rending?
Share Improve this question edited May 25, 2009 at 5:07 asked May 25, 2009 at 4:47 BenHelleyBenHelley 2- It uses the async attribute of the script tag. I think FF 3.0 doesn't support it. – Bart van Heukelom Commented Dec 22, 2009 at 11:44
- The article link is broken. Here is a link to the last cached version from April 2014 web.archive.org/web/20130402061350/http://lyncd.com/2009/03/… – Karl Glennon Commented Jul 3, 2014 at 8:00
5 Answers
Reset to default 7You could use Google Analytics [asynchronous loading of tracking codes][1]. The following snippet should help:
<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>
Put the Google Analytics code as the last thing before the </body>
tag, like Google recommends?
You may be seeing this bug. Before 3.6, FF sometimes incorrectly blamed google analytics for slowing down the page...
https://bugzilla.mozilla.org/show_bug.cgi?id=487638
But it at the bottom (just before the </body>) and delay it:
<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
<script type="text/javascript">
if (typeof(_gat)=='object')
setTimeout(function(){
_gat._getTracker("UA-1234567-8")._trackPageview()}, 1500);
</script>
Have a look at my explanation about why I think this is the "best way to integrate analytics".
The DEFER attribute may work for you
<script DEFER type="text/javascript" src="http://www.google-analytics.com/ga.js">
<script DEFER type="text/javascript">... tracker code ...</script>
本文标签: javascriptGoogle AnalyticsBlocks HTMLpage renderingStack Overflow
版权声明:本文标题:javascript - Google Analytics - Blocks HTMLpage rendering - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738731295a2109339.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论