How to Add Google Analytics 4 Tag to WordPress
Ready to start collecting data from your WordPress site with Google Analytics 4? Setting up tracking is the first critical step to understanding your visitors - what content they love, where they come from, and how they interact with your site. This guide will walk you through the three best ways to add your GA4 tag so you can choose the method that fits your technical comfort level.
Before You Begin: Get Your GA4 Measurement ID
No matter which method you choose, you first need your GA4 "Measurement ID." This unique identifier tells Google Analytics that the data coming in belongs to your website. If you've already created a GA4 property, you can skip to grabbing your ID. If not, here’s how to set one up in just a couple of minutes.
Sign in to Google Analytics: Go to the Google Analytics homepage and sign in with your Google account.
Navigate to Admin: Click the gear icon labeled "Admin" in the bottom-left corner of the screen.
Create a Property: In the "Property" column, click the blue "+ Create Property" button. Give your property a name (like your website's name), and set your reporting time zone and currency.
Set Up a Data Stream: Next, you'll be prompted to set up a data stream, which is just a source of data. Since you're installing this on a website, choose the "Web" platform.
Enter Your Website Details: Enter your website’s URL (e.g., www.yourwebsite.com) and a stream name (again, your website's name is fine here). Make sure "Enhanced measurement" is turned on - it automatically tracks helpful events like page views, scrolls, and outbound clicks. Click "Create stream."
Find Your Measurement ID: You'll now land on the "Web stream details" page. In the top right, you'll see your ID that starts with "G-" followed by a series of letters and numbers (e.g., G-XYZ123ABC). This is your Measurement ID. Copy it, as you'll need it for the following steps.
Now that you have your ID, you're ready to add it to WordPress.
Method 1: The Easiest Way - Using a WordPress Plugin
For most WordPress users, a plugin is the simplest and safest way to add GA4. You won't have to touch a single line of code, which eliminates the risk of accidentally breaking your site. It also ensures the tracking code stays in place even when you update your theme.
Why Use a Plugin?
No Code Required: The setup is usually just a few clicks through a user-friendly interface.
Extra Features: Many analytics plugins provide a simple dashboard right inside WordPress, so you can see your most important stats without leaving your site.
Error-Proof: It’s nearly impossible to mess up the installation, making it perfect for beginners.
Step-by-Step: Adding GA4 with Site Kit by Google
While there are many great plugins, Google's own "Site Kit" is an excellent choice. It's free, official, and connects your site not only to Google Analytics but also to Search Console, AdSense, and PageSpeed Insights.
Navigate to Plugins > Add New in your WordPress dashboard.
Search for "Site Kit by Google," then click "Install Now" and "Activate."
Once activated, you'll see a banner at the top of your dashboard. Click "Start Setup."
You'll be guided to sign in with the Google account you used to create your GA4 property. Grant the necessary permissions for Site Kit to access your data.
Site Kit will automatically verify that you own the website.
Next, it will prompt you to connect services. Click "Connect" for Google Analytics. Site Kit will find the GA4 property you just created.
Select your account and GA4 property from the dropdown menus and click "Configure Analytics."
That's it! Site Kit has now placed the necessary tracking code on your site. Analytics data will start appearing in both your Google Analytics account and your Site Kit dashboard inside WordPress within 24-48 hours.
Method 2: For More Control - Manually Adding the Tag
If you're comfortable editing theme files and prefer to keep your plugin count low, you can add the GA4 tracking code directly into your theme's header.php file. This gives you direct control over the code.
Important: Use a Child Theme!
Before you proceed, a strong word of caution: never edit your parent theme's files directly. Why? The moment your theme receives an update, all your custom changes will be overwritten and lost. A child theme inherits all the functionality and styling of its parent theme but allows you to make your own modifications in separate files that won't be affected by updates. If you don't already have a child theme, create one first.
Finding Your Global Site Tag (gtag.js)
For this method, you need the full JavaScript snippet, not just the Measurement ID. Here's how to find it:
In Google Analytics, go to Admin > Data Streams and click on your web stream.
Under "Installation instructions," click on "Install manually."
A code snippet starting with
<!-- Global site tag (gtag.js) -->will appear. This is what you need. Click the copy icon.
Adding the Code to Your Theme's header.php
In your WordPress dashboard, go to Appearance > Theme File Editor.
On the right side, under "Theme Files," select your child theme.
Click on the
header.phpfile to open it in the editor.Find the closing
</head>tag.Paste the entire Google Analytics code snippet you just copied right before the
</head>tag.Click "Update File" to save your changes.
Method 3: The Scalable Choice - Using Google Tag Manager
Google Tag Manager (GTM) is a free tag management system that acts as a middleman between your website and third-party tools like Google Analytics. Instead of adding dozens of code snippets to your site (for analytics, ads, pixels, etc.), you add just one: the GTM container. Then, you manage all your other tags from the GTM interface.
Why Use Google Tag Manager?
Keeps Your Site Clean: One script to load them all. This can help with site organization and even performance.
Empowers Marketers: It allows you to add or modify tracking tags without needing a developer or editing theme files every time.
Advanced Tracking: Easily set up powerful tracking for events like button clicks, form submissions, and video plays.
Part 1: Setting Up GA4 within Google Tag Manager
Go to the Google Tag Manager website and create an account and container for your website if you haven't already.
Inside your GTM workspace, go to Tags > New.
Name your tag something clear, like "GA4 Configuration."
Click inside the "Tag Configuration" box and choose Google Analytics: GA4 Configuration.
In the "Measurement ID" field, paste your GA4 Measurement ID (G-XXXXXXXXXX).
Next, click inside the "Triggering" box and select the All Pages trigger. This tells GTM to fire the GA4 tag on every page of your site.
Click "Save."
Part 2: Adding the GTM Container to WordPress
Your container code gives you two snippets — one for <head> and one for <body>. Like the manual method, you can place these in your child theme's header.php file.
In GTM, your container ID is visible in the top right (looks like
GTM-XXXXXXX). Click it to open the installation code.Back in WordPress, go to Appearance > Theme File Editor and select your child theme's
header.php.Paste the first snippet as high in the
<head>section as possible.Paste the second snippet immediately after the opening
<body>tag.Save the file.
Finally, go back to your GTM workspace and click the blue "Submit" button in the top right corner, then "Publish." This makes your new GA4 tag live.
Is It Working? How to Verify Your Setup
After installing your code, you'll want to make sure it's actually working. Here are two easy ways to check:
1. Use the Realtime Report
In your Google Analytics account, navigate to Reports > Realtime. Now, open your own website in a new browser tab or on your phone. Within a minute or so, you should see yourself pop up as a visitor in the Realtime report. If you see activity, your tag is installed and sending data correctly.
2. Google Tag Assistant
Another great tool is the Google Tag Assistant, which can debug your GTM and analytics installations on any given page. Simply enter your website's URL and it will show you exactly what tags fired successfully and which, if any, have errors.
Final Thoughts
Whether you choose the plug-and-play simplicity of a plugin, the direct control of a manual installation, or the scalable power of Google Tag Manager, you’re now set up to collect valuable data about your audience. This data is the foundation for making smarter marketing decisions and growing your online presence.
Once your GA4 data starts flowing, making sense of it can be the next challenge. Rather than manually pulling reports and struggling to combine GA data with insights from your ad platforms, sales tools, and e-commerce store, we built Graphed to do the heavy lifting for you. We connect all your tools in one place and let you build professional, real-time dashboards just by asking questions in plain English - no complex setup or endless spreadsheets required.