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
Add a comment  | 

5 Answers 5

Reset to default 7

You 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