set up Google Analytics in WordPress

When it comes to optimizing and properly marketing a website, few things are as valuable as knowing your audience and how they interact with your content. This information can inform nearly every business decision you make. That’s why it’s a smart idea to set up Google Analytics in WordPress.

Google Analytics is one of the best solutions on the market for gathering data about your website’s visitors. Many users struggle to integrate Google Analytics with WordPress, but thanks to plugins, it can actually be a simple task.

In this article, we’ll explore Google Analytics and its benefits. Then we’ll walk through three different methods for adding this key tool to your WordPress site, including two completely code-free solutions. Let’s get started!

📚 Table of contents:

An introduction to Google Analytics

Google Analytics is a powerful platform that enables users to dive deep into their website’s audience, traffic patterns, and more. It’s easy to use and, perhaps best of all, free.

Google Analytics works by embedding a tracking code on your site (usually in the header, so that it’s present on every page). It then uses that code to log details about each visitor to your site, including:

  • Where they arrive from
  • Which pages they land on and leave from
  • The pages they visit and how long they spend there
  • Their demographic information (such as age, gender, and interests)
  • Other activities (for example, clicking on specific links)

You can also segment this data for even finer detail. The result is a powerful portrait not just of the volume of traffic your site receives, but also the behavior of those visitors. This information can then be used to inform all manner of business decisions, from marketing strategy to which blog posts you’ll feature on your home page.

Three ways how to set up Google Analytics in WordPress

It’s relatively easy to set up Google Analytics in WordPress. However, if you’ve never dealt with code or dived into the HTML that makes up your site, adding the tracking code can be intimidating. For that reason, several plugins exist to simplify the process by automatically embedding that code.

In the following sections, we’ll walk through setting up this integration using two of the best WordPress Google Analytics plugins, as well as by adding the code manually. Note that these methods all assume you’ve already signed up for a Google Analytics account and completed the initial setup process – including setting up a web property to add your site to Google Analytics. If you haven’t done that yet, head over to the Google Analytics site and sign up first.

1. Install Google Analytics using the GA Google Analytics plugin

GA is a lightweight, fast, and free plugin that links your WordPress website with Google Analytics. By using it, you can log in anytime to check out your site’s stats. To make it work, you just need to add your Google Analytics tracking code and the plugin does the rest. GA is up to date with all the Google Analytics features and tracking methods. Moreover, it gives you the option to add the tracking code to the footer, header, and WordPress pages.

To get started with the Google Analytics functionality in the GA plugin, head to your WordPress dashboard and install the plugin. Once it’s activated, navigate to Settings > Google Analytics:

Set up Google Analytics in WordPress via the GA plugin dashboard page.

On this page, the plugin offers you the instructions to enable Google Analytics on your site. In How to Use section, you will see all the steps that you need to follow.

But, beforehand, you have to create a Google Analytics account if you don’t already have one. If you do have an account, skip this part.

Once you’ve created your Google Analytics account or assuming you already had one, click on the Plugin Settings section, as per the plugin’s instructions. Enter your GA tracking code (that you can find in your Google Analytics admin dashboard), choose the desired tracking method, select the tracking ID location, and configure the other remaining settings as you wish.

GA plugin settings - set up Google Analytics

Save the changes and you’re done.

⚠️ Note: The stats won’t appear in your Google Analytics dashboard immediately, you will have to wait around 24-48 hours before you can see the data.

If you’re not happy with the settings you selected, you can always restore the plugin to default by going to the Restore Defaults section and clicking on the provided link.

2. Install Google Analytics using the MonsterInsights plugin

The second method we’ll explore is using the MonsterInsights WordPress plugin, a popular solution for implementing Google Analytics in WordPress. In addition to helping you set up Google Analytics, the plugin also lets you view important statistics without leaving your WordPress dashboard.

To get started, head to your WordPress dashboard and install and activate the plugin. After activation, you’ll be presented with a welcome screen. Scroll down a bit until you see the Launch the Wizard! button:

The MonsterInsights welcome page.

This button opens a setup wizard that helps walk you through the process. First, you’ll be asked to select a category for your site, which determines some of the default settings you’ll start with.

After that, you’ll be asked to Connect MonsterInsights, which is what syncs your site with Google Analytics:

Connect MonsterInsights to set up Google Analytics in WordPress

After that, you’ll be asked to enter your Google Analytics account information (or choose the associated Google account from a list):

Choose Google account

Once that’s done, give MonsterInsights the requested permissions:

You can set up Google Analytics in WordPress once you give Google access

Then, you can choose your website from a list of Google Analytics web properties. If you don’t see your site, remember that you need to set up a property in Google Analytics first:

Choose your site

⚠️ Note: It can take up to 24 hours for the data to start flowing between the two services. However, once it does, you can view your site’s stats from either the Google Analytics website or your WordPress dashboard.

The basic MonsterInsights plugin is free to use. You can also upgrade to a premium version, which starts at $79.56 per year, but do note that this is the current promo price and could increase in the future. The premium MonsterInsights offers some additional features such as more advanced dashboard tools and integrations with other WordPress plugins.

3. Install Google Analytics in WordPress manually

The final option we’ll cover here is the most basic, but also the most complicated to implement: manually adding the required tracking codes to your WordPress site. If you go with this approach, it’s essential that you use a WordPress child theme. Otherwise, your Google Analytics code will be overwritten every time you update your theme.

In addition, since you’ll be making changes to your website’s core files, it’s a good idea to back up your site before getting started.

To add the Google Analytics tracking code to your WordPress theme manually, you’ll need a piece of code known as the “Global Site Tag.” You can find this in your Google Analytics admin dashboard. Locate Tracking Info from the list of options, and then select Tracking Code:

The tracking code in the Google Analytics settings.

On the next page, you’ll be presented with your Tracking ID, and below that you’ll find the code you need:

The Google Analytics Global Site Tag to enable integration with WordPress.

Copy that code and paste it somewhere safe (or just leave the tab open).

Now, head back to your WordPress dashboard and navigate to Appearance > Theme Editor. This is a built-in code editor for the files that comprise your WordPress theme.

In the sidebar to the right, locate the file labeled Theme Header (header.php) – make sure you choose the file from your child theme. If you don’t see a header.php file in your child theme, you can add it by manually copying it from the parent theme folder to the child theme folder. Click on this file to open it in the main editor window:

The header.php file in the WordPress Theme Editor.

Paste the Global Site Tag you copied earlier into this file, directly below the opening <body> tag. Click on Update File to save the changes. You’ve now added the Google Analytics tracking code manually!

Frequently asked questions about Google Analytics and WordPress

Before we wrap up, let’s address some of the most frequently asked questions about using Google Analytics on your WordPress site.

Does Google Analytics work with WordPress?

Yes! There are multiple ways to integrate Google Analytics with WordPress, but all end with the same result: your WordPress site’s stats will be tracked and aggregated in the Google Analytics dashboard.

How do I use Google Analytics in WordPress?

First, you’ll need a free Google Analytics account. Then you can integrate that account with your website, using one of several methods.

The simplest way to use Google Analytics with WordPress is via a plugin. There are several options available, one quality solution is GA. It’s a free plugin that offers simple and quick Google Analytics integration, plus several other features such as Google Analytics tracking techniques, integration with all Google Analytics features, options for tracking code location, custom tracking code, and more.

You can also implement Google Analytics on your WordPress site manually, by copying and pasting some code into your theme files. However, this method is riskier and less reliable than using a plugin.

How do I add Google Analytics to my free WordPress blog?

You can use Google Analytics no matter what type of website you have. Whether you’re running a free blog, a membership site, or an ecommerce store, you can use the methods listed above to set up Google Analytics and track your visitors.

What is the best Google Analytics plugin for WordPress?

We recommend GA or MonsterInsights to set up Google Analytics on WordPress. The former is excellent for simple, straightforward integration. It is free and supports all the Google Analytics updates and tracking methods. Its premium version comes with advanced features like multiple tracking codes, custom tracking, visitor opt-out boxes, and more.

Either plugin will work just fine for Google Analytics integration. Choosing one is simply a matter of weighing your needs versus the cost.

Conclusion

Whether your website is a hobby or a key business asset, knowledge is power. Few platforms offer the amount of knowledge that Google Analytics does, and integrating it with your WordPress website can help you take your traffic and revenue to the next level.

There are several ways to set up Google Analytics in WordPress. You can opt for a plugin such as MonsterInsights or GA, or you can go the DIY route and add the integration manually by editing theme files as long as you use a child theme. Either way, you’ll get access to some of the best analytics on the market combined with the power of WordPress.

Once you’ve added Google Analytics to your WordPress site, we also have some other guides to help you get the most from Google Analytics:

Do you have any questions about using Google Analytics with WordPress? Let us know in the comments section below!

Free guide

4 Essential Steps to Speed Up
Your WordPress Website

Follow the simple steps in our 4-part mini series
and reduce your loading times by 50-80%. 🚀

Free Access

0 Comments
Inline Feedbacks
View all comments

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!