Want to know where should you put your Google Analytics code?
While it’s safe to put your code in the header or footer, Google recommends you to add your code to your WordPress header.
But how can you add the code without the need to hire a developer?
In this article, we’ll explain should you put Google Analytics code in the WordPress header or footer?
Let’s start with…
The Benefits of Adding Analytics Code into Header
This is why Google recommends you add your tracking code in the header of your site. It helps you to accurately record traffic stats because your header scripts are loaded earlier than any other scripts on your page.
Besides, the tracking code loads on your site asynchronously, meaning other scripts can also load simultaneously. For that reason, adding your tracking code into your header doesn’t reduce the page speed or impact your WordPress site performance.
Now, are you ready to learn how to add the tracking code in your website’s header?
How to Add Your Google Analytics Code into Header
There are many ways to add your Google Analytics code snippet to your WordPress site. First, you can use a WordPress plugin like MonsterInsights to add the tracking code without editing code or hiring a developer.
Or you can manually enter the code to your website. This method isn’t recommended as it requires going through your website’s code. And if you make any mistake while entering the code, it could have adverse effects on your site’s performance.
That being said, let’s look at both methods.
Method 1: Use MonsterInsights to Add Google Analytics Code
The easiest way is to set up your Google Analytics with your WordPress site using the MonsterInsights plugin.
MonsterInsights makes it easy to add your tracking code into your WordPress header without even touching the code. All you have to do is install the plugin on your site, and it will take care of the rest.
Once the plugin is active, follow the setup wizard, and you’ll have Google Analytics tracking code in your site’s header in no time.
Another benefit of using a WordPress plugin is that if you decide to update your WordPress theme in the future, you won’t have to reenter the Google Analytics tracking code.
You can follow our detailed step-by-step instructions on how to properly add Google Analytics to WordPress.
After setting up Google Analytics, you can see all your important stats insides your WordPress admin area. MonsterInsights dashboard reports make it very easy to spot the data you need without having to leave your site.
Method 2: Manually Add Google Analytics Code to Header
The next method for adding Google Analytics tracking code to your website’s header is without using a WordPress plugin.
This method is tricky, and we don’t recommend it for beginners. That’s because it can be tricky to add code, and any mistake can mess up tracking. Besides that, you’ll have to enter the tracking code every time you change your website theme.
That said, to manually enter the tracking script, the first thing you need to do is copy the code from Google Analytics. You can find the code by going to admin settings and navigate to Tracking Info » Tracking Code.
After that, go to your WordPress website admin area and then navigate to Appearance » Theme Editor. Next, click the Theme Header (header.php) option under Theme Files.
Now paste the Google Analytics tracking script you copied earlier before the </head> tag and click the Update File button.
And that’s it!
You’ve now manually entered the tracking code to the header of your website. Google Analytics will now start tracking your visitors and show you reports to see how they interact with your site.
We hope you liked our guide on should you put Google Analytics code in the WordPress header or footer. If you found this helpful, do check out our post on how to track link clicks in WordPress.