0

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?

Baumr
  • 6,124
  • 14
  • 37
  • 63

1 Answers1

2

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.

Jason
  • 51,583
  • 38
  • 133
  • 185
  • 3
    The answer seems to refer to older versions of the tracking code, as this is not how the current GA code works. The code snippet that is implemented into the page creates a function that pushes values to a javascript object. The actual analytics script is loaded via js injection, asynchronously and non-blocking. For all practical purposes however Jason is correct (so +1 for "practically no"). It would be an extreme edge case where top vs. bottom of the head makes any difference (e.g. serving very large assets via very slow connections) and GA would be the least of your worries. – Eike Pierstorff Dec 10 '14 at 09:06
  • @EikePierstorff, great comment — you should make that into an answer so you can get credit :) – Baumr Jan 13 '16 at 17:11