Google Analytics is a free web analytics service that allows you to track visitors on your website and analyze their behavior. It provides valuable insights that help you improve your website, shape successful business and marketing strategies, create better content for your readers, and pinpoint sources that are bringing you the most traffic.
In this tutorial, we will walk you through the necessary steps to add Google Analytics to your WordPress website with two different methods, by using a plugin and by adding the tracking code to the WordPress theme files.
Create a Google Analytics account
The first thing you’ll have to do is sign up for a Google Analytics account on the Google Marketing Platform. Click on the Start for free button and go through the following steps:
1. Log into your Google account and sign up for Google Analytics.
2. In the next screen, you’ll be prompted to enter the account name. In the Account Data Sharing Settings, you can change the settings or leave them by default. Click on Next to proceed to the next step.
3. Now, if you don’t have any mobile apps, leave the default Web option checked. Click on Next to proceed.
4. Set up your property. Fill in your website name and URL, select the industry and time zone. Click on Create to continue to the final step.
5. In the final step, you’ll have to accept the Google Analytics terms. That’s it!
Now you’re ready to connect Google Analytics to your website. We’ll look at two ways of achieving that – by using a WordPress plugin and inserting the tracking code to HTML by yourself.
Method 1 – connect Google Analytics with the MonsterInsights plugin
This method is recommended for most website owners as it does not require any knowledge of HTML coding. With over 2 million users, MonsterInsights is the most popular Google Analytics plugin for WordPress. It will help you add Google Analytics to your website in just a few steps. Plus, it comes with a few other goodies, such as a built-in dashboard to display analytics data and reports.
First, install and activate the plugin. Upon activation, a setup wizard will open to guide you through the process.
In the first step, you’ll have to select a category that best describes your website.
Next, you will have to connect with your Google Analytics account. Click on the button labeled Connect MonsterInsights, and you will get redirected to another page, where you’ll need to select a Google account. If you are not signed in, you’ll need to do this first. Once signed in, select the account your Google Analytics belongs to.
After that, you’ll need to allow permissions so MonsterInsights can access your Google Analytics account.
Next, select a profile to complete the connection. If you have multiple websites on your Google Analytics account, then you’ll need to choose the right one here. When done, click the Complete Connection button. After a few seconds, the authentication process will finish, and Google Analytics will get successfully connected to your website.
Lastly, you’ll be prompted to choose your settings. The default settings should work fine for most websites. Click on the Save and Continue button to save your settings.
The last two steps will show you paid addons, which are part of the premium version of the plugin, and a recommendation for a contact form plugin (WPForms). You can skip both of these to continue to the last screen. If everything went alright, you should see a success message. Hit the Finish Setup & Exit Wizard button, and you’re all done.
Method 2 – connect Google Analytics by inserting the tracking code to HTML
This method is for advanced users who are not afraid to mess with the HTML/PHP code. For Google Analytics to work correctly, you should embed the tracking code to the <head> tag of every page. In WordPress, you’ll commonly find the head tag in the header.php file of your theme.
First, you’ll have to get the tracking code. Sign in to your Google Analytics account and go to Admin > Tracking Info > Tracking Code. Copy the Global Site Tag tracking code – the whole code snippet.
Next, head to your hosting server. Go to your WordPress root directory, navigate to wp-content/themes, and double-click your theme folder. In most themes, you’ll find the header.php file in the base folder. Open the file and paste the code – the whole thing from the opening to the closing script tag – in the head, right above the closing tag.
That’s it! Your website should be successfully connected to Google Analytics now.
Important note! In case you’re using a caching plugin, you should also clear the cache, otherwise the code you inserted might not show.
How did it go? We’d love to hear if you successfully connected Google Analytics to your website, or did you have any issues along the way?
I always look forward to your post, you always seem to be able to find a way to make every time interesting and full of fresh content.