How to Add Google Analytics to Wordpress

How to Add Google Analytics to Wordpress

Jun 02, 2023

How to Add Google Analytics to Wordpress

Are you searching on how to add google analytics to WordPress website? Once your site is running, you want to know how many visitors visiting your website. Knowing your site traffic helps you in many ways. You can also check what peoples do when they are on your website. Even you can check how people find your website and when they are visiting your website. You can track all these details by using Google analytics for free. The easiest way is to use a WordPress plugin.

What is Google Analytics?


Google Analytics is a free website tracking service that tells website traffic, conversions, user behavior and more. You can check how many visitors visit your website and how they find your website. Also when they are coming to your website. So overall you can check the performance and effectiveness of your website. This helps you to find out the strength or weakness of your website. The more important is the tool is completely free. So you don’t need to pay for knowing your website traffic. It creates customizable reports on a real-time basis. We can use a plugin to install google analytics on your WordPress website.


In this article, we discuss how we can add Google Analytics to your website by using a free plugin.

  • First, you need to create a Google Analytics account. To do this visit Google Analytics Signup page. You will be prompted to Google sign in page. Login to your Google account. If you don’t have to create a Google account.
  • add google analytics to wordpress
  • Once you sign-in you will be prompted for a window shown below. Here you can sign up for Google Analytics to your Gmail account.
  • add google analytics to wordpress
  • On next window, you have options to choose between Website and Mobile app. Don’t forget to choose Website option.
  • add google analytics to wordpress
  • Next, you have to fill out details of your website.
  • add google analytics to wordpress
  • Then click on Get Tracking ID button is given below to get the unique ID.
  • add google analytics to wordpress
  • [wp_ad_camp_1]
  • A popup opens and you have to select your Country and then click on I Accept button.
  • add google analytics to wordpress
  • You will be presented with a new window. Here you can see the Tracking code. Copy the code because you have to enter this code on your website.
  • add google analytics to wordpress

Don’t close the browser tab because you may need to revisit it.

How to install Google Analytics on WordPress


There are many ways to setup Google Analytics. We will show you three different methods to setup Google Analytics.

1. Using MonsterInsights Plugin

MonsterInsights is a very popular plugin for setting up Google Analytics on your WordPress website. It is the easiest way to setup Google Analytics.

  • First thing is, you have to install and activate MonsterInsights plugin. To know how to install and activate a plugin read our previous article.
  • add google analytics to wordpress
  • You will notice Insights option in the left sidebar. Hover over it and then click on Settings option under it.
  • add google analytics to wordpress
  • A new window opens and you have to click on Authenticate with your Google account button.
  • add google analytics to wordpress
  • This will bring a popup. Click on Next button.
  • add google analytics to wordpress
  • It will again bring a popup. Click on Click to Get Code button.
  • add google analytics to wordpress
  • This will bring up another popup with the message ‘MonsterInsights would like access to your Google Analytics data’. Click on Allow button to continue.
  • add google analytics to wordpress
  • It will bring a popup with a line of code. Copy the code.
  • add google analytics to wordpress
  • Paste this code in Monsterinsights popup which is already open and click on Next button.
  • add google analytics to wordpress
  • Finally, select your profile which you want to track from the drop-down and click on Next button.
  • add google analytics to wordpress

Close the popup. Remember it will take some time to show your status or reports.

Visit Reports under Insights given in left sidebar to see the reports.

add google analytics to wordpress

2. Using Insert Headers and Footers Plugin

The second method is you have to install Insert Headers and Footers plugin.

add google analytics to wordpress

To know how to install and activate a plugin read our previous article.

  • After you activate the plugin hover on Settings option given in the left sidebar and click on Insert Headers and Footers option.
  • add google analytics to wordpress
  • [wp_ad_camp_2]
  • A new window opens and here you need to paste the Google Analytics code that you copied in step 7(where we tell don’t close the browser) into the headers section.
  • add google analytics to wordpress
  • Click on Save button to save your changes.
  • add google analytics to wordpress
3. Install Google Analytics in WordPress Theme

This method is for those who are familiar with the code. This is not a good method because if you switch the theme your code will disappear. But if you are using the same theme you can use this method.

  • Create a child theme of your theme you are using. To know how to create a child theme read our previous article.
  • Download the header.php and functions.php file from your parent theme folder using FTP and paste these file in your child theme folder in the same location in which they are located in the parent theme folder.
  • Open the header.php file in any editor and paste the code you copied in step 7(where we tell don’t close the browser) right after the tag.
  • Save the file and upload to the server.

You can also add the code you copied earlier in functions.php file which you copied into child theme folder.

  • Open functions.php file in any editor and paste below code:

  • <?php
  • add_action('wp_head', 'wpb_add_googleanalytics');
  • function wpb_add_googleanalytics() { ?>
  • // Paste your Google Analytics code from Step 7(where we tell don't close the browser) here
  • <?php } ?>
  • Save the file and upload on server.

Note: For second and third method visit Google Analytics website to see the reports. You have to log in to your Gmail account which you used earlier.