Beginners Guide On How To Add Google Analytics To WordPress
Google Analytics is one if not the most used user tracking services out there. In this guide, we will teach you how to add Google Analytics to your WordPress site. So without further ado, let’s get started.
What is Google Analytics
Creating Google Analytics account
To create your Google Analytics account, you are going to need to have an existing Google account or create a new one here.
If you already have a Google account or just created one you can log into Google Analytics from here.
Step 1 – Account name
Set up an account name. This can be called anything but I do recommend setting it the same as your page title unless you are going to have multiple different sites or tracking codes under the same account.
Step 2 – Property setup
The second step is to create the property. Depending on how many properties you have (meaning sites) it’s good to name them by your site again. Another important checkmark is to check the “Create a Universal Analytics property” if you want to create Google Analytics Universal Analytics with your new Google Analytics 4 code.
In this example, we will be creating both.
Step 3 – About business
This step can be skipped completely if you want to since you are not forced to answer questions regarding your business.
How to add Google Analytics to WordPress
After creating the Google Analytics account(s) it’s time to add the actual code to our site. For this, we will be using Google’s official WordPress plugin, though a quick and easy solution we highly recommend MonsterInsights.
1. Install and Activate Google Site Kit
Go to Plugins > Add new and search for Site Kit by Google – Analytics, Search Console, AdSense, Speed
After finding the plugin, install and activate it.
2. Start the setup
After activating the plugin you will be requested to “Start setup”. Clicking this will take you to the plugin’s settings where you will be asked to Sign up to Google.
3. Sign in with Google
When you sign in to Google, Google will request access to certain parts of your account to be able to pull the data from your accounts.
4. Setting up Analytics
Now that we have access to your Analytics you can simply select the right property and press save. The Site Kit will do the rest and add the code to the right areas of your site.
Other Google products you can connect with Site Kit include Search Console and Google Adsense.
How to manually add Google Analytics to WordPress
If you don’t want to use Google Site Kit or MonsterInsights (Recommended) to add the code to your site you can always add the code directly to your site’s header.php file. To do this you are first going to need to find the Google Analytics tracking code from your Google Analytics account.
Where to find Google Analytics tracking code
The Google Analytics Global Site Tag or the tracking code is placed in two different places. Depending on if you’re installing Universal Analytics or Google Analytics 4. Here’s how to find them.
Google Universal Analytics
For the Universal Analytics you need to head on to your Admin > Property > Tracking Info > Tracking Code.
After that, you will find the Global Site Tag (gtag.js) code.
Google Analytics 4
If you are using Google Analytics 4 head on to Settings > Data Streams and select the data stream you want to add. From there click the Add new on-page tag > Global site tag (gtag.js) and copy it.
Adding the tracking code to your site
In both cases the code needs to be inserted in your <head> for this we either recommend adding it directly to your header.php where you will in most cases find a place to simply paste the code or use a plugin like Insert Headers and Footers.
Another way is to use your functions.php and create a function to add the code to your header.
/* Add Google Analytics tracking code to header */
add_action('wp_head', 'google_analytics_tracking');
function google_analytics_tracking(){
?>
ADD TRACKING CODE HERE
<?php
};
We hope our guide helped you in adding Google Analytics to your WordPress site and if you liked our guide, don’t forget to share and comment.