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?
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.
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.
The script that triggers/sends the tracking events to Google Analytics must be loaded once (and only once) on every page of your site.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With