How to Add a Google Analytics Tracking Code to Your WordPress Site

How to Add a Google Analytics Tracking Code to Your WordPress Site

Google Analytics is one of the best tools to monitor your website. Whether you run a blog or an advertising company, you may need to check the geographical area of your readers.

That’s how you can target your audience to get more leads. Most of the CRM companies are dependent on the data provided by Google Analytics.

But to enable it on your WordPress website, you need to add its tracking code. As you know, there are millions of sites running on the WordPress CMS, and not everyone is techie enough.

So they use plugins. But here, I don’t recommend using a plugin to add the tracking code. You should find an all in one plugin which can be used for other things too.

In this tutorial, you will learn the two different ways to add the Google Analytics Tracking Code to your WordPress website.

One will consist of the use of a plugin, and another will be a little bit techie. You have to edit the files of your WordPress theme.

Let’s Start With the Use of a Plugin

As you know, in the official WordPress Plugin’s repository, there are thousands of plugins and still growing.

More and more people are contributing to the open source. But the biggest problem is to choose the right plugin. When it comes to adding the tracking code, people search for a Google Analytics plugin.

Well, the smart way is to use a plugin which can be used to add any tracking code to your WordPress website.

If you use a plugin specifically for Google Analytics, that wouldn’t be a smart move. When you install Google Analytics, adding Hello Bar, Google AdSense, etc., you need to add their tracking code.

So, you can use Insert Headers and Footers plugin which was developed by the WPBeginner team. It’s a lightweight plugin which doesn’t slow down your WordPress website.

I hope you know how to install a WordPress plugin.

Once you do that, follow these steps.

Step 1

Go to Settings>>Insert Header and Footers and a new page will open to you.

Step 2

You will see two boxes. One is to add the code to the header area of the website and another one to add any code to the footer area.

To activate Google Analytics, you have to add it to the header area. So paste the code you have copied while submitting your website to Google Analytics to this box.

Click on the Save button and you’re good to go. Within a few hours, your website will be crawlable by Google Analytics and you will be able to monitor it.

This is one of the simplest methods. But as I have mentioned above, I am going to show you another method which doesn’t have the use of a plugin.

Add the Tracking Code Without Using Any Plugin

As I have mentioned, the code should be added to the header area. It means you require to edit the header section of your website which is controlled by the header.php file of your WordPress theme.

Do you know how to edit this?

If you don’t, let me tell you that you can use two different methods. The simplest way is to access it from your WordPress admin panel and that’s what you’re going to learn today. Another one is to edit it from cPanel.

Follow the steps.

Step 1

Go to Appearance>>Editor and once you open the page, you will see the CSS code by default.

Step 2

You have to find the Theme Header(header.php) file from the right-side menu. Open it.

Step 3

This is the most important step because now you have to choose the right place to add the code. You have to find the <body> tag.

The code will go just after that. Check the screenshot I have added. Once you add the code, click on the Update File button.

You have successfully added the Google Analytics tracking code to your WordPress website. Google takes some time to analyze the website.

To gather the proper data, you may need to wait for a week or more than that.

Which Method are You Going to Choose?

Now and then it’s said that you should use the less number of plugins because more plugins can slow down the website’s speed.

So now it’s up to you. Google Analytics can help you check the bounce rate of your website which can be helpful in improving the user experience.

You can filter some referral traffic to avoid getting penalized by Google. And of course, you can check if you are creating the informative content by monitoring the percentage of returning visitors.

So, are you going to use the plugin method or the coding method?

Conclusion

Every now and then it’s said that you should do the best you can to boost your online business. And it requires a monitoring tool.

Google Analytics is what you got right now. It’s free and easy to use. If you ask me, you should edit the header.php file to add the Google Analytics tracking code.

It’s a one-time task, you don’t need to touch it ever again.

Check out these top 3 WordPress hosting services:

A2 Hosting
$2.99 /mo
Starting price
Visit A2 Hosting
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.8
  • Pricing
    4.0
Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How to Install Google Analytics on Your WordPress Site

Want a better insight of your website stats? This is a step-by-step guide on ins
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to Add Google Tracking Code Using PHP in cPanel

This how-to walks you through a step by step process to add Google tracking code
3 min read
Arvind Singh
Arvind Singh
Hosting Expert

Google Tag Manager – How it Works

Article will cover the basics of Google Tag Manager including what its for and a
3 min read
Angela Olaru
Angela Olaru
Senior Writer & Hosting Expert

How to Secure Your WordPress Website

Millions of websites get hacked every year and many people consider WordPres
5 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top