Google Analytics code: Header or Footer?
The official Google Analytics GTAG documentation states that in order to install it you need to place the code somewhere in the website’s <head> of the website.
But what should you do if a performance-obsessed developer does not agree to follow these instructions? What if a developer insists on adding GTAG at the end of the <body> (a.k.a. in footer)? Or maybe your content management system does not allow you to place the code in the <head>?
In general, it will work fine. The only thing that is affected is the time when it will load. The higher the GTAG code is placed in the page source code, the sooner it will load, and obviously, the sooner your tracking implementation will be activated.
So if the circumstances do not allow you to follow Google’s recommendations, don’t panic. You’ll still be able to use Google Analytics. Even if it is somewhere in the body (e.g. at the end of it).
Unfortunately, I cannot give you numbers of how many visitors can you possibly miss in your analytics reports under these circumstances. There are too many variables and conditions that affect this. IT DEPENDS.
Google Analytics in Header or Footer: Summary.
Even if GTAG is added to the body of the website, it will still work fine.
However, it is better if you add the <script> code to the head. It means that Google Analytics will start loading sooner and your website measurement setup will be more accurate.
The same applies to tracking codes implemented via Google Tag Manager.
But, on the other hand, having tracking codes load as soon as possible can affect the page loading speed. But there are other options for how to mitigate this with Google Tag Manager.