How to Install Google Analytics Tracking Code Into Your Website? [2024]

| | April 12, 2024

Do you know how to install Google Analytics Tracking Code into your website and track your visitors interaction with your website?

The answer is Google Analytics.

After creating a new blog and making it live for your audience, it becomes important for you to track:

  • how your audiences are interacting with your website.
  • which pages your audiences are visiting the most,
  • what is the bounce rate of your site and pages,
  • average session duration,
  • landing pages and exit pages,
  • which devices they are using to access your site,
  • countries from which your visitors are coming to your blog
  • and many more stats.

And all these stats are provided by Google Analytics for free.

I have written this article for those bloggers or website owners who have just created their blog or website and wants to monitors their blog/site traffic but don't have any idea how to go about it.

In this article I will explain what is Google Analytics, how to install Google Analytics tracking code into your website and why it is extremely important to add it in your website.

I will also tell you what are the different methods to add Google Analytics to your WordPress website step by step.

Note: This article contains affiliate links. When you click an affiliate link and make a purchase, we get a small compensation at no cost to you. See our Privacy Policy and Disclaimer for more info.

What is Google Analytics?

Google Analytics is a web analytics service offered by Google that tracks and reports website traffic. It is the most widely used web analytics service on the web. 

Why You Should Use Google Analytics in Your Website?

Once you start your blog it becomes important for you to analyze your traffic. It helps you to target specific audience and convert your visitors into subscribers and your subscribers into customers.

Google Analytics help you make data-driven decisions by showing you important stats that matter to you most.

By adding google analytics to your website you can track your website traffic and users activity such as session duration, pages per session, bounce rate etc. along with the information on the source of the traffic.

It allows you to analyze what people do after landing on your website, how long they stay, what other pages of your website do they visit, etc.

Thus, to get success in your blogging career or your business website you must understand and study the behavior of your visitors to deliver better results.

Over 50 million websites around the world uses Google Analytics for a reason. So, if you are not using it on your website, you should set it up right now.

Adding Google Analytics just require you to add a tracking code to your website and your are good to go.

Let's see how to add the tracking code to your website in next section.

How To Create Google Analytics Tracking Code To Your Website?

Google Analytics is free to use. Sign up process is very easy to implement.


Follow the steps given below to learn how to create tracking code to your site.

1

First you are needed to create an account at Google Analytics. If you have a Gmail account you can easily login using the Gmail id. Visit Google Analytics here.

On the Google Analytics page, select Set Up for Free. Under Account details, enter your Account Name and select Next.


You can enter anything under Account Name that relates to your blog or business.

Create Google Analytics Account
Google Analytics Account Setup
2

Now you will presented with three options under, What do you want to measure?

The three options are Web, Apps and Apps + Web. Since we want to measure our website we will select Web. Now, select Next

Google Analytics Measure Website
3

Now you will have to enter your website details under Property Setup.

Under Website Name, enter your website name.

 

Under Website URL enter your blog's URL.

 

If your blog is secure i.e. you can open our blog with https then first select https://, then enter your blog URL.


Now, select Industry Category, Reporting Time Zone and finally select Create.

Add Website Details in Google Analytics

Accept the terms and conditions of Google. Now you have successfully added your website in Google Analytics.

In the next step you will be provided Tracking Code for your website.

Copy this tracking code as you will need to enter it in your WordPress website depending on the method you use below.

Tracking Code Google Analytics

How to Install Google Analytics in WordPress

You can setup Google Analytics in your WordPress website in two different ways. Let see these two methods one by one.

Choose the one method that best suits your needs.

1. Install Google Analytics Using MonsterInsights

With over 2,000,000+ active install, MonsterInsights is the most powerful and user-friendly WordPress plugin to add Google Analytics to your blog.

It is the easiest method to add Google Analytics to your WordPress blog or website.

To add Google Analytics to your site you first need to install MonsterInsights plugin. Download the plugin from here.

MonsterInsights Analytics Plugin

After downloading the plugin, install and active it inside your WordPress Dashboard. If you need help installing plugins on your site, check out our WordPress plugin installation guide.

Install MonsterInsights Plugin

After activation, it will take you to the MonsterInsights HomeScreen. Here, select Launch the Wizard option.

In case, you are not able to see the setup wizard, go to a new menu item labeled Insights to your WordPress admin menu.

Clicking on it to launch the MonsterInsights setup wizard.

You will be asked to choose a category for your website. Choose anyone between Business Website, Publisher (Blog), or Ecommerce. Select any one and then click on Save and Continue button.

MonsterInsights Onboarding Wizard

Now you will be asked to select Connect MonsterInsights button.

Connect MonsterInsights

A popup will be displayed asking you to sign in or select a Google account if you are already signed in.

Sign in with Google - MonsterInsights

Now, MonsterInsights will ask for permission to access your Google Analytics account.

MonsterInsights Google Analytics Permission

Select Allow button to continue.

Now you will be taken to the final step. Here, select your website and click on Complete Connection button to continue.

Now, MonsterInsights will install Google Analytics on your website and ask you to select the recommended settings for your website.

MonsterInsights Recommended Settings

In this step, you can go with the default setting but if you need some additional tracking feature such as Affiliate Link Tracking you can make the changes here. Just add the path you use to cloak affiliate links. This will allow you to track all your affiliate links in Google Analytics.

Click on Save and continue.

Now MonsterInsights will show you some add-ons. But you need to upgrade to Pro plan to access these add-ons.

To skip this step you can simple click on the Save and Continue button.

MonsterInsights Add Ons

Now in the next step, you will be asked to install WPForms plugin, which is one of the best WordPress contact form plugin.

Install it or simply click on Skip this Step.

MonsterInsights WP Forms

Select Finish Setup & Exit Wizard. That's it. Google Analytics is now successfully installed in your WordPress website.

MonsterInsights Finish Setup

One of the best feature of MonsterInsights is that it allows you to view your Google Analytics reports right inside your WordPress Dashboard.

To view your website traffic stats just head over to Insights >> Report.

Under this section you will get access to the following statistics:

  • Sessions
  • Pageviews
  • Average Session Duration
  • Bounce Rate
  • New vs. Returning Visitors
  • Device Breakdown
  • Top 10 Countries
  • Top 10 Referrals
  • Top Posts/Pages

2. Install Google Analytics using Header & Footer Plugin

In this method, you need to install and activate Header and Footer plugin.

Please keep in mind that in this method you won't be able to track your website analytics inside the WordPress Dashboard.

We will just add the Google Analytics tracking code in the header section provided the Header and Footer plugin.

To see your website stats you would need to login to Google Analytics.

Let's see how to add the tracking code.

In the WordPress Dashboard, go to Plugins >> Add New

Now add Header and Footer as the keyword. Install and activate the plugin as shown in the image below.

Header and Footer Plugin

After activation, go to Settings >> Insert Headers and Footers

Now add the Google Analytics tracking code in the Header section and click on Save.

That's it. Google Analytics is now successfully installed in your WordPress website.

Add Google Analytics Tracking Code

3. Add The Tracking Code In The header.php File

This is an advanced option. It is recommended that if you are not sure what you are doing then don't proceed with this method or ask your developer to perform this step.

It is also recommended to perform this step in a child theme. This way even if you update the main theme you won't lost the code.

In this method we will add the tracking code to your website by inserting the code into the website's header. This method is similar to the previous one but we will not use any plugin this time.

Adding tracking code in the header ensures that the code will work across each and every page of your website.

Under WordPress Dashboard, go to Appearance >> Theme Editor >> header.php

Now add the tracking code from Google Analytics into it right before the closing </head> bracket.

Add Tracking Code in Header File

4. Add The Tracking Code In The functions.php File

This is exactly similar to the method explained above. It is again recommended that if you are not sure what you are doing then don't proceed with this method.

Again it advised to perform this step in a child theme.

In this method we will add the tracking code to your website by inserting the code into functions.php instead of header.php.

Adding tracking code by this method also ensures that the tracking code will be added to every page on your WordPress site.

Under WordPress Dashboard, go to Appearance >> Theme Editor >> functions.php

Add the tracking code inside it and select Update File.

Google Analytics tracking code is now successfully added in your website.

Note: Before making any changes to header.php or functions.php please take a backup of the files.

Conclusion

After successfully adding the tracking code to your website, Google will soon start monitoring and analyzing your website's traffic.

Also Read: Add Google Analytics to GeneratePress

The tracking code records various activities of your users when they visit your website, along with the attributes such as age, gender, interests, devices, cities & countries, etc. of those users.

It then sends all that information to the GA (Google Analytics) server once the user exits your website and you get access to all the stats.

I hope that now you know the importance of Google Analytics and how to install Google Analytics tracking code into your website to analyze your traffic stats.

Google Analytics is great free tool to analyze your website traffic. It provides plethora of information and is used by almost all website owners who wants to track their visitors.

It can do wonders for your blog or business website. It provides you with valuable insights that can be used to improve the performance of your website and increase conversions. 

So, if you have not yet tried this free tool from Google, sign up today and start tracking your website traffic.

If you have any questions or suggestions please comment below.

Sharing is Caring! If you like this article, please share it now.

You can also use QR code on tracking your blog's contents. Read How To Track Your QR Codes In Google Analytics

Photo of author

Deepak Choudhary

Deepak Choudhary is the founder of Technicalwall.com. He is a Blogger and an Affiliate Marketing Expert. He publishes useful articles for newbie bloggers related to the following topics - Affiliate Marketing, Email Marketing, Software Reviews, Software Tutorials, Blogging, WordPress, SEO, Passive Income, and more.