How to Add Google Analytics Tag to WordPress
Adding Google Analytics to your WordPress site is one of the most important first steps for understanding who your visitors are and how they interact with your content. It unlocks a wealth of data you can use to grow your business, improve your user experience, and make smarter decisions. This guide will walk you through several easy methods for getting your analytics tag set up correctly.
First, Get Your Google Analytics 4 Tag
Before you can add analytics to WordPress, you need the actual tracking tag from your Google Analytics account. Google Analytics 4 uses a single "G-" Measurement ID and a corresponding JavaScript snippet (called the global site tag or gtag.js) to track your website's traffic.
If you already have a Google Analytics account, finding your tag is simple. If you don't, you'll need to create a free account and a new GA4 property for your website first.
Here’s how to find your existing GA4 tag:
Log in to your Google Analytics account.
Click the Admin icon (the gear) in the bottom-left corner.
In the Property column, make sure your desired website property is selected.
Click on Data Streams and then select the data stream for your website.
Here you'll see your Measurement ID, which looks like G-XXXXXXXXXX. Some tools only need this ID. You'll also see an option to View tag instructions. Clicking this will give you the full global site tag snippet, which is the complete JavaScript code you'll need for manual installation.
The full code snippet looks something like this:
Depending on the method you choose below, you'll either need just the Measurement ID or this full code snippet. It's a good idea to copy both and have them ready.
3 Easy Ways to Add Google Analytics to WordPress
There are several ways to install your GA4 tag, but they generally fall into three categories. We'll start with the easiest method (using a plugin) and move to the more hands-on approaches for those who want more control.
Method 1: Use a Plugin (The Easiest Way for Beginners)
For most WordPress users, using a dedicated plugin is the simplest and safest way to add Google Analytics. You won’t need to touch any code, the setup is guided, and you often get the added benefit of seeing your basic traffic reports right inside your WordPress dashboard.
Using Site Kit by Google
Site Kit is the official WordPress plugin from Google. It not only connects Google Analytics but also integrates other key Google services like Search Console, PageSpeed Insights, and AdSense, giving you a centralized performance dashboard.
Step 1: Install and Activate Site Kit
In your WordPress dashboard, go to Plugins > Add New. Search for "Site Kit by Google," click "Install Now," and then "Activate."
Step 2: Connect Your Google Account
Once activated, you’ll see a prompt to begin the setup. Click "Start Setup" and follow the instructions to sign in with the Google account associated with your Analytics property.
Step 3: Verify Ownership and Grant Permissions
Site Kit will walk you through a few steps to verify that you own the website (usually automatically via Search Console) and ask for permission to access your Google account data. Granting permission allows it to pull reports into your dashboard.
Step 4: Connect Analytics
During the setup, Site Kit will automatically detect your Google Analytics account. All you have to do is select the correct property and data stream from the dropdown menus. Once you confirm, Site Kit will automatically place the tracking tag on every page of your site.
That's it! Site Kit handles everything for you and will start displaying data in your WordPress dashboard within a day or two.
Using MonsterInsights
MonsterInsights is another incredibly popular and user-friendly plugin for Google Analytics. Its setup process is just as simple as Site Kit's, but it's focused entirely on Analytics and offers more detailed in-dashboard reports and advanced tracking features.
In your WordPress dashboard, navigate to Plugins > Add New.
Search for "MonsterInsights," then click "Install Now" followed by "Activate."
Launch the setup wizard. It will guide you through connecting your WordPress site with your Google Analytics account via a similar authentication process as Site Kit.
Once connected, MonsterInsights automatically adds the proper tracking code to your site. You don't need to copy or paste anything.
The main benefit of MonsterInsights is the depth of its in-dashboard reporting, which lets you see detailed traffic sources, top-performing pages, and audience demographics without ever leaving WordPress.
Method 2: Manually Add the Tag to Your Theme (For Coders)
If you're comfortable editing theme files and want to avoid adding extra plugins, you can insert the GA4 global site tag directly into your theme's header.php file.
Warning: This method is recommended only for advanced users. Editing theme files directly can break your site if done incorrectly. It's highly recommended that you use a child theme for this. If you don't, any changes you make will be erased the next time you update your theme.
Copy the Global Site Tag
First, from your GA4 Data Stream settings (as shown in the first section), copy the entire gtag.js code snippet.
2. Navigate to the Theme File EditorIn your WordPress dashboard, go to Appearance > Theme File Editor. You'll see a warning about editing theme files directly - proceed with caution.
3. Find Your header.php FileOn the right-hand side, under "Theme Files," find and click on the file named Theme Header (header.php). Make sure you're editing your child theme, not your parent theme.
4. Paste the CodeScroll through the code until you find the closing </head> tag. Paste your entire Google Analytics tracking code snippet on a new line just before this closing tag.
5. Update the FileClick the "Update File" button to save your changes. The GA4 tag is now active on your site.
Method 3: Use a Code Snippets Plugin (The Safest Manual Method)
If you want a manual approach without the risks of editing theme files directly, a code insertion plugin like WPCode - Insert Headers and Footers is the perfect middle ground. It gives you a dedicated place to add scripts like the GA4 tag without having to touch your theme's core files.
This approach has a few key advantages:
It's much safer than direct theme editing.
Your code snippets are stored independently, so you can change your theme without having to reinstall your GA tracking code.
The interface is clean and dedicated to one purpose: adding code.
Here’s how to do it:
Install the plugin: In your dashboard, go to Plugins > Add New, search for "WPCode," and install and activate the plugin.
Go to the Header & Footer Page: After activation, a "Code Snippets" menu will appear. Go to Code Snippets > Header & Footer.
Paste Your Global Site Tag: Copy the complete
gtag.jssnippet from your Google Analytics account and paste it into the "Header" box.Save your changes, and you're all set. The plugin will now inject your analytics code into the header of every page on your site.
How to Verify That Your Tag is Working
After installing your Google Analytics tag, it's a good idea to confirm it's firing correctly. The quickest way to do this is with the Realtime report in Google Analytics.
Log in to Google Analytics and navigate to your property.
Go to Reports > Realtime.
In a new browser window or tab, open your website and click around to a few pages.
After 30-60 seconds, you should see your own visit pop up in the Realtime report. The "Users" count should switch to at least 1, and you'll see your current location show up on the map.
If you see your activity, you've successfully installed your GA tag! Data will now begin populating your reports, though it can take 24-48 hours for the standard reports to fully update.
Final Thoughts
Adding Google Analytics to your WordPress site is a non-negotiable step for any serious website owner. Whether you choose the simplicity of a plugin like Site Kit or the control of adding the code manually, the process is straightforward and paves the way for making informed, data-driven decisions that will help your site grow.
Once you’ve set everything up and data is collecting, we built Graphed to help with the next step: actually understanding it all. You can connect your Google Analytics account and use plain English to ask questions and instantly build custom dashboards. Instead of getting lost in default reports, you can just ask, "Show me my top 10 blog posts from last month by new users" and get a clear visualization in seconds, turning that raw data into actual insights.