Guide to Add Google Analytics to WordPress

  • Post category:WordPress
  • Post author:
  • Post last modified:November 7, 2020
  • Reading time:5 mins read

Google Analytics lets you track the traffics of your website and the behavior of the traffic(users). You can check the details of users’ behavior on Google Analytics. Some useful features of Google Analytics are…

  • Find the number of users who visited your website.
  • From where the users are coming(Organic, Social, Direct, etc).
  • How long do users stay on your website?
  • Which pages are most popular on your website.
  • Which age group of the users is visiting your site mostly.
  • And many more …

You can add Google Analytics to WordPress using several methods. I have explained two different methods below. These two methods are easy and safe and also beginner-friendly.
But, first, you need to sign up for Google Analytics. If you already have signed up for it then you can ignore the Signing up process and go to the next step.

Google Analytics account creation

Go to and log in with your Google account.

create google analytics account first step

Enter a name for the account. You can enter your name or the name of your website so that you can recognize the account(You can have multiple Analytics accounts for different websites with a single Google account).

Go to the next screen by clicking on the Next button at the bottom. It will ask you to choose the platform where you want the Analytics to measure traffic.

Here choose the Web option for the website traffic measurement.

select web to measure website traffic

Go to the next screen by clicking on the Next button at the bottom. Here you need to enter your website details, for which you are creating the Analytics account.

Google Analytics property setup
  1. Enter a name for the website. You can choose any name here.
  2. Enter the website URL. Select the protocol of your website (HTTPS or HTTP).
    (If your site doesn’t have a secure protocol installed you can install it within minutes by this tutorial.)
  3. Select the website type. If you do not find a match for your website, you can select the Other option.
  4. Select Reporting Time Zone. Select the location where you are located, so that it can match with your time zone.

After filling all these details click on the CREATE button. You will be asked to accept terms and conditions on the next screen. Accept these.

Your Google Analytics account is successfully created. You can see a piece of JavaScript code on the screen.

Google analytics javascript code

You can copy this code or save somewhere else(You can copy this code from the analytics account later). You need to enter this code to your WordPress website by one of the methods below. You can choose the method which you find easier. All the methods will work fine with your WordPress website.

Add Google Analytics to WordPress by adding the code to the theme header

To connect Google Analytics to your WordPress website you can choose this method. This is the recommended method if you do not want to compromise the loading speed by adding more plugins(Though not all the plugin slower down the load speed of the website).

For this method, you need to paste the Analytics code to the theme’s header.php file. I would recommend you to create a child theme and customize with codes on the child theme. So that you do not lose any codes when the theme updates.

After creating the child theme activate the theme ( Also you can do it on the main theme if you do not want to create a child theme).

Now go to Appearances -> Theme Editor.

WordPress Appearance theme editor

It will open the code editor for the theme core files. Select the theme here (current theme is always selected). Select the header.php from the right. Paste the Analytics code before the closing of the </head> tag as the image below.

Paste Analytics code on themes header file

Now update the file. Google Analytics is now successfully integrated with your WordPress website.
You can measure the traffic details from the Analytics window.

NB: When you will change the theme, you need to paste the same code on the new theme’s header.php file.

You can add Google Analytics to WordPress by using the Insert Header and Footer plugin. This plugin will push the Google Analytics code to the page when the page will load. For that, you need to install the plugin. This plugin has more than one million active installations.

Insert Header Footer plugin

After installing the plugin activate it. And go to Settings -> Insert Header and Footer.

Settings Insert Header and Footer menu

Now on the Scripts in Header box paste the Google Analytics code. And save it.

Insert code into Insert Header and Footer plugin

You can check this plugin will do the same job as I explained in the manual method. It will push the code between the <head> tags of the website.

Final Thoughts

Both methods explained above are beginner-friendly and easy. You can add Google Analytics by following any one of the methods.

The manual method, by adding the analytics code to the theme header file is the method I use on the WordPress websites.

Remember, when you will change the theme you have to add the code again to the new theme’s header file.

You can choose the second method (with the plugin) if you are not comfortable with adding codes to the theme files.

You can ask me for any query. I will definitely get back to you.

This Post Has 2 Comments

Leave a Reply