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. 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
The most straightforward way to add Google Analytics to your WordPress website is with a WordPress plugin. There are lots of popular options to choose from, including Site Kit by Google, MonsterInsights, ExactMetrics, and Analytify.
Since 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.
-
Log in to wordpress.org.
-
From the sidebar of your WordPress dashboard, click Plugins.
-
Click Add New Plugin.
-
In the search bar next to Search Plugins, enter Site Kit.
-
From the list of results, click Install Now next to the plugin you want to add—in this case, it’s Site Kit.
-
Once installed, the Install Now button will change to Activate. Click Activate.
-
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.
-
Click the checkbox next to Connect Google Analytics as part of your setup, and then click Sign in with Google.
-
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.
-
Click Next.
-
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
-
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.
-
Go to analytics.google.com.
-
In the sidebar, click Admin.
-
In the Data collection and modification widget, click Data streams.
-
Click the data stream you want to use.
-
Click View tag instructions.
-
Click the Install manually tab to reveal your Google Analytics script (tracking code).
-
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
-
Go to wordpress.org.
-
In the sidebar, click Appearance, and then select Theme File Editor.
-
You’ll be warned about editing your theme. Click I understand to continue.
-
From the Theme Files sidebar, click Theme Header (header.php).
-
Paste the Google Analytics code you previously copied above the closing head tag:
</head>
. -
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. 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.
-
Go to wordpress.org.
-
In the sidebar, click Appearance, and then select Theme File Editor.
-
From the Theme Files sidebar, click Theme Functions (functions.php).
-
Paste the Google Analytics code you previously copied in the text box before the closing
</script>
tag. -
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, you can automatically do things like track form submissions or payments on your site. For more inspiration, check out ways you can automate your data analytics. Or use one of these pre-made templates to get started.
Related reading:
This article was originally published in March 2019 by Justin Pot. The most recent update was published in September 2024.