Google advice that the analystics code should be positioned before the . Supposedly it has to do with aquiring more accurate data (as the script becomes available faster), both for pageviews and duration of visit.
Should we comply with this?
The advantage to placing it in the head is that you will track a users' pageview even if they leave the page before it has been fully loaded.
To me, I wouldn't want that counting as a page view.
I can imagine some cases where very customized analytics is in place and I want that level of control and visibility. But I don't think this is the 80% case.
added to documentation ticket.
I have recently had a few sites "unverificate" due to the analytics not being correctly positioned in the page.
I feel the amount of time between the loading of a page from head to foot (and thus positioning the analytics code at the bottom for more accurate tracking) is rather negligible. If that sort of discrepancy is worry, I would think a better solution to be implementing some sort of "engaged" views tracking, such as tracking an event on a page load.
I definitely think the analytics code positioning should be re evaluated based on their guideline and in the light of sites having there verification status obstructed because of it.
This also can effect the linking of webmaster and analytics accounts.
what's "unverificate" ?
Is this a google analytics thing? where can i find out more about it?
"Unverificate"/"deverify". This happened to a site I had in which I had a Google webmaster tools profile linked to the analytics profile. I think they were linked via GA code, however at some point Google told me the verification was invalid and the solution was to move the code to the head tag as outlined in the asyncTracking best practice. I will attempt to get the message I got again and screen cap it for you if you'd like.
They advocate a Split Snippet in their documentation, in which they simply initialize an array in the head. If doing this is okay, then putting the entire thing at the bottom of the page should be fine as long as the _gaq array (with options) is initialized before any of the ga code.
For the record, I'm in favor of keeping the code where it is for the same reason that @paulirish mentioned above, barring any account verification issues.
This is the error message received when trying to verify a site using GA in which the async snippet is not in the head. There is of course the work around of using one of the many other verification methods, however I think that the code should be where it google says it should be.. The snippet is async now anyway. At the very least, something added to the documentation about this.