Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google analytics in header or footer?

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?

like image 830
tyler Avatar asked May 23 '12 03:05

tyler


People also ask

Can I put Google Analytics in footer?

You can. The only difference is that if you put in the "footer" (i.e. just before the </body> tag), the browser will first load the DOM (i.e. everything up to the script tag) and then start to load the script.

Where do I put the Google Analytics code in my header?

Probably the quickest and easiest way to do it, it requires a simple code edit. Just go to Appearance > Editor > header. php and add your Google Analytics code right before the ending </head> tag or after the opening <body> tag.

Does Google Analytics code needs to be on every page?

The script that triggers/sends the tracking events to Google Analytics must be loaded once (and only once) on every page of your site.


1 Answers

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.

like image 179
John Conde Avatar answered Sep 18 '22 17:09

John Conde