Originally published: March 31, 2025 · Last reviewed and updated: October 2026
Google Analytics 4 (GA4) shows you how people find and use your WordPress site: which pages they read, where they come from, and which actions they take. Adding it takes two parts. First you create a GA4 property in Google Analytics. Then you place the Google tag on every page of your site.
This guide explains how to add Google Analytics 4 to WordPress in 2026, compares the three main methods, and covers the settings and privacy steps most sites forget.
The Short Answer
To add Google Analytics 4 to WordPress:
- Create a Google Analytics account and a GA4 property at analytics.google.com.
- Add a Web data stream for your site’s URL and copy its Measurement ID, which starts with
G-. - Connect WordPress using one method: the free Site Kit by Google plugin, Google Tag Manager, or a header code snippet.
- Check that data arrives in the Realtime report.
- Set data retention, filter out your own visits, and add a cookie consent banner if you have visitors from regions that require it.
Before You Start
Universal Analytics, the older version, stopped processing data on July 1, 2023, so GA4 is now the only standard version of Google Analytics. If your site still has an old tracking ID that starts with UA-, remove it. It no longer collects anything and only adds code to your pages.
You also need admin access to WordPress and a Google account. If your site uses a page cache, clear it after you add the tag so visitors receive the new code.
Step 1: Create a GA4 Property and Data Stream
- Sign in to Google Analytics and go to Admin → Create → Property.
- Enter a property name, your time zone, and your currency.
- Add your business details and choose your business objectives.
- Choose Web as the platform, enter your site URL, and give the stream a name.
- Keep Enhanced measurement turned on. It automatically records page views, scrolls, outbound clicks, site search, video engagement, and file downloads.
- Copy the Measurement ID (for example,
G-XXXXXXXXXX).
Google’s own setup guide, Set up Analytics for a website, walks through the same screens.
Step 2: Choose How to Add GA4 to WordPress
| Method | Best for | Code needed | Notes |
|---|---|---|---|
| Site Kit by Google | Most site owners | None | Official free plugin; also connects Search Console |
| Google Tag Manager | Sites with several tags or custom events | Minimal | One container manages GA4, ads, and other tags |
| Header snippet | Developers who want no extra plugin | Some | Must stay in place when you change themes |
Use only one method. Adding GA4 twice, for example with Site Kit and a manual snippet, counts every page view twice.
Method 1: Site Kit by Google
Site Kit is Google’s official WordPress plugin.
- Go to Plugins → Add New, search for Site Kit by Google, then install and activate it.
- Click Start setup and sign in with the Google account that owns your Analytics property.
- Allow Site Kit to verify your site and connect Search Console.
- When asked, connect Analytics and choose your existing GA4 property and web data stream.
Site Kit then places the Google tag on every page and shows summary reports in your WordPress dashboard.
Method 2: Google Tag Manager
Google Tag Manager suits sites that run several tags, such as GA4, ad conversion tags, and heatmaps.
- Create a Tag Manager account and a web container.
- Add the container code to WordPress. Site Kit can do this for you, or you can use a header and footer code plugin.
- In Tag Manager, create a Google tag with your
G-Measurement ID and the Initialization – All Pages trigger. - Use Preview to test, then Submit to publish the container.
Method 3: Add the Google Tag Manually
In your GA4 data stream, open View tag instructions and copy the Google tag code. Then add it to the <head> of every page, either with a code snippet plugin or through your child theme’s functions.php:
add_action( 'wp_head', function () {
?>
<!-- Paste the Google tag code from your GA4 data stream here -->
<?php
} );
Don’t edit the parent theme’s header.php directly, because a theme update will erase the code. If you need a child theme, see how to create a child theme in WordPress.
Step 3: Verify That Tracking Works
Open your site in a private browser window, then check Reports → Realtime in Google Analytics. Your visit should appear within a minute or two. You can also use Tag Assistant to confirm that the tag fires once per page.
If no data appears:
- Clear your caching plugin and any server or CDN cache.
- Check that the Measurement ID matches your data stream.
- Check that an ad blocker or browser privacy setting is not blocking the tag on your own device.
- Look for duplicate tags if page views look doubled.
Our WordPress cache plugins guide explains how to purge caches correctly.
Step 4: Settings Worth Changing on Day One
- Data retention. GA4 keeps user-level and event-level data for 2 months by default. Change it to 14 months under Admin → Data collection and modification → Data retention so you can compare longer periods in Explorations. Standard reports use aggregated data and are not limited by this setting.
- Internal traffic. In your data stream, open Configure tag settings → Define internal traffic and add your office or home IP address. Then go to Admin → Data filters and switch the internal traffic filter from Testing to Active. Filters are not applied to data collected before they were activated.
- Key events. Mark the actions that matter, such as a contact form submission or a purchase, as key events so you can track conversions.
- Search Console link. Link Search Console to see which search queries bring visitors. Our complete WordPress SEO guide shows how the two tools fit together.
Step 5: Privacy and Cookie Consent
Analytics cookies are personal data under laws such as the EU’s GDPR, so visitors from the European Economic Area usually need to give consent before tracking starts. Google also requires Consent Mode signals for sites that use its measurement and ads features with traffic from the EEA.
On WordPress, the usual setup is:
- Install a consent management plugin that supports Google Consent Mode v2.
- If you use Site Kit, check its Consent Mode setting and make sure it works with your consent plugin. Many consent plugins connect to Site Kit through the WP Consent API plugin.
- Update your privacy policy to explain that you use Google Analytics and how visitors can opt out.
This is general information, not legal advice. Check the rules that apply to your audience.
Common Mistakes
- Running two tracking methods at once. Double tags inflate page views and lower your engagement rate.
- Leaving the old UA code in place. It no longer collects data and adds an extra script.
- Keeping the 2-month retention default. You lose detailed history you can’t recover later.
- Leaving the internal traffic filter in Testing mode. Your own visits still count.
- Skipping consent. Tracking EEA visitors without consent can break privacy rules.
FAQ
Is Google Analytics 4 free?
Yes. The standard version of GA4 is free. Google Analytics 360, the paid enterprise version, adds higher limits and support for large organizations.
Does Google Analytics slow down WordPress?
The Google tag loads asynchronously, so its effect on loading is small. Avoid adding the same tag twice, and see our page speed optimization guide for other improvements.
Do I need a plugin to add GA4 to WordPress?
No. You can paste the Google tag into your site’s head with a child theme or code snippet. A plugin like Site Kit is easier to maintain and adds dashboard reports.
How long does it take for data to appear?
Realtime data appears within minutes. Standard reports can take up to 24 to 48 hours to fill in.
Can I track WooCommerce sales in GA4?
Yes. Use an integration that sends GA4 e-commerce events such as purchase. Our guide on how to create an online store with WordPress covers the store setup itself.
The Bottom Line
To add Google Analytics 4 to WordPress, create a GA4 property and web data stream, then connect it with one method: Site Kit for simplicity, Tag Manager for flexibility, or a snippet for minimal plugins. Confirm data in Realtime, extend data retention, filter internal traffic, and set up consent before you rely on the numbers.
Sources & Further Reading
- Google Analytics Help: Set up Analytics for a website and/or app
- Google Analytics Help: Universal Analytics has been replaced by Google Analytics 4
- Google Analytics Help: Data retention
- Google Analytics Help: Filter out internal traffic
- Google for Developers: Consent mode
- WordPress.org: Site Kit by Google
- WordPress.org: WP Consent API
Articles are editorially reviewed by Jackober and factual claims are checked against cited sources.
1 comment