Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'd like to go to the asynchronous Google Analytics script, but I'd rather not have it in the head (even though I know this is best practice).

So, is there any benefit of using the async code if it isn't in the head, and alternatively, would it be safe to place elsewhere high in the page, like just inside the opening body tag, or in a .NET user control that loads at the top of the page?

EDIT:

In the instructions Google states:

If that isn't an option, you can still put the asynchronous snippet at the bottom of the page. You can also split your snippet to retain some of the benefits of asynchronous tracking.

If I place the code there (without splitting) do I still benefit from asynchronous loading or is it negligible since it is at the bottom anyway?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Compared to having the old tracking code at the bottom of the page, having the asynchronous code at the top of the <body> should still mean that the tracking is more likely to register users who leave the page (or interact with elements on the page that are being tracked) before it has fully loaded.

share|improve this answer

You can put it anywhere you just get the most benefit from putting it in the header. The full instruction to add it to your web page are here - http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html.

You do want to put it inside of the head or body tags though. Just to be clear. But beyond that you can do whatever you want.

share|improve this answer
    
The instructions also say you can put the async code at the bottom of the page. Would that have any benefit over the old code? –  Jim Jul 12 '10 at 15:28
    
Google imply that you can put the code pretty much anywhere but that for most pages the optimal place is at the bottom of the <head> (code.google.com/apis/analytics/docs/tracking/asyncTracking.html) –  pelms Jul 12 '10 at 15:37
    
@pelms, that is my worry, it is implied, but no explicit alternate placing (besides the bottom where the old code is) is stated. –  Jim Jul 12 '10 at 15:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.