How to add Google Analytics to WordPress- Beginner’s Guide

How to install Google Analytics in WordPress

Let me begin this tutorial by saying “If you want to grow your blog or website, tracking web traffic stats and knowing how visitors interact with your site is important”.

And for this there are tons of tracking tools available. However, Google Analytics is considered web standard.

Now, when it comes to adding Google Analytics in WordPress, a lot of users face problem.

Recently, I was approached by a blogger and was asked “Why was Google Analytics silent when the is site actually receiving clicks”.

And the answer was simple Google Analytics was not installed properly.

Also in some situations, Google Analytics may have been tracking data for sometime but all of a sudden one day when you login to check your traffic stats. And you find its not working properly or not working at all. And this is fairly a common question asked on Facebook groups.

We have a Facebook Group as well- Join Blogging Unplugged Community

This can happen in 3 situations

  • If you have implemented Google Analytics manually, then recently the theme you are using may have been updated and the tracking code was wiped out automatically.
  • In case, you were using a plugin for this, then a recent plugin update could have removed the code. This is a rare scenario.
  • In some sites I have seen the analytics code being implemented more than once which causes the problem of analytics not showing accurate data.

And this is the reason why setting up Google Analytics can be confusing for some.

Having said that,

In this tutorial, we will be covering all the basics when it comes to Google Analytics and you will learn

  • What is Google Analytics
  • Why do you need Google Analytics
  • How to sign up for Google Analytics
  • How to install Google Analytics in WordPress using plugins
  • How to add Google Analytics to WordPress manually
  • How to check if Google Analytics is working properly or not.
  • Common mistakes related to Google Analytics.
  • Getting familiar with Google Analytics
  • Things to remember when adding Google Analytics

Lets get started with the tutorial

What exactly is Google Analytics?

As the name suggests, Google Analytics is a free analytics tool by Google that helps you track traffic on your website.

This service was launched by Google in 2005 after acquiring Urchin. And as of 31st May 2020, this service is being used by over 54% of the websites which nearly 84% of the total market share.

And this makes Google Analytics one of the most used web analytics tool.

Having said that,

Google Analytics does much more than just tracking a website’s traffic. It can also be used to gather usage data from Android and iOS apps using SDK and this service is known as Google Analytics for Mobile apps.

And this takes me to the next question which is

Why do you need Google Analytics

As mentioned before, to grow your website or blog you need to know about your visitors and this is where Google Analytics comes into the picture.

It will provide you with data that will help you decide what you need to do in order to take your site to the next level. And here is what you can find in Google Analytics.

Traffic Source

One of the very first things you need to know is, How do people find your site or in other words what is the traffic source.

Is it through the links you have shared on social media or is it a recent guest post that’s bringing the traffic.

Answers to all these questions will let you know which traffic sources or channels are working as per your expectation and which of these need your attention. This will help you decide on which sources you need to focus on rather than going after every channel.

Devices Used

I’m sure you are familiar with the fact that, to browse the internet we use various devices with different screen sizes.

And Google Analytics provides you with information on how your site is performing across various devices.

For example, if a website is working perfectly fine on desktop and is not compatible with mobile devices. You will see a higher bounce rate on smaller screen sizes.

And by using this information you can understand and fix this problem.

Location

At times, you may have to run campaigns that target a particular location and that is where this set of data comes in handy.

You will be able to see how your campaign is performing, see which keywords are generating results and using this information you can further improve your campaign for better results.

Behaviour

When it comes to running a website, knowing how people interact with your site matters. Using Google Analytics, you can gather all the insights on

  • Time spent on pages
  • Traffic flow
  • Links clicked

And much more. By using this information, you can create strategies that will help improve user flow and bounce rate which will positively impact your website’s overall viewership.

Also, you can use this information to modify pages and see the improvement.

Time

Knowing when is the best time to post gives you the ability to publish content when it can get maximum exposure.

Using this insight you can schedule your posts to be published on best possible time.

When you get access to data driven insights, it eliminates the guesswork from the equation allowing you to craft a solid strategy to improve your website and provide value to your audience which further helps amplify your reach.

And on top of that Google Analytics is free to use and doesn’t add to website cost.

Having said that,

In order to add Google Analytics in WordPress, the first step is to

Create a Google Analytics account

As previously discussed, you can add Google Analytics in WordPress using 2 ways. However, the first step is the same.

Now, to sign up for Google Analytics, the only requirement is a Google or Gmail account. In case you do not have one, then you can create one for free.

And for that all you have to do is follow the step-by-step tutorial below and it will give you an option to create a new account.

To create a new Google Analytics account, the first step is to visit Google Analytics and it will ask you to either sign in using an existing account or create a new Google account.

sign up for google analytics
  • Save

If you have an existing account then you need to enter your email, click next and it will take you to a new screen where you will have to enter your password.

In case, you don’t have a Google Account, then to create a new one, click Create account and it will take you to a new screen where you will have to provide basic information and within a few minutes you will have a new account.

Moving forward,

Once you enter your password and sign in, it will take you to the Google Analytics welcome page where you need to click “Start Measuring”.

create google analytics account
  • Save

When you click Start Measuring, it will take you to a new screen where you need to provide your account name.

This name can be any name. The only thing you have to keep in mind is, this name should be easy to remember as it will be used internally.

I prefer keeping this name the same as the main brand name as later on if you want you can add other related properties to this. Now, it is important to know under a Google Analytics account you can have multiple properties.

Google Analytics account set up
  • Save

After selecting a name, click Next in the bottom of the page and it will take you to a new screen where you will be asked “What do you want to measure?” and there will be 3 available options

  • Web
  • Apps
  • Apps and Web

Out of the 3, you need to select web and again click Next

Measure website traffic using Google Analytics
  • Save

On clicking Next, you will be prompted to provide property details and this includes

  • Website name
  • URL
  • Industry Category
  • Reporting time zones
property setup in Google analytics
  • Save

As you can see in the screenshot above, I have provided all the information related to my blog and also have changed the reporting time zone.

After providing property details, click Create and a popup showing Google Analytics Terms of service agreement will appear.

Now, all you have to do is select your country from the list and accept the terms.

Google Analytics terms of service agreement
  • Save

When you click I accept, it will take you to the Google Analytics dashboard where it will show you the Tracking id and Google Analytics Global site tag.

google analytics tracking ID and global site tag
  • Save

Once you are done till here, the next step is

How to install Google Analytics in WordPress

As mentioned above, there are 2 ways to add Google Analytics in WordPress

  • Using Plugins
  • Manually

And in this tutorial, I will be sharing both starting with the easy one first which is using plugins. In case you want to do this manually, you can use the Table of Contents in the sidebar to navigate to the desired section.

Note– In case you are a WordPress.com user, that means you do not have a WordPress.org self hosted blog then this tutorial is not for you as you cannot add plugins or edit code in WordPress.com. In WordPress.com blogs you can see your analytics using built-in Jetpack functionality.

Related Article- WordPress.com vs WordPress.org

Before we move forward, it is important to know themes like Genesis by StudioPress offer a feature where you can add code snippets to your theme header without having to use the plugin.

In case you are using a child theme by Genesis then to add Google Analytics to your WordPress website, all you have to do is navigate to Appearance in your WordPress dashboard and click Customize

theme customization setting in WordPress dashboard
  • Save

On clicking customize, it will take you to your site’s home page and will show you theme customization menu.

theme customization settings
  • Save

Here you need to click theme settings which will show you another set of settings and at the bottom you will find Header/ Footer scripts.

header and footer scripts settings in Genesis
  • Save

This setting will allow you to add scripts in the header and footer. In the next step, you need to copy the Google Analytics code and add it in the box where it says Header scripts.

adding google analytics code in theme settings
  • Save

Once you are done adding the code, click Publish and clear cache. And that’s it you have successfully installed Google Analytics on a WordPress site using Genesis framework.

Now, if you are not using Genesis themes then you can easily do it using plugins. Just follow the tutorial below.

How to add Google Analytics in WordPress using plugins

If you are looking to install Google Analytics using plugins, then it is important to know this can be done using 2 plugins

And the first one on the list is

Google Analytics for WordPress by MonsterInsights

If you are not familiar with this plugin, then let me tell you MonsterInsights is the most popular Google Analytics plugin with over 2 million active installations and a rating of 4.5 out of 5 stars on the official WordPress plugins repository.

Google Analytics by monsterinsights
  • Save

This plugin is available in both free and premium versions and include features such as

  • Real time tracking inside WordPress dashboard
  • Detailed stats for each page and post
  • Setup tracking easily with just a few clicks
  • See Google Analytics report inside your WordPress dashboard
  • Automatic tracking of affiliate links and ads

And much more.

Having said that,

For this tutorial, I will be using the free version and in case you are looking to buy the premium version feel free to use our special link and get 50% off.

To set up Google Analytics using MonsterInsights, the first step involves download the plugin and installing it.

For detailed information on downloading and activating the plugins, you can follow our guide on How to install a WordPress plugin

Once you are done installing and activating the plugin, it will show the plugin’s welcome screen where you need to click “Launch the Wizard” button.

add google analytics in WordPress using monsterinsights
  • Save

On clicking, it will take you to the MonsterInsights setup and the first thing you have to do is select a category that best describe your blog or website.

Related article- Difference between a blog and a website

It will show you 3 options, pick whichever fits best

monsterinsights set up
  • Save

After you are done selecting, click Save and Continue.

In the next step, it will ask you to connect MonsterInsights to your website. Click “Connect MonsterInsights”

install google analytics using monsterinsights
  • Save

When you click it, it will take you to Google accounts where you need to select the account that you have used to sign up for Google Analytics.

set up google analytics using monsterinsights
  • Save

In the next step, MonsterInsights will ask for permission to access data from your Google account and all you have to do is click Allow.

allow monster insights to access Google analytics data
  • Save

On clicking Allow, it will take you to net screen where you need to pick a profile that you want to track and then click Complete Connection to finish the process.

connect google analytics with monsterinsights
  • Save

When you click complete connection, it will show you the plugin’s recommended settings. And if you are an affiliate marketer and want to track affiliate links you can do so by adding links in Affiliate link tracking.

Once you are done click Save and Continue.

tracking affiliate links using monsterinsights
  • Save

In the next step, it will show you a list of recommended add-ons. If you are currently not looking to invest then you can skip this step by clicking Save and continue.

When you click Save and Continue, it will take you to the next screen where you will be prompted to install WPForms.

In case you are looking for a multipurpose form builder plugin then this is the plugin for you. You can create

  • Contact forms
  • Subscription forms
  • Payment forms

And more using this plugin. And if you buy using our special link, you can get a discount of 50%.

If you are not looking to install right now, then you can click skip this step.

wpforms recommendation
  • Save

And that’s it, you have successfully setup Google Analytics on your WordPress website using MonsterInsights.

Click Finish Setup and Exit Wizard to go back to your WordPress Dashboard.

how to add google analytics in wordpress using plugin
  • Save

Before we move forward, it is important to know that it can take up to 24 hrs for reports to show.

Also, if you are looking to access web analytics from your dashboard then all you have to do is navigate to Insights in your WordPress dashboard sidebar and click Reports.

Having said that,

The next plugin on the list is

Insert Headers and Footers plugin

As the name suggests, this plugin will allow you to add Google Analytics tracking code in the header of the website.

If you are new to the online industry, this plugin will be very helpful in accomplishing in other tasks such as

Using this plugin is very easy and the first step in the process is downloading and activating the Insert headers and footers plugin.

To install and activate a plugin, you can follow our guide on How to install a WordPress plugin.

Once the plugin is installed, the next step is to head over to the plugin settings and you can locate it in your WordPress dashboard under Settings >> Insert headers and footers.

insert headers and footers plugin
  • Save

When you enter the plugin settings, you will find there are 3 separate boxes to insert code. In the next step, you need to go to the browser tab where you have the Google Analytics tracking code.

And all you have to do is copy the complete code and paste it in the box named “Scripts in Header”.

add google analytics tracking code in wordpress using plugin
  • Save

After adding the code, the next step is to click the Save button at the bottom and clear your cache. That’s it.

You have successfully installed Google Analytics using Insert Headers and Footers plugin.

Once you are done till here, next step in the process is to understand the basics of Google Analytics and you can jump to that section using Table of Contents in the sidebar.

How to add Google Analytics in WordPress manually

If you are looking to add Google Analytics manually then this section is for you. You can install Google Analytics in WordPress manually in 2 ways

  • Using Header.php
  • Using Fuctions.php

Before we move forward, it is important to keep in mind that these changes must be implemented on the child theme and not your main theme because you will lose the tracking code when your main theme will update.

Also, it is recommended to take a backup before you make any such changes. And for that we recommend UpdraftPlus.

How to add Google Analytics tracking code in header.php

In case this your first time implementing a tracking code manually then this process may look a little confusing. However, it is very easy to execute. You just have to follow this tutorial carefully.

To install Google Analytics manually in WordPress using header.php, the first step in the process is to navigate to Appearance >> Theme Editor.

theme editor in wordpress
  • Save

Once you are in the theme editor, on the right you will see all your theme related files and in those files you need to locate a file named header.php or theme header.

theme files in WordPress
  • Save

There are chances that you may not find this file on the list and in this situation you will have to copy this file from main theme and paste it in the child theme.

Having said that

Once you locate the header.php file, you need to open it and it will look similar to the screenshot below.

how to add google analytics in wordpress manually
  • Save

The next step in the process is to locate the <head> tag and for that you can use the search function

  • Windows users press CTRL+ F
  • Mac users press CMD+F

Once you locate the tag, all you have to do is paste the complete Google Analytics code just under it and click update file.

how to add Google Analytics tracking code in header.php
  • Save

And that’s it. You have successfully installed Google Analytics in WordPress using Header.php.

In case the changes are not reflected or analytics isn’t working, I will suggest clearing cache and in most cases it will work just fine.

Next on the list is

How to add Google Analytics in WordPress using functions.php

This is another way to add Google Analytics in WordPress without a plugin and this method is for the advanced WordPress users.

The process is a bit similar to what we have done above but instead of using header.php, we will be using functions.php.

Having said that,

The first step in the process is to take a backup of your website using UpdraftPlus and in the next step header over to Appearance >> Theme Editor

theme editor in wordpress
  • Save

Now, on the right you can see all your theme related files and from that list you need to select functions.php.

theme files in WordPress
  • Save

There are chances that you may not find this file in the list of files and in that case you will have to copy and paste functions.php file from main theme to child

Once you have found the file, the next step is to open it and paste the following code. Make sure you change the Google Analytics Tracking ID to yours.

add_action('wp_head','bu_analytics', 10);
function bu_analytics() {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id='UA-xxxxxx-1'"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxxxx-1');
</script>
<?php
}

And below is the screenshot with the code implemented

add google analytics tracking code in functions-php
  • Save

The final step is to save the changes you made by clicking Update File and clear cache.

Congrats!!! You have successfully installed Google Analytics in WordPress without using plugin.

Once you are done till here the next step is,

How to check if Google Analytics is working

Now that you have installed Google Analytics on your WordPress website, the next important step is to check if you have implemented the analytics tag correctly or not.

This can be done in 2 ways

Using Google Analytics dashboard

This step is very easy to execute. Once you have successfully placed the Google Analytics tag, you have to go back to the Google Analytics dashboard and click Admin button on the bottom left.

how to check if google analytics is working
  • Save

It will open a new screen where you will see your property listed. Under the listing, you will find an option named “Tracking Info”. Click it and a drop down menu will appear that will have the option Tracking Code.

google analytics tracking info
  • Save

On clicking Tracking Code, it will show you the tracking ID and in front of it will be the Status.

If you have recently installed Google Analytics, you will see No Data received in past 48 hrs.

You can click Send Test Traffic just below that and in a few minutes you will notice, the status will change and show the number of active users (including 1 from test traffic). See the below screenshot for reference.

checking if analytics is working
  • Save

In case the status does not change that means there is a problem and you need to go back and see if you have placed the code correctly.

The second way to check is through

Website source code

Till now we have established the fact that to add Google Analytics to a WordPress website, you have to add a tracking code and method for adding the tag could be either plugins or manually.

This means if you scan through the code you will be able to find it. And in case it is missing or not in correct place then that means Google Analytics won’t work.

To check the Google Analytics code in the website source, all you have to do is visit the homepage of your website or blog and

  • For Windows press CTRL + U
  • Mac user press Option/ ALT + Command + U

And it will open your website’s source code in a new tab. After seeing all the website code some of you may be thinking, isn’t there an easy way to do it.

Yes, I agree, scanning through this code and looking for this tiny code fragment is difficult and time-consuming and to make this easy we will use the search function.

  • Windows user can press CTRL + F
  • For Mac press CMD + F

It will open a search box where you need to add Google Analytics tag and press enter.

On pressing enter, it will show you the code. If the code is present and is under <head> tag will mean the Google Analytics is installed properly.

Else you will have to add the Google Analytics code again.

Common mistakes related to Google Analytics tag

In case you have installed Google Analytics tag and the tool is still not tracking, then there may be one or more of the below mentioned problem.

Patience

If you have just installed Google Analytics, then you need to wait for 24 hours for the reports to show.

Caching

In case you have implemented the Google Analytics tracking code and you cannot find it in the website source code then try clearing the cache and in most cases you will be able to see the code just by doing this.

Placement of code

If you are adding Google Analytics tag manually, make sure it is placed just below <head> tag. If placed anywhere else, Google Analytics won’t be able to track.

Copy and Paste error

This can happen to the best of us and to avoid this I will suggest copying the code directly from dashboard as it will eliminate any chance of including extra white space or any other characters.

Wrong property or tag

In case you are tracking multiple properties from a single account then there are chances you may have either applied the wrong code. And if the tag is correct then you are viewing the wrong property. Make sure you are working with correct tag and property.

Other reason

Recently, I encountered a problem related to Google Analytics where after adding the Pinterest verification code, the analytics stopped working. Now, this problem wasn’t due to the Pinterest code. It was caused because Pinterest verification tag was placed inside the Google Analytics code. To avoid this, be sure to add any other codes like this after the Analytics tag by pressing enter.

This will ensure the code is in the next line and it won’t interfare with the Google Analytics.

These are some of the common problems you can encounter and if everything is working as expected then the last step is

Getting familiar with Google Analytics

Once you have implemented the Analytics tag and started receiving some traffic, the next step involves learning the basics of Google Analytics.

For this, the first thing you have to do is log in to your Google Analytics account and the dashboard will look very similar to the screenshot below.

basics of google analytics
  • Save

As you can see, this is a new account and your dashboard will have data and that will be the only difference.

In the middle, you can see the overall statistics of your website and by default it displays data for the last 7 days.Also, it allows you to select a data range to see data for a particular period of time.

google analytics dashboard
  • Save

On the extreme right, it will show if there are any active visitors on your site currently and it also displays the pages being browsed.

You can click on the Real Time Report and it will show you all the details of the visitor.

google analytics real time reports
  • Save

Having said that,

On the left, you can find all the reports that you can see in the Google Analytics. Each of these reports is collection of multiple reports and when select one, you will see each sub menu items.

reports in Google Analytics
  • Save

And below I have described each one of these reports briefly.

Realtime

This report will show you all the details about the visitors that are currently browsing your site. You can see their location, source, page they are on and much more.

Audience

If you want to learn more about your audience then this report is for you. It contains all the data related to demographics, interests, location, time spent, devices and browser used and much more.

Acquisition

Using this report you can find out about how various traffic sources are performing. And it will give you a clear picture on which channels to focus on and which to improve.

Behaviour

This report will give you detailed information on how users are interacting with your site. You can find out which pages are generating most engagement. Along with this you can also see your site speed, site search and event reports.

Conversion

As the name suggests, conversion reports will let you know how you are performing against your own goals. If you have set goals in Google Analytics, then this is the report you want to check.

Having said that,

Adding Google Analytics to WordPress may seem complicated at first, however it is an easy process.

If you are not comfortable with adding code to your theme, then you can do this using plugins.

Before you leave, here is a quick recap of what we have discussed.

Things to remember when installing Google Analytics in WordPress

  • Copy and paste the code directly from Google Analytics dashboard to avoid addition of any white spaces or characters.
  • Make sure you clear your cache after adding the Google Analytics tracking code and wait for 24 hours for reports to show.
  • In case you are managing multiple properties from a single account, make sure you are adding the correct Google Analytics tag and tracking the correct property.
  • You can add Google Analytics in WordPress in 2 ways- Using plugins or manually.
  • If you are using plugins then I will suggest using MonsterInsights as you will get access to additional features such as affiliate link cloaking and tracking directly from your dashboard.
  • In case you want to do this manually, then either you can add the Google Analytics tracking code in the header.php or function.php. I will suggest adding in header.php.
  • If you are adding the code manually in header.php, make sure it is placed right below <head> tag.

Having said that,

Once you are done setting up analytics, the next step is to add your website in Google.

I hope you find this tutorial helpful and are able to add Google Analytics to WordPress easily. If you have any queries feel free to get in touch via the contact page or social media.

Also, let us know which method did you use to add analytics on WordPress- plugins or manually. And don’t forget to share this post with your friends and colleagues.

Before you leave, feel free to check the best deals and discounts on Blogging tools. Also, to stay up to date with our content, Join our Facebook group, sign up for our newsletter and follow us on social media.

how to install google analytics in wordpress
  • Save

Want more articles like this

Sign up to get Detailed Tutorials and Practical Tips to Grow your Blog

godaddy discount code99 cent Domain Names
Buy Domain Name from GoDaddy in under $1
Get domain name from GoDaddy in under $1.
buddyboss discount codeLifetime Deal
Get Lifetime BuddyBoss Deal and never think about Renewals again
BuddyBoss is offering a Limited time Lifetime Deal where you don't have to worry about renewals after purchase. Offer available for limited time only.
missinglettr discount code14 Day Free Trial
Get 14 Day Free Trial + 50% off on any plan for 3 months
Convert your Blog Posts into Engaging Social Media Campaigns with MissingLettr- Start your 14 Day Free Trial now

Join Facebook Group

I believe in building a community and that is why we have created a Facebook group where you can connect with me, ask questions and connect and collaborate with other bloggers in your niche.

6 thoughts on “How to add Google Analytics to WordPress- Beginner’s Guide”
Leave a Comment

×

Table of Contents

Hello There

Thank You for Subscribing

You are now a part of the Blogging Unplugged community. We will be sending you blogging tips shortly. In the meantime, you may like to read some of our popular and currently trending articles. 

If you like our website design and want to check the tools we have used.

siteground discount code70% off
Get 70% off on Siteground Hosting + Free SSL Certificate
67% off on Siteground Hosting and Free SSL Certificate when you buy it using this deal
wp rocket discount code20% OFF
Speed Up your website with WP Rocket- Limited time offer
WP Rocket is one plugin that I recommend to everyone starting out. It is the best cache plugin in the market today and using it can improve your sites loading time drastically.
elementor discount codeDownload Free
Best WordPress Page Bulider- Download for Free
Elementor is the number 1-page builder in the market today and we have used it to design this website. If you are new to the industry and looking to create a website or landing pages that grab attention, then Elementor is the one you need.
67 Shares
Share via
Copy link