Does placing Google Analytics tracking code higher in the <head> increase accuracy?

91 views Asked by At

Does including the Google Analytics (GA) tracking code before anything else (including meta elements and other JavaScript files) at the top of the <head> (as opposed to just before the closing </head> tag as recommended by Google) ensure that all users who bounce will be reported in GA?

In other words, if the GA tracking code is included at the bottom of the HTML document's head, can some users be not tracked (as bounced) if the browser doesn't manage to load everything in the head before they close their browser/tab or hit the back button?

1

There are 1 answers

2
Jason On

Technically yes, but practically no. The user would have to be on the world's slowest connection (or be the fastest browser closer) to escape a tracking event by Google Analytics code placed at the bottom of <head> vs. the top. However, placing it above other linked files such as stylesheets and other JS (which should go at the bottom of your page) will increase the chances of firing a tracking event before the user leaves. But, think of your users. Let your stylesheet load before your tracking code so that your site doesn't look like crap for a split second while your tracking code is loading.