How to install Google Analytics on WordPress [Ultimate Guide 2021]

Hammad Afzal Shiekh
10 min readMar 27, 2021
How to Install Google Analytics on WordPress

Want to install Google Analytics in your WordPress, here you will learn the entire process step-by-step. This guide is for new and experienced users who haven’t installed google analytics on their websites. It is a very easy process and I suggest that you bookmark (⌘+D for Mac OS | CTRL+D for Windows®) this page for future reference. And share it with your friends and anyone who wants to learn how to install Google Analytics in WordPress.

Success in any online endeavor pivots on data. Being a website owner, the most vital thing you can track is how many visitors you get. Where they’re coming from, and how they behave after reaching the page. The visitors are real people, with different personalities, and different interests. And to magnify the chances to succeed, one should learn about the behavior of your visitors. And how they get attracted to your website is in the first place. This helps in taking that insight and harness it in the future. Amongst the best tools for tracking your site users is Google Analytics.

What is “GA”, Google Analytics?

It is a freemium website traffic analysis tool from the tech giant, Google. To define GA you could say at its core it provides statistics of a website on a daily, weekly, monthly, or yearly basis. You can check the number of visitors, the keywords they used to come to your site, and the region they are in. there are hundreds of different things that it will tell you including complete demographics, and location information. Being the largest platform around the world lets you learn a plethora of information about your websites.

The primary metrics that it tells you are, at first, a session that is created whenever a user is active with your website. A session has a thirty-minute duration, or it expires at midnight, so a user can have multiple sessions in a day. Then comes the number of users who have initiated at least one session during a certain time. It reports users as new and returning, meaning you will know if they are new or repeated users. Next is page-views, which is the number of viewed pages by the user in one session. Session duration is what tells you how engaging the content is to the users.

A bounce rate that measures the number of visitors who bounced or leave your site from the page they landed. Interpretation of these stats is very crucial and you should carefully read the data to interpret it.

WordPress + Google Analytics:

Being the most popular platform, WordPress hosts over 33 percent of all the websites on the internet. The main reason for its success is its easy customization. With a few clicks, you can fully enhance the functionality of your WordPress and add new features. It lets you install themes that can change the entire look of your blog. And with plugins, you can add as many features as you need to boost your website. This open-source CMS lets you build a stunning website without writing a single line of code. Assuming you already know all about WordPress and you already own a blog/website, I will tell you what you get when you install GA on WP.

As a blogger, you should know a lot of things about the visitors to your website/blog. After you learn how to install google analytics in WordPress you will access all this. It helps you in making a decision based on data. It tells you a lot of interesting facts about your website traffic, for example:

Who is the visitor?

This part answers questions like, what is the geographical location of your audience, which browser is used for the visit. And many other things like JavaScript and Flash Support, language, screen resolution, etc. For webmasters, this data is highly pivotal in several ways. If the majority of users don’t have specific support you can avoid it to improve the user experience.

Acquisition:

This refers to how the site gets traffic, meaning it simply tells you the way traffic arrives at your site. To simplify, if a user reaches the site from google search or from any social media platform like Facebook to Instagram. Or the user directly typed the URL to open the website. To install google analytics in WordPress is very easy and the things it tells you are really important.

All the data that it displays in real-time, so, whenever you view it, all the statistics that it shows are happening at that very moment. You can see how many people are actually reading the awesome post that you published. Or if they are watching that latest video that you recently uploaded. Normally it shows the actions that have occurred on your site in the last five minutes. But a few reports will allow you to view data as long as the last 30 minutes.

Traffic source tells you how users found your site, how much traffic the new posts are generating, and from which medium. You can also get insight into where users are landing on the website and how long they are staying. And whey the exit, which page they were on before that.

How to install Google Analytics in WordPress?

The process to install Google Analytics in WordPress is very, very easy and users with basic WordPress and internet knowledge can do this.

Setting up Google Analytics:

First of all, you will need a google account to access all google services, and Analytics is one of them. Signup in a regular way (if you already have one, just login), and visit, analytics.google.com.

“Create Account” page will appear, here provide the name of the account. This is an essential requirement and you can add multiple websites to one account. Add an appropriate name and scroll down a bit.

Underneath there will be four checkboxes, read them cautiously, and check all the boxes (all of them are recommended). And click “Next”.

Now it will ask you “What do you want to measure?”. There are three options here, 1st is “Web” which is to measure your website. This provides all the above-mentioned information about your website. The 2nd choice is “Apps” for getting insights into your iOS and Android apps. The 3rd is a mixture of both, so choose whatever suits you and what you intend in the future. For demonstrations, I will go for the top option and click next.

You now have to set up “Property” or website details, Add the name of your website, its URL. As well as the “Industry Category” that your site belongs to. It’s total up to your site, so click on “Select one” and choose any of the stated options. The dropdown menu has several options like Arts and Entertainment, Automotive, Beauty and Fitness, Books and Literature, Business, and Industrial Markets. Other options are Computers and Electronics, Finance, Food and Drink, Games, Healthcare, Law and Government, Online Communities, and various others, select the one relevant to your site. And select a time zone, after filling all fields, click the create button.

Terms of Service:

Google Analytics Terms of service agreement and additional terms applicable to data shared with google will appear. Read it thoroughly to understand, check both checkboxes, and click “I Accept”.

Now Google Analytics dashboard will open, and in the middle of the screen it will show “Tracking ID”. You will need it in the future for integration, DO NOT close this window, and you will need to copy some code in a few minutes.

Time to install Google Analytics in WordPress:

I believe you have an active and running WordPress website, plus you have just created your Google Analytics account. Now we will add it to your site, and this has three methods of achieving the final result.

01) — Install Google Analytics from the WordPress Theme Editor:

There are countless themes for WordPress, depending on what theme you have, you might have to adopt a slightly different approach. But the basic idea is the same, so this won’t be problematic for anyone of you. There is a drawback to this is that it only works until you switch the theme. As soon as you install a new one, it will disappear and you’ll have to carry the entire process from scratch. This is suited for advanced users who have an understanding of code. And if you are hesitating, skip this and view the other two approaches.

Anyway, open the WordPress dashboard in a new tab, hover over “Appearance” and click “Theme Editor”. A warning will show stating “Heads up!” and some information. Read it if you want and click “I understand”, and the theme editor will appear.

HEADER.PHP file:

Here, you will see on the right side of the page, Theme files, locate “header.php” and click to open it.

Now go back to google analytics and under “Global Site Tag (gtag.js)” you will find a box with some code, copy all of it.

Jump back to WP and paste the code right below <body> tag and click the blue “Update File” button.

FUNCTIONS.PHP File:

You can also copy this code in the “function.php” file, along with some PHP code. To do so, instead of the header file, locate functions.php file, and open it. And copy the following code,

<pre class=”brush: php; title: ; notranslate” title=””>

&lt;?php

add_action(‘wp_head’, ‘wpb_add_googleanalytics’);

function wpb_add_googleanalytics() { ?&gt;

// Paste your Google Analytics code here

&lt;?php } ?&gt;

</pre>

Paste this in the functions files and where it says “Paste Google Analytics Code Here”, replace it with Analytics code.

02) — With a Header and Footer Plugin:

This is the easiest method and you complete it without any prior coding knowledge. Let’s dive in, from the WP dashboard, click “Plugins –> Add new” on the black sidebar. Now in the “Search Plugins” are type “Insert Headers and Footers” and install the first one that shows up and activates it.

After activation, visit “Settings –> Insert Header and Footer” and paste the Google analytics code in Scripts in the Header section, and hit save. That’s it, as I told you, this is the easiest method and you can do so just in a short time.

03) — With Google Analytics Dashboard Plugin for WordPress by Monster Insights:

This technique is not as simple as the second one, but it surely has its own perks. This is the finest and most popular Google Analytics plugin for WordPress. With over two million active installs and more than 34 million downloads (as of September-2019), it is the thirteenth most popular plugin of all time. It was originally designed as “Google Analytics by Yoast” by Joost de Valk, the developer of “Yoast SEO”, with the success of Yoast, they focused on SEO products and dropped the Google Analytics project. And it got re-branded as “MonsterInsights” by Syed Balkhi in 2016.

It is a no-fuss solution for connecting your WordPress with google analytics and is designed to make it easier for beginners. It has a free and a paid version and for now, we will install the “Free” version. With the Premium version, you get advanced functionalities like Author/Ads/eCommerce tracking. And both have the same procedure to install. The installation is the same as the Headers and footers plugin, so follow those steps and install this plugin and activate it.

Configuration:

After activation, it places a new item in the menu “Insights”, after clicking on it a page will open. Scroll down a bit and click the “Launch the Wizard” button.

Now it will ask you to choose one of three options, “Business Website”, “Publisher (Blog)”, and “eCommerce”. Choose the once adequate for your site and hit “Save and continue”.

Now press “Connect MonsterInsights” on the page that appears next.

Now it will prompt you to select the account you want to use this plugin with, add whichever you prefer.

Click “Allow” to give permission to MonsterInsights for accessing the account.

Now pick the profile that you want to be monitored by MonsterInsights and click on “Complete Authentication” and save the changes.

GA on Site:

It will now install GA on your site and after completion, it will show a “Recommended Settings” page. Generally, the default settings would be fine and sufficient for you as a beginner. But if you have an Affiliate Link that you wanna track with it, you can input it in the designated areas.

In the same window, you can select user roles who will have to access MonsterInsights’s reports, after that click “Save and continue”.

Recommended Addons page will pop up and it will ask you to upgrade to the pro version to get these add-ons, Click on Save and continue.

It will now propose installing the WPForms plugin that gives you the ability to create beautiful forms. This step is entirely up to you if you want to install it press “Continue & Install WPForms” otherwise, push “Skip this Step”.

Now you will land on the last page of the wizard, saying “Awesome, You’re All Set!”, here tap on “Finish Setup & Exit Wizard”.

Congratulations! You’ve successfully installed and configured the plugin. The biggest advantage of the plugin is that you can view the stats internally from within the WordPress dashboard. To view the reports hover over Insights –> Reports, and it will present a brief overview of the stats.

Reading Data on Google Analytics:

Since you have learned how to install google analytics in WordPress, and correctly installed it. Thus now is the time you should know how to access and read the data. So go to your GA page and run the left-sidebar click on “Realtime” and “Overview”. This will show you the number of active users on your site, and some other things that are visibly labeled and are easy to understand. Here you can play around and view different options to get a variety of information. So feel free to dabble around and analyze the current situation of your website.

This is a very resourceful tool that gives you extremely high-value information that you can utilize you boost your site. So take your time and closely observe all the data that you find here. This article was primarily targeted at how to install Google Analytics on WordPress, however, if you want further knowledge on how to use Google Analytics. There are gobs of helpful resources on the internet that you can refer to get additional assistance.

Furthermore, if you want enhanced results, you can use Google Search Console to get in-depth details of search results. By using both of them combined you can supercharge your WordPress site by gaining insights into what the visitors want.

Conclusion:

WordPress and Google Analytics are very excellent tools and combining both can give you heights of success. Use them for measuring and improving and maximizing the site’s performance, and accomplishing your goals. I wish you the best of luck and hope your online business flourishes. If this guide helped you, do share it with others and on social media.

If you want to learn more about the WordPress please check out my recent posts:-

--

--