How to Install Google Analytics on WordPress

Today we are going to understand how we can add Google Analytics Code in WordPress.
Before jumping into the answer of the above-mentioned question i.e “How to add Google Analytics Code in WordPress Blog?” let’s understand What is Google Analytics and its use.

What is Google Analytics?

Google Analytics is the Web Analytics FREE tool offered by Google which is used to analyze the website traffic.

We are not going to deep for the Google Analytics Tool in this article, but just the basic definition and its use.
Google Analytics is the analytics tool which can be used for the analysis of your website traffic. Using it you can know how many users are visiting your website or page daily, monthly, yearly, etc.

You can know:

  • How many users are currently on your website
  • Browser of the visitor, device of your visitor like mobile or desktop.
  • Location of visitors.
  • How much time spent by the visitor on your website or blog post.
    So this statistics will help you to improve your website traffic. You can know that which blog post visited more times and from which location.

Lets jump into the question now.

How to add Google Analytics Code in WordPress Blog?

There are two ways to insert Google Analytics code in WordPress blog:

  1. Edit header.php file and put the Google Analytics code in between < head> and </head> tag.
  2. Use WordPress Plugin Insert Headers and Footers ( Recommended )

Lets understand both of the above ways of adding Google Analytics Code in WordPress blog.

1. Edit header.php file and put the Google Analytics code in between <head> and </head> tag.

This is not recommended at all.

This is risky one if you are not that much technical. Never edit any of the WP file instead use Plugins.

What is the Risk?
If you are not technical: The Risk is you may put it on wrong place or you may something else which is not expected. Any small mistake will break your website. Hence take a backup of your website code or at least the file which you are editing ( in this case it is header.php )

If you are technical person and you know the wordpress file structure still you have the risk and the risk is:
When you Change theme your changes will be lost and because of that you will loss the tracking of activities on your site. When you apply new theme you again need to add the Google Analytics Code to the specified file.

So lets understand how to add Google Analytics code in your WordPress blog without using Plugin:

Step 1: Get your Google Analytics Code:


1. Login your Google Analytics Account and select the website for which you need the tracking code.
2. Click on Admin in the left taskbar.

Click on Admin menu ( left side )

3. After click on Admin menu, you will see three columns as: Account, Property, View

4. Click on Tracking Info in Property Column.

Click on Tracking Info under Property column

5. After click on Tracking Info you will see sub menus, select first menu i.e. Tracking Code

copy the GA tracking code

6. After Clicking on Tracking Code you will see the tracking info that your Tracking ID and below that you will see the heading Website Tracking and subheading Global Site Tag (gtag.js). You can see the box in which your Google Analytics code is present.

7. You need to Copy this code and add that code in header.php file of WordPress.

Step 2: Add your code to header.php

Now its time to navigate to your header.php file to put the copied code.

1. On left side of your WordPress dashboard ( after login ) you can see the menu Appearance, click on that menu.

2. After clicking on Appearance you will see sub menus and the last sub menu is Editor. Click on Editor Menu.

Editor Menu to edit the WP files

3. After clicking on Editor menu, you will see the Popup with heading Heads up!

Heads up ! popup – select I understand

4. So if you want to go ahead then click on I Understand, otherwise Go back.
After clicking on I Understand, you will see like this:

Click on Theme Header option on left side

5. Click on Theme Header header.php )

6. Paste the GA Tracking code before the tag.

Paste the tracking code in header.php in between head and /head tag

Click on Update File to save the changes.

Thats it!  You have successfully added the GA tracking code means you have successfully installed Google Analytics without using Plugin.

2. Use WordPress Plugin Insert Headers and Footers ( Recommended )

Now lets see how we can add GA tracking code using Plugin.
We recommend to use Insert Headers and Footers plugin to add Google Analytics code. This is very easy method to add GA tracking code.


First, install and activate Insert Headers and Footers plugin.

Once you activate the Insert Headers and Footers plugin you can see Insert Headers and Footers menu under the Settings Menu on left side of WordPress dashboard.

Click on Insert Headers and Footers.

Insert Headers and Footers menu

Paste your GA tracking code in Scripts in header box and click on Save button at bottom.

Paste your Google Analytics tracking code in Scripts in header

In this way you can add the Google Analytics Tracking Code in WordPress. Congrats, you have installed Google Analytics successfully