About cookies on this site

We use cookies to collect and analyse information on site performance and usage, to provide social media features and to enhance and customise content and advertisements. Learn more

Cookie settings

About cookies on this site

Cookies used on the site are categorized and below you can read about each category and allow or deny some or all of them. Learn more

Necessary

Some cookies are required to provide core functionality. The website won't function properly without these cookies and they are enabled by default and cannot be disabled.

Preferences

Preference cookies enables the web site to remember information to customize how the web site looks or behaves for each user. This may include storing selected currency, region, language or color theme.

Analytical cookies

Analytical cookies help us improve our website by collecting and reporting information on its usage.

Marketing cookies

Marketing cookies are used to track visitors across websites to allow publishers to display relevant and engaging advertisements. By enabling marketing cookies, you grant permission for personalized advertising across various platforms.

  • Courses
    • Paid courses
    • Course bundles
    • Free courses
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login
  • Courses
    • Paid courses
    • Course bundles
    • Free courses
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login

google analytics header or footer

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.

 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey.Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Content Groups in Google Analytics 4
  • 3 Ways to Pull Data from Data Layer with Google Tag Manager
  • 13 Reasons Why a Tag in Google Tag Manager is Not Firing (or Fires When it Shouldn’t)
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings