views:

1681

answers:

6

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?

+4  A: 

Put the Google Analytics code as the last thing before the </body> tag, like Google recommends?

chaos
I have and if you notice from the lyncd.com article code, it dynamically loads the JS into the head element.
Okay. When you're seeing the "Transferring data from www.google-analytics.com" message, has anything on your page actually been blocked from rendering, or does the page appear to have finished apart from that message hanging around?
chaos
When I see the message, the page has a noticeable block in rendering the page. I have JS that turns some DIV display from "none" to "block" but that code doesn't occur because the page get stuck on this "transfering data from www.google-analytics.com"
I see. Well, you could try arranging to have the script appended slightly after page load, on a short setTimeout; that at least will let other immediately pending operations run before it waits on Analytics. If that doesn't work or isn't feasible, you'd probably have to work out a way to pull the Analytics script using AJAX, which seems a bit challenging.
chaos
+1  A: 

But it at the bottom (just before the </body>) and delay it:

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"&gt;&lt;/script&gt;
<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".

cherouvim
+1  A: 

The DEFER attribute may work for you

<script DEFER type="text/javascript" src="http://www.google-analytics.com/ga.js"&gt;

<script DEFER type="text/javascript">... tracker code ...</script>
SpliFF
+4  A: 

You could use Google Analytics asynchronous loading of tracking codes. 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.src = ('https:' == document.location.protocol ? 'https://ssl' : 
        'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();

</script>

Place this before the closing body tag.

James
FYI - this code is out of date. Google has published an update:http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html
Brian
+2  A: 

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

Brian
A: 

I have FF3.5.13 and when I try to load certain websites it flashes the page real quick and at the bottom it gives me this "Transferring data from www.google-analytics.com" message. Is this a virus? or is there a setting on FF that I accidentally turned on? Need Help!

Thanks

John