How to Add Google Analytics to WordPress – Easy Steps
Are you finding a way to add google analytics to your WordPress website? Then, don’t worry you have found the complete step-by-step guide to add google analytics in WordPress.
In this tutorial, I will tell you how to add google analytics 4 to the WordPress website. So let’s go ahead.
This tutorial will teach you:
- What is Google Analytics?
- Why is Google Analytics so Important for your WordPress Website?
- How to Add Google Analytics to WordPress without a Plugin
You can also click on the above links to jump on that particular step. So let’s begin with a quick introduction to google analytics. You can also skip the introduction if you want.
What is Google Analytics?
Google Analytics is a web analytics service offered by Google. In simple words, it is an online free web application. That provides us with the tools that we can use to analyze our website data and see where our visitors are coming from. And collect our traffic insights, track our website’s performance, and more.
Why is Google Analytics so Important for your WordPress Website?
You may have a question in your mind why is it so important for your WordPress website? Here is the answer.
Whenever we start a new website, blog, business website, e-commerce store, or any other type of website. We always feel a need that there should be a tool that we could use to check how our brand-new WordPress website is performing. How many people are visiting our website? And from where are the visitors coming?
Also what pages are visited most and what are the pages on our website that have less amount of traffic? All these questions arise in our minds. And fortunately, google analytics is the tool of our dreams.
Not only this. We can use this information to improve our website performance, traffic, and many other things. So, now I hope that you know the importance of Google Analytics. So let’s see how to set up google analytics and then we’ll connect it to our website.
How to Add Google Analytics to WordPress without a Plugin
In this method, we will manually put the google analytics code to our WordPress website. And we don’t need to install any plugins. But before that, we will set up a Google Analytics account first. So that we can get our Google Analytics tracking code, without wasting time, let’s go to our first step.
Step 1: Set up Google Analytics Account
1: Log in to your Google Account and open the Google Analytics website.
First thing, you need to make sure that you have a Google account and that you are logged in to that Google account in your browser. If you are logged in then, open the Google Analytics website in your browser to get started.
After clicking on the link above, you will go to this page like in the image below:
Note: If you’re logged in then at the right top of the page you will see your avatar. As shown in the image above. This means you are logged in.
Now click on the Start Measuring button as you saw in the image above.
2: After clicking on the start measuring button you will go to this page like in the image below.
Here enter the account name (you can enter your name or whatever). Then, click on the Next button located at the bottom of the page.
3: Nowhere on this page below. You have to enter the property name (you will enter your website name here). Then, select your time zone and currency. After that click Next.
4: After that select any check box below the business size list. And then select, what are the reasons you want to use Google analytics. And click on the Create button.
5: Now check the box and click on the I Accept button to accept the terms of service. As you can see in the image below.
Here subscribe to email updates
Here below in the image, they are asking about email updates. If you want to receive email updates from google analytics, you can check the boxes and click on save. It is optional you can skip this too.
6: Now we will generate the google analytics code for our WordPress website. Click on the Web button as shown in the image below.
7: After clicking on the web. See the below image. Here you will have to enter your website URL and stream name (you can enter your website’s name here) then click on Create Stream button.
Note: Just make sure the enhanced measurement button is on.
Remember: You can add 100 properties (websites) in one Google Analytics account.
8: Here we go, we have completed the setup of Google Analytics. Now we will connect google analytics to the WordPress website.
Step 2: Connect Google Analytics to WordPress Website
Now it’s time to connect Google Analytics to WordPress. So that you can see your website’s insights and reports. We need a google analytics tracking code that we will add to our WordPress website to work.
1: To do this, go and click on Data Streams. As you can see below.
2: After that click on your website as you can see in the image below. The site that you have added before.
3: Nowhere, scroll down, find and click on the Global site tag (gtag.js) as you can see in the below image. And then copy the code.
Now you have the google analytics tracking code. So, we are going to enter that code into our WordPress website.
Step 3: Add Google Analytics Code to WordPress
There are two ways to add Google Analytics tracking code in WordPress:
- Without using any Plugin insert Code to your Theme inside the (header.php) file
- Insert Google Analytics Tracking Code via Plugin (Recommended)
1. Add (GA4) Code in WordPress without Plugin inside (header.php)
To do that, log in to your WordPress Dashboard and go to appearance then theme editor as you can see in the image below. And on the right side click on header.php as in the image.
After opening the header.php, the tracking code that you have copied before. Just paste that code inside head tags and then don’t forget to click on the update button to save the changes.
Now your Google Analytics has connected to your WordPress website. Let’s see the second method to add code.
Adding code to your theme file is risky. Because whenever you update your WordPress theme or install a new WordPress theme then the tracking code will be lost. That’s why I will recommend you use the plugin given below to add your Google Analytics tracking code.
2. Insert the Tracking Code through a Plugin called (Insert Headers and Footers)
To do that, you need to go to the plugins area and then click on add new Plugins to search for a new plugin called Insert headers and footers.
After installing and activating the plugin, open the plugin. This will be located in your Settings tab and at the end just click on that to open. Like in the image below.
Now just paste the Google Analytics code inside the header section as you can see in the below image. Then save it.
Congratulations! Now your google analytics is connected to your WordPress website. And you can see your analytics.
I hope this guide will be very helpful for you. If you have any questions related to this then leave a comment below.