Where to Put Google Analytics Tracking Code: Header or Footer?

Screen of website codingWhether you’re setting up Google Analytics for the first time, just jogging your memory or auditing a current website, making sure your Google Analytics tracking code is in the right place is the first step to accurate tracking.

Should the tracking code go into the header or footer?

To quote Google’s guidance:

“Once you have the Javascript tracking code snippet for your property, copy the snippet exactly without editing it.

Paste your tracking code snippet (unaltered, in its entirety) before the closing </head> tag on every web page on your site you wish to track.”

According to Google you should put your tracking code in the header.

Do I have to put it in the header?

In a word, no.

Your Google Analytics tracking code will work anywhere on the page. The reason why it’s recommended that you add it within your <head> section is so it gets executed early in the loading of your page. This *should* lead to more accurate data collection.

If someone lands on your page and navigates to another page before the page has fully loaded and your Google Analytics code hasn’t executed yet, Google Analytics won’t be able to accurately track where this person landed as it will never have received the signal from that first page.

It’s as simple as: the higher on the page you put the tag, the more likely it is to fire before the user moves on to somewhere else than if you had it lower down the page.

Will the Google Analytics code make my page load slower?

Not really. Or at least it’s not supposed to.

We know that fast loading pages are essential. We all expect easy to access, click-of-a-button content and we know Google uses it as a ranking factor so it’s natural to be worried about this.

The Google Analytics tracking code is asynchronous so it won’t slow or block the loading of any content later in the page.

So why all the confusion?

Before Google had an asynchronous tracking code (pre-2009), it could have slowed down the loading of your page. With the older, less streamlined tracking codes Google recommended adding them lower down the page (after the opening <body> tag) for this exact reason.

With the updated tracking codes, it is no longer necessary to place the code lower down your page.

But I know my Google Analytics code is slowing down my site

If you’ve seen a ‘waiting for google-analytics.com’ message or you’ve seen that your tracking code is slowing down your website, try some of the following:

  • Double-check your tracking code – is it the most recent version?
  • Use a pageload tool to pinpoint what’s slowing your load speeds
  • Move the tracking code further down the page – is it still having an effect?
  • Try improving the optimisation of the other assets on the page – images, css or anything that’s showing in your pageload breakdown report

Have you had problems with your Google Analytics tracking code? Looking for advice or want to share a solution – please share below!

Where to Put Google Analytics Tracking Code: Header or Footer?

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep updated

Get all the latest digital marketing tips, guides and news straight to your inbox