How to add Google Analytics in WordPress

Struggling with how to add Google Analytics in WordPress?

If you want to understand where your site's visitors come from and what they do on your site, Google Analytics is one of the most popular solutions. It's free and gives you incredibly detailed web analytics data, which is a pretty compelling value proposition for most people.

However, in order to add Google Analytics to your WordPress site, you need to add a tracking code snippet to your site in addition to registering for your Google Analytics account. If you're not a developer, working with a code snippet like this can be a little confusing.

Don't worry - we're here to help!

In this post, we're going to show you how to add Google Analytics in WordPress using three free methods that you can choose according to your needs and knowledge level:

  1. Lightweight plugin for just the tracking code - a simple plugin that lets you add the Google Analytics tracking script to your site and configure a few other basic settings.
  2. Feature-rich plugin that includes in-dashboard stats - an official plugin from Google that lets you both add the tracking script and view statistics from Google Analytics without leaving your WordPress dashboard.
  3. Manual code snippet - you can add the code directly to your theme. This is a little more complicated, but it eliminates the need to use a plugin.

All of these methods are 100% free, so you won't need to pay for anything that we cover in this article.

But first, let's talk about the basic setup you need to do before you can start adding Google Analytics to WordPress.

What you need to do before adding Google Analytics in WordPress

To help understand how to add Google Analytics in Wordpress, we’ve put together some tutorials below. The only thing that we'll assume is that you've already registered for a Google Analytics account and added your website as a web "property" in the Google Analytics dashboard.

That is, no matter which method you use below, you'll need to have set up your Google Analytics account first. If you haven't created your Google Analytics property yet, here's a quick guide.

If you're only adding analytics to a WordPress site, we recommend using a Google Analytics Universal Analytics (AKA Google Analytics 3) property instead of the newer Google Analytics 4 (which helps you measure both web and app data, which most WordPress sites don't need).

The reasons are a bit complex, but the basic idea is that Google Analytics 3 (Universal Tracking) is a better choice for most WordPress sites at this time. For example, Google Analytics 4 doesn't currently support bounce rates and it doesn't integrate with Google Search Console, among some other notable limitations that might affect WordPress sites.

To begin, go to the Google Analytics homepage and log in using your existing Google account. Then, click the Start measuring button.

First, you'll need to enter an account name and choose a few details:

Google Analytics setup

Then, you'll need to add your WordPress website as a "Property". In the Property setup section, expand the advanced options and enable the toggle to Create a Universal Analytics property. There, you can enter the direct URL of your site.

Select the option to Create both…, which will give you the option to still collect Google Analytics 4 data. Then, click Next:

Google Analytics property setup

On the last page, answer a few questions about your site and click Create:

Google Analytics Business information form

You should now be in the Google Analytics dashboard. Use the drop-down at the top to select your Universal Tracking property. It's the one that does not have "GA4" next to it:

Google Analytics Dashboard

To find your Google Analytics tracking code, click on the gear icon in the bottom-left corner and then select Tracking Code under Tracking Info:

Google Analytics tracking code

You'll now see a screen with your Tracking ID and Global Site Tag. You'll need this information for some of the methods below, so keep it handy:

Google Analytics tracking ID

For more details, check out Google's "Get started with Analytics" documentation.

3 simple methods on how to add Google Analytics in WordPress

Once you've added your WordPress site as a property in Google Analytics, you can use one of the methods below to add the Google Analytics tracking code to WordPress.

You only need to choose one method - you don't need to do all three. However, it’s a good idea to read through all three methods before starting so that you can pick the one that works best for you.

Method 1: Lightweight Plugin - GA Google Analytics

If you just want to add the Google Analytics tracking script to your site and you're fine with viewing actual analytics data in the Google Analytics dashboard, the free GA Google Analytics plugin is the best option for you.

To begin, install and activate the free GA Google Analytics plugin from WordPress.org.

Then, go to Settings → Google Analytics and expand the Plugin Settings to configure the plugin as follows:

  • GA Tracking ID - paste in your tracking ID - e.g. UA-213146654-1. We showed you where to find this in the previous section.
  • Tracking Method - leave as Universal Analytics.

You can leave all other settings as the defaults. However, you might want to check the Admin Users box to disable tracking WordPress admin users. This will prevent you from accidentally polluting your analytics data with your own actions when you're working on your site.

To finish, click the Save Changes button:

Google Analytics plugin settings

And that's it! You just added Google Analytics to WordPress - your site's data should start showing up in the Google Analytics dashboard shortly.

To make sure it's working, you can click the Send test traffic button in your Google Analytics dashboard:

Google Analytics send test traffic button

Method 2: Feature-Rich Plugin - Google Site Kit

If you want the ability to view your site's analytics data inside your WordPress dashboard, you can find some high-quality Google Analytics plugins that give you that option.

Sometimes the Google Analytics dashboard can feel a little overwhelming, especially if you just want basic stats. The nice thing about these plugins is that they can present your data in a way that's easier to consume and understand. If that appeals to you, this could be the best method for your needs.

There are several popular plugins that can do this, but we're going to recommend and use the Site Kit plugin because it's an official plugin that comes directly from Google. With that being said, other options worth considering here are:

Here's what it's like to set up Google Analytics with the Site Kit plugin.

1. Activate Site Kit features

To begin, install and activate the free Site Kit plugin from WordPress.org. Once you activate it, you should see a prompt to Start Setup. If you don't, you can find it by going to the new Site Kit tab in your dashboard:

Google Analytics new Site Kit tab

This will open Google's website where you'll be prompted to sign in and connect:

Google Analytics Site Kit sign in page

Now, you'll go through a few different prompts where you'll need to select your Google account and click allow. As part of the process, Google will also set up your site with Google Search Console if you haven't done so already.

Just go through and click "allow", "proceed", or "continue" where needed:

Google Analytics Site Kit permission settings page

Once you've finished connecting to Site Kit, click the Go to my dashboard button to go back to WordPress:

GA Site Kit Go to my dashboard button

2. Connect to Google Analytics

Now, in the Site Kit area of your WordPress dashboard, click the Connect Service button under Analytics:

Congrats on setting up Site Kit

This will launch another set of Google prompts where you'll need to select your Google account and give the plugin access:

Google Analytics dashboard analytics connect service

Once you give it access, you'll go back to your WordPress dashboard where you can select the Google Analytics property for your site.

The plugin should automatically detect the right property, but you'll want to make sure that it's the correct web property. Once you've verified everything, click the Configure Analytics button:

Google Analytics plugin access settings

3. View your stats in your WordPress dashboard

That's it! When you go to the Site Kit area in your WordPress dashboard, you should now see that Analytics is marked as "Connected".

What's more, you'll get a new menu at Site Kit → Analytics where you can see your site's stats without leaving your WordPress dashboard.

There won't be anything there at first, but you'll start seeing data show up here soon. Here's an example of what it looks like once you get some data:

Google Analytics Configure Analytics button

To view stats for individual pieces of content, you can:

  1. Click on them in the top content list in the backend Site Kit Analytics dashboard.
  2. Open the page on the frontend of your site and click the new Site Kit option on the WordPress toolbar.

WordPress toolbar Site Kit

Method 3: manual method - a code snippet

If you're the type of person who doesn't like installing plugins, you can also add the Google Analytics tracking script to WordPress using a code snippet that you add to your theme's functions.php file.

Because this method works with code, it's a little more complicated than the two previous plugins.

Additionally, because this method involves adding a code snippet to your theme, it's important that you use a WordPress child theme so that your changes don't get overwritten when you update your theme. Or, you can use a code snippet management plugin like Code Snippets.

Because you'll be tweaking your site's code, we also recommend creating a backup before making any changes just in case something goes wrong.

Once you have a recent backup, go to Appearance → Theme Editor and select your child theme's functions.php file.

Then, add the following code snippet:

[EMBED THIS SNIPPET FROM PASTEBIN]

Make sure to replace the example tracking ID - UA-XXXXX-Y - with your actual Google Analytics tracking ID. If you'd prefer, you can also use Google's Global Site Tag tracking snippet instead of the analytics.js method that we added to the code snippet.

Here's what the finished code might look like:

GA dashboard theme functions

That's it! You should start seeing data appear in your Google Analytics dashboard soon.

Get started with Google Analytics on WordPress today

Google Analytics gives you a free way to track where your WordPress site's visitors come from and what they do on your site.

In order to get started, you'll need to add your WordPress site as a web property in Google Analytics. Once you've done that, you can use the plugins or manual approach above to add the Google Analytics tracking script to your site and start collecting data.

Follow our how to guide within this article on how to add Google Analytics in Wordpress. As a reminder, here are our recommendations for each method:

  • Method 1: GA Google Analytics plugin - the best option for people who want a simple way to add the tracking snippet and are fine with using the Google Analytics website to view stats.
  • Method 2: Site Kit plugin - a great option for people who want to view simplified analytics data without leaving the WordPress dashboard.
  • Method 3: Manual code - a good option for people who are ok with adding a code snippet and don't want to install a dedicated WordPress Google Analytics plugin.

Still have questions about how to add Google Analytics in WordPress? Feel free to give us a shout in the comments!

About the author