views:

428

answers:

3

To use Google Analytics, you put some JavaScript code in your web page which will make an asynchronous request to Google when the page loads.

From what I have read, this shouldn't block or slow down page load times if you include it directly before the end of your HTML Body. To verify this, I want to make the request after some period of time. The user should be able to log into my site regardless of the time it takes for the request to Google or if it comes back at all (the tracking code is on the login page).

There is a 'pageTracker._trackPageview()' function call in the Google Tracking code. Is this where the request is sent to Google?

If so, should I just do:

window.setTimeout(pageTracker._trackPageview(), 5000);

any help is appreciated, especially if you have worked with Google Analytics and have this same problem.

A: 

That should do it. Put some quotes around the call:

window.setTimeout("pageTracker._trackPageview()", 5000);

You can check this using Firebug if you want to see the request go through.

Liam
quotes around a function call? are you sure?
Corey Goldberg
+1  A: 

window.setTimeout(pageTracker._trackPageview(), 5000); will call the code immediately - what you want is

window.setTimeout(function() { pageTracker._trackPageview(); }, 5000);

Greg
That is incorrect, the first parameter is the method to call, the second is the timeout value to wait for.
Mitchel Sellers
No, it's correct: window.setTimeout(pageTracker._trackPageview(), 5000); is the same as var foo = pageTracker._trackPageview(); window.setTimeout(foo, 5000);
Greg
A: 

This should work:

window.setTimeout(pageTracker._trackPageview, 5000);
Marko Dumic