• Skip to main content
  • Skip to primary sidebar

How to Add Google Analytics to WordPress Blog?

Reading Time: 5 mins. Posted on December 18, 2019 .

4 Ways to add Google Analytics to a WordPress blog or website without any PHP programming, without a plugin and using MonsterInsights

How to Add Google Analytics to WordPress Blog?

There are multiple ways to add Google Analytics to a WordPress Blog. I will share four ways to get it done for you.

  1. With a Simple Plugin to Insert Analytics Code
  2. Modifying the theme’s Header File (Edit HTML)
  3. Modifying the theme’s Functions File (PHP Programming)
  4. Using MonsterInsights

But before, let’s set up the website property in Google Analytics and grab the tracking code/tracking ID.

Grab Google Analytics Tracking Code

The Google Analytics setup includes three steps. Create an account, select what you want to measure, and set up your property (site/blog). Finally, place the tracking code in WordPress.

Log in to Google Analytics with a Gmail account and click the start measuring button.

welcome to google analytics page 1

Create Account

Name your account. You can name an account as the website or blog name. Moreover, it can be different too. A single account can track more than one website or blog. In short, you can name it based on the sites or blogs under this account name.

account setup

Tick the checkbox as per your convenience to enable other features & products. Recommended – Tick all of them. Now click next to select what we want to track.

What do you want to measure?

Google allows users to measure website traffic, apps traffic, or both simultaneously. For a WordPress blog, select the web option. Click next to set up the blog as a property in Google Analytics.

what do you want to measure

Property setup

To set up property, include website name and URL. Select the industry category from the drop-down list.

As I am in India, Indian time reporting works better for me. Choose the time that suits you, but remember, it won’t be possible to change later. Once done, click create.

property setup

To finish the process, you will have to accept Google Analytics Terms of Service Agreement and Additional Terms Applicable to Data Shared with Google. Select your location from the drop-down list. Tick the checkbox, scroll down, and click the I Accept button.

Google Analytics Terms of Service Agreement

Now you are on the settings page of the Google Analytics interface. The system will display the code upfront. Refer to the one marked in red. There’s a unique tracking ID integrated into the code. You can copy the whole code or note the property ID.

website tracking code in google analytics

Copy the code in a notepad. Technically speaking, we are done with the analytics tool here. Now we will head over to your site or blog’s WordPress backend to install the analytics code.

Also read:
How Much Does It Cost to Start A Blog in 2022
How Much Does It Cost to Start A Blog in 2022
There are 7 cost elements to consider to start a self-hosted WordPress blog. Let's break down each to estimate the overall cost.

Insert Google Analytics code to WordPress via a Plugin

Do you want to add Google Analytics to your WordPress site or blog without to deal with PHP programming?

Let me help you connect Google Analytics to WordPress with an Insert Headers & Footers plugin.

To do this, you will first need to install the plugin in the WordPress account. Follow the steps below to install the plugin.

  • Log into your WordPress account.
  • Hover mouse on the plugin tab & click the add new option on the left panel.
  • Search for the plugin Insert headers & footers in the search bar. Top right.
  • Click install now and activate the plugin after that.

Example image for reference.

Add insert headers & footers plugins in wordpress

However, you can download this plugin and upload it here using the upload plugin function. There’s no difference in it. Once the plugin is installed, activate it.

Hover your mouse over the settings tab and click insert headers and footers. Now paste the code we copied from Google Analytics into the header space. Click Save, and it’s done.

inserting code in the header in wordpress

Wait for a few moments. Check whether the code is successfully integrated into our site or not. To do this, browse your website or blog in a separate window and view the real-time report for Google Analytics.

It will show you browsing the site under the realtime stats.

Insert Google Analytics code to WordPress via Theme header File (header.php)

In the WordPress admin, Click the theme editor under appearance option.

Now you’re on the edit themes page. On the right side, select the theme you want the code to insert the code into. Generally, your theme is selected as default. In our example, I have taken the twenty-twenty theme.

google analytics code in header dot php

Within the “theme files” section, locate the theme header (header.php). Click on it, and the code of the header.php file will load for you to edit, as shown in the example image above.

Find the closing head HTML tag </head>. Paste your analytics tracking code above the HTML </head> tag. Finally, click the update file button.

Your Google Analytics code is installed.

Insert Google Analytics code to WordPress via Theme functions File (functions.php)

At times, in many themes, the header file doesn’t have the HTML head elements. They may be in some other files. Genesis is one such theme where you won’t find the </head> tag in the theme’s header file.

So, in that case, we opt to edit the theme’s functions.php file.

The step remains the same as in the above method of editing the header.php except for this time we modify the theme’s functions.php file instead of the header.php.

google analytics code in functions dot php

Scroll down to the end and insert your tracking code between the lines.

<?php
//* Copy the above PHP opening tag if and only if your functions.php has a closing PHP tag
function add_google_analytics() { ?>
<!-- Paste Your Google Analytics Code Here -->
<?php } add_action('wp_head','add_google_analytics',10);
view raw functions.php hosted with ❤ by GitHub

Then place the code at the end of the functions.php file.

Google Analytics to WordPress via MonsterInsights

We will install the MonsterInsights Plugin and connect Google Analytics via the MonsterInsights options.

  • Log into your WordPress account.
  • Hover mouse on the plugin tab & click the add new option on the left panel.
  • Search for the plugin MonsterInsights in the search bar. Top right.
  • Click install now and activate the plugin.

monsterinsights

Once the plugin is active, it will add an Insights link in the left menu. Click settings under Insights.

MonsterInsights Settings

You can either paste the unique Google Analytics tracking ID we obtained or can use the “Connect MonsterInsights” button that will redirect you to Google to approve the Google Analytics app to MonsterInsights.

Once done, your Google Analytics is added to your WordPress Blog. MonsterInsights offers a lot more like viewing Google Analytics, some critical reports in the WordPress Dashboard itself, and much more.

You are Here: Home / Freelancing / How to Add Google Analytics to WordPress Blog?

About Shabbir Bhimani

Blogging Since 2009. If I can leave my high paying C# job in an MNC in the midst of global financial crisis of 2008, anybody can do it. @BizTips I guide programmers and developers to Start and Grow an Online Business. Read more about me here.

May I help You With ...

Upwork Proposal
Finding Clients
Start a Store
Start a Blog
 

Or Help Yourself ..

Primary Sidebar

About Shabbir Bhimani

Blogging Since 2009. If I can leave my high paying C# job in an MNC in the midst of global financial crisis of 2008, anybody can do it. @BizTips I guide programmers and developers to Start and Grow an Online Business.

Get in touch with me on LinkedIn or read more about me here.

Let me Guide You to Start and Grow your Online Business

Download my
FREE eBook NOW
to win more clients.
And it is not an annoying pop-up either

Additional menu

  • Twitter
  • Linkedin

BizTips

Shabbir Bhimani: Start and Grow an Online Business

  • Freelancers Start Here
  • Start An eCommerce Store
  • Start A Blog
  • About
  • Archive
  • Disclaimer
  • Contact
  • Glossary

2009 - 2025 All my content & images are licensed as Creative Commons.

WebTurtles LLP. LLPIN: AAL-5288. Hosted with Linode.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT