How to connect Google Analytics to your WordPress website

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.

How to connect Google Analytics to your WordPress website

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.

Sign up for your Google Analytics account.
Sign up for your Google Analytics account.

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.

Enter your account name.
Enter your account name.

3. Now, if you don’t have any mobile apps, leave the default Web option checked. Click on Next to proceed.

Select the default Web option for WordPress websites.
Select the default Web option for WordPress websites.

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.

Enter your property details.
Enter your property details.

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.

Install and activate the MonsterInsights plugin in the WordPress Admin area.
Install and activate the MonsterInsights plugin.

In the first step, you’ll have to select a category that best describes your website.

MonsterInsights setup - select the type of the website.
MonsterInsights setup – select the type of the 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.

Connect MonsterInsights to your WordPress website.
Connect MonsterInsights to your WordPress website.

After that, you’ll need to allow permissions so MonsterInsights can access your Google Analytics account.

Give MonsterInsights access to your Google Account.
Give MonsterInsights access to your Google 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.

Choose your website domain.
Choose your website domain.

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.

MonsterInsights success screen.
MonsterInsights success screen.

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.

Get your Google Analytics tracking code.
Get your Google Analytics tracking code.

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?

Comments (1)

  1. Amit Manglani says:

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *