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

Note: If you're looking for information specific to Google Analytics 4 tracking code placement, refer to this article. 

If you’ve landed here, you’re probably all set to dive into analysis with Google Analytics! But before you get to all that juicy data, you need Analytics to start collecting information.

Embedding your Google Analytics tracking code onto your website pages is how you get Analytics to start tracking your traffic and following your users’ journey through your site.

So where do you put your Google Analytics tracking code?

If you’re using Universal Analytics, you should place the tracking code into the header of each page. This will ensure the most accurate tracking. 

Today we’re going to discuss embedding your tracking code with Universal Analytics. Things are a bit different in the most recent version of GA, Google Analytics 4, which we’ll discuss in a future article. But for all you UA users, come with us to learn more about why it’s important to use your tracking code in the header of all your website pages.

About Google Analytics Tracking Codes

First, let’s talk about what exactly the Google Analytics tracking code is so we can understand where to put it.

Your GA tracking code is a JavaScript code embedded into your website pages. It automatically tracks page views as users move through your site. The JavaScript code being used in current versions of Analytics, including Universal Analytics and Google Analytics 4, is asynchronous code, so it loads instantly and shouldn’t cause any delays. All Analytics codes generated after 2009 are asynchronous. Before 2009, this wasn’t the case, but as long as you’ve set up your Analytics account within the past decade, you’re in the clear.

Additionally, now that you can link Analytics to Google Search Console, your users’ entire search pattern can also be tracked, including keywords and their impressions. Google’s asynchronous code has been proven to fetch more accurate results than the previous version, and it shouldn’t interfere with your page loads either.

Now, let’s discuss where Google says you should place your code on your website to get Analytics to start tracking.

What Does Google Recommend?

Back before the asynchronous JavaScript code, Google recommended you place your GA tracking code in the footer. But with the asynchronous, post-2009 code, Google’s official recommendation is to put the tracking code after the <head> tag in your header. This is the case whether your header is static or dynamic.

Now, let’s discuss why Google makes that recommendation and why you’ll probably want to take their advice.

The Benefits of Putting GA Code in Your Header

There are a few exceptions, but for the most part, you’ll always want to put your GA tracking code immediately after the <head> tag in the header of each page of your site.

If you put the code in the footer, especially if you run other scripts on your site, Analytics might not track your users accurately. This happens because the scripts are triggered in the order they’re embedded on your page. So, if you put your Analytics tracking code in the footer, the prior scripts could prevent it from running. This can lead to a lot of issues when it comes to your data collection, so it’s not the best way to get accurate results.

By putting your GA tracking code in your header, you’re prompting it to load before the rest of the scripts on your site. This way, you’ll get the most precise data about your traffic and user behavior.

This is the main reason why Google recommends putting your tracking code in the header, but by making the GA tracking code asynchronous, note that the code loads simultaneously with the other scripts on your site. This means it shouldn’t slow down your page speed or impact your site performance.

But even though your page speed shouldn’t be affected, questions about site performance while running the GA tracking code still come up quite often, so let’s explore that in our next section.

Will The Tracking Code Make My Site Load Slower?

One of the most popular questions about embedding the GA JavaScript is whether it will impact your site speed. The answer is that it shouldn’t as long as you’re running the asynchronous version of the code (post-2009).

If you’ve installed your Analytics tracking code and are experiencing site slowness or other performance issues, here are a few things to check:

  • First, make sure your tracking code is the most recent version, post-2009.
  • Try moving your tracking code further down the page to troubleshoot if it’s really the issue.
  • Other things are probably slowing down your site, so try optimizing your images and videos, or anything else that could potentially slow the page load.
  • You can also use a page load tool to see what’s slowing down your site. Google has an excellent one available called PageSpeed.

Where to Find Your GA Tracking Code

Okay, so now that we’ve discussed the GA tracking code and how it works, let’s talk about where to find your tracking code.

To find your tracking code in Universal Analytics, follow these steps:

1. Click “Admin” in the bottom left corner.

2. Under “Property,” click “Tracking info.”

3. Then click “Tracking code.”

You’ll see your tracking ID and global site tag displayed on the right. Copy the entire global site tag to paste into your webpage headers.

When it comes to embedding your tracking code onto your web pages, you’ll need to be extremely careful. Any tiny mistake could cause a major issue for your data collection.

It’s recommended that you defer to a developer to help you embed your code if you’re not familiar with editing HTML. For assistance adding your tracking code, you can refer to Google’s official documentation seen here.

Google Analytics Tracking Code

Embedding your GA tracking code into the header of each web page you want to track is the first step to Analytics data collection. You’ll need to be very precise about embedding this code, as any little error can cause major issues.

It’s always recommended you default to someone with expertise if you’re not comfortable editing HTML. And remember that if you’re using Google Analytics 4, things have changed, so stay tuned for more updates.

Have you run into any trouble when embedding your Analytics tracking code? Let us know!

Leave a Comment

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

Show Buttons
Hide Buttons
Scroll to Top