Google analytics in header or footer?

styler1972 picture styler1972 · May 23, 2012 · Viewed 67.1k times · Source

My questions is, do you put Google Analytics Javascript code in the header or at the very bottom of the page (before </body>). I've heard people say it's best to put Google Analytics Javascript code at the very end of your html. Others say its best to put it in the header. Is there a best practice?

Answer

John Conde picture John Conde · May 23, 2012

Put it in your header. It's asynchronous so it won't block your page from loading and by placing it in your header you'll be more likely to get a accurate stats.