There are several different ways to set up Google Analytics in WordPress. We’ll show you three ways where the first option is the easiest and the last is the most difficult.
You can choose the one that best suits your needs.
Note :
you need to use only one of these methods on your website to avoid double tracking of page views in your Google Analytics account.
Method one : Google Analytics for WordPress by MonsterInsights
MonsterInsights is the most popular plugin for Google Analytics for WordPress. More than 3 million websites use it, including the likes of Bloomberg, PlayStation, Zillow, dr-WP, and more.
It’s the easiest and best way to add Google Analytics to WordPress (for all novice and expert users alike). In addition, it offers a double tracking feature that allows you to add Universal Analytics and Google Analytics 4 to your WordPress site without editing the code.
MonsterInsights is available both as a paid plug-in, and a free version . In this tutorial, we will use the free version of MonsterInsights.
You can use the MonsterInsights Pro version if you want more advanced features such as ecommerce tracking, ad tracking, author tracking, etc. The process of their preparation is the same.
Let’s get started.
The first thing you need to do is install and activate the MonsterInsights add-on. For more details, see our step-by-step guide on how to install WordPress plugins.
When activated, the extension will add a new menu item called “Insights” to the WordPress admin menu and a welcome screen will appear for you. Go ahead and click on the “run wizard”button.
Clicking on it will open the MonsterInsights setup wizard.
First, you will be asked to choose a category for your website (business website, blog or online store). Select one
and then click the “save and Continue” button.
Next, you need to link MonsterInsights to your WordPress site.
Just click on the “Connect MonsterInsights”button.
Next, you need to link MonsterInsights to your WordPress site.
Just click on the “Connect MonsterInsights”button.
After that, you will be asked to allow MonsterInsights to access your Google Analytics account.
Click the “Allow” button to continue.
The next step to completing the connection is to select the profile that you want to track.
You need to select your website here and then click the “full connection” button to continue.
After that, just click on the “full connection” button to continue. MonsterInsights will now install Google Analytics on your website.
After that, you will be asked to select the recommended settings for your website.
The default settings work with most websites. If you are using an affiliate link plugin, you need to add the path that you use to hide affiliate links . This will allow you to track your affiliate links in Google Analytics.
MonsterInsights will also ask who can see the reports.
You can choose different WordPress user roles . Once finished, click the “save and Continue” button to save your settings.
After that, MonsterInsights will show you a list of website tracking features that you would like to enable.
You can scroll down and click on the “Continue” button or the “skip Now”option.
On the next screen, MonsterInsights will show that you have successfully install Google Analytics tracking.
You can see that Google Analytics is connected, the tracking code is installed, and data is now being collected.
After that, you can scroll down and see a field for entering your license key.
Go ahead and click on the “complete setup without upgrade” option right now.
You have successfully install Google Analytics to your WordPress site.
Next, you will need to create a Measure Protocol API Secret. This will allow MonsterInsights to track events such as e-commerce purchases, form conversions, and more.
To get started, you can log in to your Google Analytics account. Then head to the “administrator” settings page and click on the “data stream”option.
After that, you will see your data streams.
Just select the data stream that you connected using MonsterInsights.
On the next screen, scroll down to the “Advanced settings”section.
After that, click on the “Measure Protocol API Secrets”option.
Now you will see a new window slide containing the secrets of the Measurement Protocol API. Initially, this page will be empty, and you will not have any API secrets.
Go ahead and click on the “Create”button.
After that, you will need to enter an alias for your API secret.
Once you have done this, just click on the “Create”button.
Your API secret will now be created.
Copy the API secret located under the “secret value” field.
After that, you will need to enter the secret value in MonsterInsights.
You can do this by going to Insights ” Settings from your WordPress admin panel and then clicking on the “General” tab
Then head to the “Google Authentication”section.
Just enter the” secret value “under the”Measurement Protocol API Secret” field.
I have successfully set up the measurement Protocol API Secret.
Now, let’s see how to use double tracking in MonsterInsights if you have a Universal Analytics account.
How to set up dual tracking when using Universal Analytics ?
If you already have a Universal Analytics account, MonsterInsights makes it very easy to track both Universal Analytics and Google Analytics 4 with its dual tracking feature. The best part is that you don’t have to modify any code.
Just note that Universal Analytics will be terminated on July 1, 2023, and you will not be able to track your website data after the expiration date. We strongly recommend that you set up the Google Analytics 4 website today and start sending data to GA4.
To set up binary tracking, you can start by going to Insights “Settings from your WordPress dashboard and then clicking on the” General “tab.
After that, scroll down to the “Google Authentication”section.
Under the “dual tracking profile” field, you can enter the Universal Analytics (UA) code.
You can find the Universal Analytics icon in Google Analytics by going to the “administrator”settings page.
After that, click on “location settings” under the property column.
You will see the “tracking ID” in the following format : UA-123456789-1.
Now you are successfully Tracking Universal Analytics using Google Analytics 4 on your WordPress site. Remember that Google Analytics will take some time before displaying your statistics.
The best part about MonsterInsights is that you can view Google Analytics reports within your WordPress dashboard. Just visit the Statistics “Reports page to check a quick overview of your analytics data.
It also comes with a popular posts extension that lets you view top-performing content to boost traffic and page views.
You can use it to automatically add embedded popular post links to boost engagement.
If you use an online store , it can also automatically add your top-performing products at the end of each blog post to increase sales:
Method Two : Enter the plugin for headers and footers
This method is not as good as MonsterInsights because you will not be able to perform advanced tracking configuration, and you will not be able to view Google Analytics data in your WordPress dashboard.
First, you will need to copy the Google Analytics tracking code (global location tag) that you copied in Step 4 earlier when creating a Google Analytics account.
You can find it in the web flow details under the “labeling instructions”section.
Next, you need to install and activate the Insert Headers and Footers extension .
When activated, you need to visit the settings page “insert headers and footers . Here you need to paste the Google Analytics tracking code that you copied earlier in the “scripts in headers”section.
Don’t forget to save your changes to store your settings.
That’s all, you have successfully installed Google Analytics on your site.
3. Install Google Analytics in WordPress Theme
This method is intended for advanced users who are familiar with the code. It is somewhat unreliable because your code will disappear if you switch or update the theme.
We never recommend using this method.
First, you will need to copy the Google Analytics tracking code that you copied in Step 4 earlier. You can view it in the web flow details section under the “labeling guidelines”section.
Now there are two popular ways to add this code to your WordPress theme files . You can choose one of them (not both).
1. Add the code in the header file.php
Just edit the header file.put php in your WordPress template and paste the Google Analytics trace that you previously copied right after the <body>tag.
Do not forget to save the changes and upload the file back to your server.
2. Adding via the function file
You can also add Google Analytics tracking code to your WordPress posts file . It will automatically add a tracking code to every page on your WordPress site.
You will need to add this code to the jobs file.the PHP of the template .
1 2 3 4 5 6 7 |
<?php add_action('wp_head', 'wpb_add_googleanalytics'); function wpb_add_googleanalytics() { ?> // Paste your Google Analytics tracking code from Step 4 here <?php } ?> |
View reports on the Google Analytics website
The Google Analytics program is able to display a treasure trove of data collected from your statistics. You can view this data by visiting the Google Analytics dashboard.
See the reports at Universal Analytics
You will see the embedded Google Analytics reports in the right column. Each section is divided into different tabs, clicking on a tab will expand it to show more options.
Here’s what the various reports at Universal Analytics tell you:
- The real-time report will show you a real-time view of your traffic.
- The “Audience” tab will display reports to help you understand your users.
- Acquisition reports explore where users are coming from.
- Behavior reports summarize what users do after they arrive at your site.
- Conversion reports show how well you have achieved your goals.
See the reports in Google Analytics 4
Google Analytics 4 reports are slightly different from Universal Analytics reports. In the left column, you will see a custom reports option. Reports are grouped together into two main categories, including life cycle and user.
One of the most noticeable differences you will find in GA4 reports is that there is no measure of bounce rate. Other than that, you’ll find a new reporting interface, new metrics like engagement time, no goals in GA4, and more.
However, you can expect that more new features, reports and metrics will appear soon in Google Analytics 4 since development at Universal Analytics has ended and will close in July 2023.
The following is a breakdown of the various reports in Google Analytics 4:
- The real-time report is similar to the Universal Analytics report and displays active users on your site in real time.
- The acquisition report shows the medium that users use to find your websites, such as membership, referral, email and affiliate.
- The engagement report shows conversions and events happening on your site.
- The monetization report collects all your ecommerce data in one place along with new reports such as in-app purchases and publisher ads.
- The retention report basically shows new visitors as opposed to repeaters of the visit and helps to get insights on user retention.
- Demographics help you see website traffic from the best countries, cities, and more. It also displays gender segmentation and interest reports.
- The technical report shows which device, browser, operating system, application version and screen size people use the most to view your website.
Getting the most out of Google Analytics
Google Analytics is an incredibly powerful tool with a lot of great features. Some of them are quite clear and easy to use, others require some additional preparation.
Google Analytics works best with Google Search Console (formerly Google Webmaster Tools). It allows you to see the performance of your website in search results.
If you want to improve your WordPress SEO rankings and get more traffic, we recommend using the aioseo plugin for WordPress which is an all-in-one search engine optimization (SEO) toolkit.
We hope that this article helped you learn how to install Google Analytics in WordPress.