---
title: "How to add Google Analytics to WordPress"
description: "When you add Google Analytics to WordPress, you'll get real-time data on your website's audience and their behaviors. Here's how to set it up."
image: "https://images.ctfassets.net/lzny33ho1g45/35AyaIhLYULgCzUA3g8AyY/62b277a5b9ce915d8a937eb23fead7f9/WordPress.jpg"
---

# How to add Google Analytics to WordPress

When you add Google Analytics to WordPress, you'll get real-time data on your website's audience and their behaviors. Here's how to set it up.

Whatever the purpose of your WordPress website—be it to sell services or products, host a blog, or just show the world how gorgeous your dog is—the only way to tell if it's having an impact is by digging into the data. 

Want to know how many people visited your website in the last month? Or what brought users to your site in the first place? Google Analytics can tell you all of this—and then some. 

When you add Google Analytics to your WordPress site, you get real-time data on metrics that will help you better understand your audience and their behaviors—for example, traffic sources, user behavior, and demographics. 

Here, I'll show you how to add Google Analytics to your WordPress website, step by step. 

## How to add Google Analytics to WordPress

Before we get started, you'll need to [register for a free Google Analytics account](https://support.google.com/analytics/answer/9304153?). Once you've set that up, you have two options for adding Google Analytics to your WordPress page. 

- [How to add Google Analytics to WordPress with a plugin](#plugin)
- [How to add Google Analytics to WordPress manually](#manual)

## How to add Google Analytics to WordPress with a plugin

The most straightforward way to add [Google Analytics](https://zapier.com/blog/how-to-use-google-analytics/) to your WordPress website is with a [WordPress plugin](https://zapier.com/blog/best-wordpress-plugins/). There are lots of popular options to choose from, including Site Kit by Google, MonsterInsights, ExactMetrics, and Analytify. 

Since [Site Kit](https://wordpress.org/plugins/google-site-kit/) is the official Google Analytics plugin for WordPress, we'll use that one. It's free, provides reliable data from multiple Google products, and apart from granting the necessary permissions, it doesn't require any other manual effort on your end. 

1. Log in to [wordpress.org](http://wordpress.org).
2. From the sidebar of your WordPress dashboard, click **Plugins**.
3. Click **Add New Plugin**.

4. In the search bar next to _Search Plugins_, enter **Site Kit**.
5. From the list of results, click **Install Now** next to the plugin you want to add—in this case, it's Site Kit.
6. Once installed, the _Install Now_ button will change to _Activate_. Click **Activate**.

7. Once activated, the plugin will appear in your WordPress dashboard. From the sidebar of your WordPress dashboard, click **Site Kit **to set up the plugin.
8. Click the checkbox next to _Connect Google Analytics as part of your setup_, and then click **Sign in with Google**.

9. Complete the sign-in process by verifying that you own your website and giving Google and Site Kit the required access, including access to your Search Console.
10. Click **Next**.

11. Site Kit will immediately connect with Google Analytics and display the account information in the connected Google Analytics account. If everything looks good, click **Complete setup**.

That's it. Now you can access your site's data directly from your WordPress backend. 

## How to add Google Analytics to WordPress manually

If you prefer to not install a WordPress plugin, and you have the technical expertise, you can also add Google Analytics to WordPress manually. To do this, you'll need to install your Google Analytics tracking code to WordPress. 

But first, let's quickly cover some of the reasons why you might _not_ want to go this route: 

- The setup can be tedious and time-consuming.
- You stand the risk of getting inaccurate data if the code isn't installed properly.
- You can't track your site's data directly in WordPress—you'll need to open your Google Analytics dashboard to do this.
- A theme update can easily erase the code, forcing you to redo it.
- You won't have access to advanced features offered by plugins.

If I haven't scared you off, then let's continue. 

### How to find your Google Analytics tracking code 

1. Back up your WordPress website. This step is optional but highly recommended before making any changes to your site's theme because any mistakes can break your site.
2. Go to [analytics.google.com](http://analytics.google.com).
3. In the sidebar, click **Admin**.

4. In the _Data collection and modification_ widget, click **Data streams**.

5. Click the data stream you want to use.

6. Click **View tag instructions**.

7. Click the **Install manually** tab to reveal your Google Analytics script (tracking code).

8. Click the **Copy** icon, which looks like two overlapping rectangles, in the script box.

Google Analytics tracking code in hand, you now have two options for adding it to your WordPress website: 

- [How to add the Google Analytics tracking code to your website's header.php file](#header)
- [How to add the Google Analytics tracking code to your website's functions.php file](#functions)

### How to add the Google Analytics tracking code to your website's header.php file 

1. Go to [wordpress.org](http://wordpress.org).
2. In the sidebar, click **Appearance**, and then select **Theme File Editor**.

3. You'll be warned about editing your theme. Click **I understand** to continue.

4. From the _Theme Files_ sidebar, click **Theme Header (header.php)**.

5. Paste the Google Analytics code you previously copied above the closing head tag: `</head>`.

6. Click **Update File**.

You're all set. 

### How to add the Google Analytics tracking code to your website's functions.php file

Unlike adding your Google Analytics code to your header.php file, I recommend first installing a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/). This will help preserve your existing design after updating your site's parent theme. 

Once you've set that up, you can install your code. 

1. Go to [wordpress.org](http://wordpress.org).
2. In the sidebar, click **Appearance**, and then select **Theme File Editor**.
3. From the _Theme Files_ sidebar, click **Theme Functions (functions.php)**.

4. Paste the Google Analytics code you previously copied in the text box before the closing `</script>` tag.

5. Click **Update File**.

## Automatically monitor your site's performance 

Tracking your site data is one thing, but if you want a more holistic view, you'll want to gather data from other apps connected to your site. With [Zapier's Google Analytics 4 integration](https://zapier.com/apps/google-analytics-4/integrations), you can automatically do things like track form submissions or payments on your site. Learn [how to automate Google Analytics](https://zapier.com/blog/automate-google-analytics/), or use one of these pre-made templates to get started.

**Related reading**: 

- [How to uninstall a WordPress plugin (completely)](https://zapier.com/blog/uninstall-wordpress-plugin/)
- [GA4 vs. Universal Analytics: What's new in Google Analytics 4?](https://zapier.com/blog/ga4-vs-universal-analytics/)
- [WordPress.com vs. WordPress.org: What's the difference?](https://zapier.com/blog/wordpress-org-vs-wordpress-com/)
- [How to set up Google Analytics to track your website](https://zapier.com/blog/how-to-set-up-google-analytics/)

_This article was originally published in March 2019 by Justin Pot. The most recent update was published in September 2024._