Easy question for me! Load Google Analytics in the footer!
- Because I want the best performance possible. I don’t want GA script to slow down initial rendering for things that actually appear on the screen!
- Because your site shouldn’t be loading that slow anyway between header vs footer items. If your site IS that slow, you need to fix it first before slowing it down even further.
- Because GA stats are nice but I don’t look at them THAT much. The most important thing is user experience.
Is there ever an argument for when to put GA scripts in the header?
Sure, there are some. The main one being that having the Analytics script load sooner will ensure that your users are tracked more accurately. The idea is that you don’t want to miss out on what user actions are happening before the script is loaded. There’s also the argument that loading the GA script later may increase your bounce rates because it’ll seem like your users are leaving your site faster.
For the most part, I think all the excuses are bunk. It should only be a 100-200ms difference between loading the GA script in the header vs the footer. If your visitor can decide to leave your site within that time, then was that really even a worthwhile interaction to track in the first place?
There’s also the argument that the GA script is asynchronous and doesn’t block page-render and that the script will load alongside all other JS scripts. That may be so but the still has to be read and processed and who knows what else is going on. I also like what the PagePipe guys had to say on the matter.
Don’t be silly. Load GA in the footer and get on with your life. Serve your users, not Google!
- Which plugin to load Google Analytics? I use CAOS plugin – it saves and serves the file locally from your web-server to decrease external requests from dragging down your pageload.