How to Add Google Analytics to WordPress – Beginners Guide

Are you looking for a way to add Google Analytics to the WordPress website?

Understanding how your intended audience interacts with your website is critical to your success. The easiest way to get to know your audience is through traffic statistics, which Google Analytics provides for free.

In this guide, we’ll share why Google Analytics is important and how you can easily add Google Analytics to WordPress.

Why is Google Analytics Important For Your Website?

Once you start a blog, your first goal is to get more traffic and subscribers. Google Analytics helps you in making data-driven decisions by showing the statistics that matter. You can see:

Who Visits Your Website?

This section of analytics provides information about the location of your audience. What kind of browser did the user use to access your website? Other key details include screen resolution, JavaScript and Flash support, language, and more.

This data is helpful and can be used in various ways. When building a custom website design, you can use user data to ensure that your site is compatible with your target demographic.

What Do People Do When They Are On Your Website?

You can track where users go on your website, how long they remain there, and the bounce rate.

Using this data, you can improve your pageviews and decrease your bounce rate.

You may also see your most popular posts, underperforming posts, and what type of content your users are looking for.

When Do People Visit Your Website?

You can find the best time to publish your post by looking at the peak hour of the day for your site. If that time zone is inconvenient, you can schedule your post to meet at that time.

How Do People Find Your Website?

This part of the analytics shows you where the users came from. For example, if they use search engines, enter direct links, or click on referral links from another site?

It also shows you how many visitors came from each of these sources. Google Analytics provides a breakdown of each of these categories.

How Do People Interact With Your Content?

Google Analytics shows how site visitors engage with the content. It shows how many users clicked on specific links on your website and much more.

Additionally, you can do A/B split testing in Google Analytics by creating content experiments to learn what works best for you.

Getting Started With Google Analytics

Google Analytics is free to use; you only need a Google or Gmail account to sign up. To sign up, follow the easy steps listed below to create your Google Analytics account.

Step 1: First, you need to go to the Google Analytics website and click the Get started today button.

Google Analytics Homepage

Next, you will select your Gmail account to log in. If you have your Gmail account, you can use it to sign in. Otherwise, you can create a Google account for yourself.

Sign in With Your Google Account

Step 2: When you sign in with your Gmail account, Google Analytics will take you to a welcome screen like the one below.

Here, you will sign up for Google Analytics using your Gmail account. Simply click the Start measuring button.

Sign up for Google Analytics

After that, you’ll be asked to provide an account name. Google Analytics will use this name internally; therefore, it can be anything similar to your company name.

Google Analytics will also show several account data sharing settings. These settings allow you to control how your Google Analytics data is shared. You can leave the default settings and proceed to the next step.

Enter a Account Name

Create a Google Analytics Property

Step 3: Next, you will need to create a Google Analytics property.

Google released Google Analytics 4, also known as GA4, as a new version of their web analytics tool. It’s the most recent version and tracks both your website and mobile apps in the same account. You also get additional features, metrics, and a redesigned report interface.

Important Note: If you have a Universal Analytics account, you must also start tracking data in Google Analytics 4 (GA4). This is because Google will discontinue Universal Analytics on July 1, 2023. After the sunset date, Universal Analytics will no longer receive data and will finally stop operating.

To start, provide a property name, reporting time zone, and currency. Then, click the Next button.

Enter a Property Name

On the next screen, choose an Industry category from the dropdown menu for your website and a Business size from the options given.

Enter Business Information

Next, scroll down and choose how you want to utilize Google Analytics in your business, such as measuring engagement, optimizing advertising costs, increasing conversions, and more.

You can choose multiple or all available options to fit your requirements. When you’re done, click the Create button.

Select Intend to Use Google Analytics

After you click the Create button, a popup window will appear with the Google Analytics terms of service agreement.

Simply check the box next to I also accept the Data Processing Terms as required by GDPR, and click the I Accept button.

Accept Terms of Service Agreement

Following that, you’ll see a popup with options for which Google Analytics communication emails you want to receive.

Simply check the boxes for the updates you wish to receive and then click the Save button.

Communication Emails Options

Set Up a Data Stream in Google Analytics

Step 4: You will now be shown with your Google Analytics Webs stream options.

Since we’re installing Google Analytics for a WordPress site, select Web as the platform.

Choose Web Platform

Then, enter your website URL and Stream name.

Google Analytics will have the Enhanced measurement option activated by default. This enables Google Analytics to track page views, scrolls, outbound clicks, file downloads, and other metrics.

Then, click the Create stream button.

Set Up Your Web Stream

You may now see your Stream URL, name, and Measurement ID.

Additionally, it will display various enhanced measurements that it will record.

Web Stream Details

Under the View tag instructions, Google Analytics will show you two ways to add Google Analytics code to your WordPress website.

View Tag Instructions

You can use a website builder or content management system (CMS) to finish setting up automatically or install your tag manually.

When you choose the Install manually option, you’ll see the Google Analytics tracking code.

Google Analytics Tracking Code

You can copy this code because it will be required on your WordPress site based on the method you choose below.

Now that you’ve created a Google Analytics account let’s look at how to install Google Analytics in WordPress.

How to Add Google Analytics to WordPress

There are a few different ways to set up Google Analytics in WordPress. We will show you three methods to add Google Analytics to WordPress. You can select the one method that best meets your requirements.

Method 1: Use a Google Analytics WordPress Plugin – MonsterInsights

MonsterInsights, with over 3 million active installations, is the #1 Google Analytics plugin for WordPress. It is the simplest and best method to add Google Analytics to WordPress (for all users, beginners, and experts alike).

Additionally, it has Dual Tracking features that enable you to install Google Analytics 4 and Universal Analytics without changing any code to your WordPress website.

MonsterInsights - The Best Google Analytics Plugin for WordPress

MonsterInsights is available as a premium paid plugin and a free version. For this guide, we’ll use the free version of MonsterInsights.

To start using MonsterInsights, first, you need to install and activate the MonsterInsights plugin. For more in detail, check our guide on how to install a WordPress plugin.

After you activate the plugin, it will add a new menu item to your WordPress admin menu called Insights and display a welcome screen. Simply click the Launch the Wizard button.

MonsterInsights Setup Wizard

Once you click on it, the MonsterInsights setup wizard will launch.

First, you will be prompted to choose a category for your website (a business website, blog, or online store). Choose one and then click the Save and Continue button.

Choose Website Category

The next step is to connect MonsterInsights to your WordPress website.

Simply click the Connect MonsterInsights button.

Connect MonsterInsights

This will send you to Google Accounts, where you can sign in or select a Google account if you are already signed in.

Select a Google Account to Connect MonsterInsights

Now, select your Google account or sign in with your email to continue.

Choose a Google Account to Sign in

You will then be asked to give MonsterInsights access to your Google Analytics account.

To proceed, click on the Allow button.

Allow MonsterInsights to Access Your Google Analytics Account

The next step in finishing the connection is to choose the profile you want to track.

To continue, pick your website and then click the Complete Connection button.

Select Your Website Profile to Complete Setup

Then, to continue, simply click the Complete Connection button. MonsterInsights will immediately install Google Analytics on your website.

After that, you will be asked to select the recommended website settings.

Recommended Settings for Google Analytics

The default settings work for most websites. If you’re using an affiliate link plugin, you’ll need to include the path to hide affiliate links. This will enable you to track your affiliate links in Google Analytics.

Also, MonsterInsights will ask who may see the reports. You can select from a variety of WordPress user roles. When finished, click Save and Continue to save your changes.

After that, MonsterInsights will show the list of website tracking features you can enable.

You can scroll down and click the Continue or Skip for Now option.

Enable Website Features

MonsterInsights will display that you’ve successfully set up Google Analytics tracking on the following screen.

As you can see, Google Analytics is now set up, tracking code is installed, and data is being collected.

Tracking and Analytics are All Setup

Scroll down and click the Complete Setup without Upgrading option for now.

You’ve successfully integrated Google Analytics into your WordPress website.

Set Up the Measurement Protocol API Secret

MonsterInsights will be able to measure events like eCommerce purchases, form conversions, and more thanks to Measure Protocol API Secret.

To start, log in to your Google Analytics account. Then go to the Admin settings page and click Data Streams.

Then you’ll see your Data Streams.

Simply select the data stream that you connected to MonsterInsights.

Select Data Stream

Find the Advanced Settings section by scrolling down on the next screen.

Then click the Measure Protocol API Secrets option.

Select Measurement Protocol API Secrets

A new window will now appear with your Measurement Protocol API Secrets. This page will be blank, and you will not have any API secrets.

Simply click the Create button.

Create API Secret Key

Next, enter a nickname for your API secret.

After that, simply click the Create button.

Enter a Nickname For Your API

Now, your API secret will be created.

Next, copy the API key shown in the Secret Value field.

Copy Secret Value

You must then enter the Secret Value in MonsterInsights.

To do so, navigate to Insights » Settings in your WordPress admin panel and then click the General tab.

General Settings Tab in MonsterInsights

Then navigate to the Google Authentication section and enter the Secret Value in the Measurement Protocol API Secret field.

Enter Measurement Protocol API Secret in MonsterInsights

You have successfully set up the Measurement Protocol API Secret.

Now, if you have a Universal Analytics account, let’s look at how to use dual tracking in MonsterInsights.

How to Set Up Dual Tracking in Universal Analytics

If you have a Universal Analytics account, MonsterInsights’ Dual Tracking feature allows you to track both Universal Analytics and Google Analytics 4. The best part is that no code needs to be changed.

Remember that Universal Analytics will stop working on July 1, 2023. You won’t be able to continue tracking your website data after that date. We strongly advise you to create a Google Analytics 4 property today and begin providing data to GA4.

To enable dual tracking, navigate to Insights » Settings from your WordPress dashboard and then click the General tab.

General Settings Tab in MonsterInsights

After that, scroll down to the area labeled Google Authentication.

Enter the Universal Analytics (UA) code in the Dual Tracking Profile field.

Enter Your UA Code

You can find the Universal Analytics code by going to the Admin settings page in Google Analytics.

Next, under the Property column, click Property Settings.

You’ll see your Tracking Id under the Basic Settings.

Find Your Tracking Id

That’s it! You’re now successfully tracking Universal Analytics with Google Analytics 4 on your WordPress site. Remember that Google Analytics will take some time to display your statistics.

The best feature of MonsterInsights is that it allows you to access your Google Analytics reports from within your WordPress dashboard. Simply go to the Insights » Reports tab to summarize your analytics data quickly.

Google Analytics Report in WordPress Dashboard

Method 2: Use an Insert Headers and Footers WordPress Plugin

This method is less effective than MonsterInsights because you will be unable to perform advanced tracking configuration and see Google Analytics data in your WordPress dashboard.

First, you must copy the Google Analytics tracking code you copied in Step 4 when setting up a Google Analytics account.

You can find this code in the Web stream details under the View tag instruction section.

Google Analytics Tracking Code

Next, install and activate the Insert Headers and Footers plugin. For more in detail, check our guide on how to install a WordPress plugin.

Upon activation, go to the Settings » Insert Headers and Footers page. After that, you need to paste the code into the Scripts in Header section.

Adding Google Analytics Tracking Code in WordPress Using Headers and Footers Plugin

Don’t forget to save your changes to store your settings.

Method 3: Adding Google Analytics to WordPress Without Plugin

This method is for experienced users who are already familiar with the code. It’s unreliable because your code will be lost if you switch or change the theme.

We never suggest using this method.

If you’re adding code for the first time to your WordPress files, you should first make a backup of your website.

You can use UpdraftPlus to create a complete backup of your WordPress site. It also uploads your backups to Dropbox, Google Drive, S3, Rackspace, FTP, SFTP, email, and several other cloud storage services. See your list of best WordPress backup plugins.

First, copy the Google Analytics tracking code you copied earlier in Step 4. It is displayed in the Web stream details section under the View tag instruction section.

There are two ways to add this code to your WordPress theme files. You may select either of them (not both).

1. Add Google Analytics to WordPress header.php File

Simply edit the header.php file and add the Google Analytics tracking code you copied previously just after the body HTML tag.

Once done, save your changes and re-upload the file to your server.

2. Add Google Analytics to WordPress Functions.php File

Additionally, you can add tracking code for Google Analytics to the WordPress functions.php file. It will then add the tracking code to every page on your WordPress site.

Conclusion

Google Analytics is a sophisticated free web analytics tool that collects vital information about your website’s performance and target audience. Gaining web analytics insights allows you to make data-driven decisions to build your WordPress website efficiently.

There are three methods to install Google Analytics to a WordPress website:

  • Using a Google Analytics WordPress plugin — We highly recommend using MonsterInsights for this job.
  • Using a WordPress plugin — Use Insert Headers and Footers plugin to add a Google Analytics tracking code.
  • Adding it manually — Adding a code snippet along with the tracking code to the functions.php or header.php file.

We hope this guide helps you to know how to add Google Analytics to WordPress. You might also like to read our step-by-step guide on: