How To Integrate Google Analytics to Your WordPress website ( Step By Step Guide)

In this article, we will learn how to add Google Analytics to your WordPress website, as it is very important for any live website.

After launching your website, you may be curious to know who is visiting your website, What they do on your website, where they came from, How much time they are spending, How do they respond to your content, and much more.

This is where Google Analytics comes in to answer all your above questions. You can use this information to optimize your website and its content to bring more traffic.

So let’s begin..

Sign Up For Google Analytics 

Step 1: To integrate Google Analytics into our website, we first need to sign up using this URL

If you already have a Google account, just use it to sign-in or If not, click on Create account to sign up.

Step 2: Once you sign-in with your Google account, you will be presented with a screen like the one shown below.

Now we are ready to create a Google Analytics account using our Google account. Simply click on the Set up for free button, and you’ll get a screen like the one shown below.

Here you will be asked to provide an account name. It can be anything like your business name or whatever you like. Leave rest options as it is and click on the Next.

Step 3: On the Next Screen, you will get three options – Web, Apps, and Apps and web. Select Web as we are configuring a website.

 Now click on the Next, A new screen asking about your Website Name, Website URL, Category, and Time Zone will be shown.

Fill in the required information and click on the Create button. Next, Accept the Google Analytics terms and service by clicking on the I Agree button to use their services.

Step 4:  Finally, you will be presented with a Google Analytics tracking code. This is the code we are going to place on our WordPress website.

You can copy this code or it’s better to leave this browser tab open so you can switch back to copy the code when it needed. In the next section, we will show you three different methods to place the tracking code on your WordPress website.

How To Add Google Analytics Code to WordPress

So far, you have completed the half task by generating the Google Analytics code. Now the remaining half task is to put this code in your WordPress website. Once you place the code successfully, you can start tracking your visitor.

There are many ways to add Google Analytics to your website. But we have picked a few methods and explained each in detail. You can choose any one of these methods that you find easy to implement. 

1. Using WordPress Theme Option 

Almost all premium themes come with an option to add header and footer script. So you can use this option to add Google Analytics code to your website.

To do this, login to the WordPress admin dashboard and head over to the theme setting option, look for the option to add header script and paste the GA tracking code.

For example, in my case I found the header script section by heading over to Dashboard > XYZ (theme name) > theme options > General > Custom codes > Header code. Depending on your theme, the path may change, but it should be there somewhere under the theme setting options.

This method is the easiest one, and you accomplished your task without using any plugin. If your theme does not have this header script section by default, you can still add the GA code using other methods mentioned below.

2. Using Google Analytics WordPress plugin

There are many Google Analytics plugins available in the directory. But we are going to use Google Analytics for WordPress by MonsterInsights plugin.

With over 2 million active installs, MonsterInsights has become the most popular Google Analytics plugin for WordPress.  It’s very easy to use and offers some great features. 

Let’s begin

First thing first, Install the plugin by heading over to Plugins > Add New and search for it. Now install it and activate it after the installation is completed.

Once Activated, You will also get an Insights option in your WordPress admin menu. Now go to Insights > Settings and click on Connect MonsterInsights under the Google Authentication section.

This will redirect you to the Google Analytics home page where you will be asked to sign in or if you are already logged in, you will be asked to select an account that you want to use for tracking. Here make sure you use the same Google account that has been used for creating a Google Analytics account.

Once you have logged in, you will be asked to allow the MonsterInsights plugin to access your Google Analytics account data.

Make sure you allow it as this is necessary for the plugin to work. 

On the next screen, you will be asked to select the profile you want to track. Here you need to select your website and finally click on the Complete Connection button.

 You will be directed back to your website. That’s it you have successfully integrated Google Analytics to your website.

MonsterInsights also offers one more way to add Google Analytics to your website. This is a manual method, and for this you have to enter your tracking UA code manually. So copy your Google Analytics Tracking ID first.

Go to Insights > Settings and now look for manually enter the UA code under the Google Authentication section of the plugin.

Click on it and paste the UA code (Tracking id)  you have copied from your Google Analytics account.

 Don’t forget to save your changes.

That’s it done. The manual method has one drawback that you will not be able to see the MonsterInsights reports inside your WordPress dashboard,  but you can always see it in your Google Analytics account. 

3. Using Insert Header and Footers Plugin

This plugin lets you insert the Google Analytics tracking code into your theme’s header and footer area. Install and activate the Insert Headers and Footers plugin. Once activated, go to Settings > Insert Headers and Footers option. 

Here you need to paste your Google Analytics Tracking code that you copied earlier in Step 4, into the Head section as shown in the image above, and then click on save changes.

That’s it, you have successfully integrated Google Analytics to your WordPress website. Now you can track your website users by simply login into your Google Analytics account.

4. Insert manually into the theme’s file 

In this method, we are going to edit your theme’s files to insert the tracking code. However, making any changes directly to your main theme files is not recommended. If you do, they will get lost when you update your main theme.

So the best way is to do it in a child theme. A child theme is best for editing any files, all the premium themes come with a child theme if you don’t have one, you can always create it manually. 

Now we are ready to insert the tracking code into the theme’s file, and we can do this in two ways. You can choose either one of them. Don’t choose both.

1. Insert into the header.php file 

I hope you have created the child theme successfully, now simply copy the header.php file from the main theme into your child theme folder and start editing it. And then paste the tracking code, you copied earlier from Google Analytics, right before the closing  </head> tag.

That’s it, now save and upload the file back to your server.

2. Insert into the function.php file 

As we did above, similarly copy the function.php file from the main theme folder into your child theme folder and start editing it. And add the following piece of code to your theme’s function.php file.

add_action('wp_head', 'ga_add_googleanalytics');
function ga_add_googleanalytics() { ?>
Paste your Google Analytics tracking code here
<?php } ?>

Save and upload. 

Basics of using Google Analytics Website 

Google Analytics is the most versatile tool to track almost all activities of your visitors on your website. As soon as you log in to your Google Analytics account, you will see a home page screen like this.

On the right-hand side, your website statistics will be displayed while on the left you have several options as shown in the picture. The most important part here is the reports section where we are going to spend most of the time.  Each section under reports contains other submenus and you can access them by clicking on a particular section.

Lets see different section function under reports section :

  • Real-Time: As the name suggests, It shows the real-time movement of your website visitors. With this option, you can track how many visitors are currently on your website, what they are doing, where they came from, how much time they are spending, what devices they are using to visit your website, and much more. 
  • Audience: This helps you to understand your audience better. Reports generated here show the numbers of visitors over a time period, how much time on average, they spend on your website and more.
  • Acquisition : Shows you the sources of your traffic.
  • Behavior: Summary reports of what visitors do on your website after arrival.
  • Conversion: The report shows how well you are performing against the goals that you have set up inside Google Analytics.

Google Analytics works best with Google Search Console. It shows you how well your website is performing in the search results. It also helps you in fixing website issues. We have written a dedicated article on How to Configure Google Search Console  For Your Website

I hope this article helped you to Integrate Google Analytics to your WordPress website successfully. If you have any queries, please do mention it in the comment box.

Pankaj Kumar

Passionate Blogger With Over 8 Years Of Experience In Blogging and Web Development Field.

Leave a Reply

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

Back to top button