Google Analytics is still the default answer to “how many people visit my site, and what do they do there?” Getting it onto a WordPress site takes ten minutes, but getting it on correctly, with consent handled, your own visits excluded and the events you care about actually recorded, takes a little more thought. This guide walks through the four realistic ways to add Google Analytics 4 (GA4) to WordPress, how to choose between them, and how to prove the data is arriving before you rely on it.
Before you start: create a GA4 property
GA4 is the only version of Google Analytics that collects data today. The older Universal Analytics stopped processing new hits in 2023, so any tutorial that asks you for a tracking ID beginning with UA- is out of date. What you need now is a Measurement ID, which looks like G-XXXXXXXXXX.
- Sign in at analytics.google.com with the Google account that should own the data. Use a business account rather than a freelancer’s personal one, so ownership stays with the site owner.
- Go to Admin → Create → Property, enter a property name, reporting time zone and currency.
- Add a Web data stream with your site’s URL. Leave Enhanced measurement switched on.
- Copy the Measurement ID shown on the stream details screen.
Enhanced measurement is worth understanding before you install anything. With it enabled, GA4 records page views, scrolls, outbound link clicks, site search, file downloads, embedded video engagement and form interactions without extra code. Many site owners install a heavy plugin to track things GA4 already captures on its own.
One more setting to change on day one: Admin → Data collection and modification → Data retention. The default keeps event-level data for two months; standard properties can raise it to 14 months. This only affects explorations, not the standard reports, but there is no reason to keep less history than you are allowed.
Four ways to add Google Analytics to WordPress
| Method | Best for | Trade-off |
|---|---|---|
| Site Kit by Google | Owners who want reports in the dashboard | Larger plugin; ties several Google services together |
| Lightweight analytics plugin | Simple sites, minimal setup | Fewer reports inside WordPress |
| Manual gtag snippet | Developers, performance-focused sites | You maintain the code and consent wiring |
| Google Tag Manager | Sites with several tags or marketing teams | Another tool to learn and govern |
Pick exactly one. The most common Google Analytics problem on WordPress sites is double tracking: a theme option, a plugin and a Tag Manager container all firing the same tag, which inflates page views and wrecks engagement metrics.
Method 1: Site Kit by Google
Site Kit is Google’s official WordPress plugin. Install it from Plugins → Add New, activate it and run the setup wizard. It signs you in with Google, verifies the site for Search Console, and either connects an existing GA4 property or creates one for you. It then places the tag and shows summary charts on the WordPress dashboard.
Strengths: no code, official support, and Search Console data next to analytics. Weaknesses: it is a bigger plugin than a single snippet needs to be, and the person who runs the wizard becomes the connected Google user, so do it with the account that should own the data.
Method 2: A third-party analytics plugin
Plugins in this space range from tiny “paste your Measurement ID” tools to full dashboards such as MonsterInsights. The small ones do one job and add almost no weight. The dashboard plugins add in-WordPress reports, e-commerce tracking helpers and form tracking, usually with a free tier and paid upgrades; check the vendor’s current pricing page before committing. Apply the usual checks from our guide to evaluating WordPress plugins: recent updates, active installs, and a support forum that gets answers.
Method 3: Add the gtag snippet manually
The tag itself is two script elements. Pasting them into a theme’s header.php is the classic advice, but it breaks the moment the theme updates, and block themes do not have a header.php at all. The durable approach is to print the snippet from the wp_head action in a small custom plugin or a code-snippets plugin:
<?php
/*
* Plugin Name: GA4 Tag
*/
add_action( 'wp_head', function () {
if ( is_user_logged_in() ) {
return; // skip editors and admins
}
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
<?php
}, 5 );
Save it as a single file in wp-content/plugins/ga4-tag/ and activate it. The logged-in check keeps your own editing sessions out of the reports. If you are new to actions, our explainer on WordPress hooks, actions and filters covers why this survives theme switches when editing template files does not.
Method 4: Google Tag Manager
Tag Manager adds a container to the site once; after that, GA4, ad pixels and other tags are configured in the Tag Manager interface rather than in WordPress. Create a container at tagmanager.google.com, install its code (Site Kit can place it, or use the same wp_head approach plus the wp_body_open action for the noscript part), then add a “Google tag” with your Measurement ID, triggered on all pages, and publish.
Tag Manager earns its keep when a marketing team needs to add and change tags without a developer. For a single blog with only GA4, it is extra machinery.
Consent mode and cookie banners
If you have visitors in the EU, the UK or other regions with similar privacy rules, analytics cookies generally need consent before they are set. Google’s answer is Consent Mode, which the tag reads before it stores anything. Version 2 uses four signals: analytics_storage, ad_storage, ad_user_data and ad_personalization.
- Basic consent mode: the Google tag does not load at all until the visitor accepts.
- Advanced consent mode: the tag loads with all signals defaulted to “denied” and sends cookieless pings, which Google can use for modeling; full measurement starts once consent is granted.
In practice you rarely write this by hand. Most consent management platforms and cookie banner plugins for WordPress set the consent defaults and send updates when the visitor clicks. The details are documented in Google’s consent mode developer guide. Whichever banner you choose, the default “denied” call must run before the Google tag; if your manual snippet loads first, the banner is decorative. This is one of the strongest arguments for letting a single plugin or Tag Manager own both the banner and the tag. Treat this as practical guidance, not legal advice; what you must do depends on where you and your visitors are.
Set up key events that match your goals
Page views tell you about traffic; key events (what GA4 called conversions until 2024) tell you whether the site is working. Decide on three to five actions that matter to the business, for example:
- A contact or quote form submitted (track the thank-you page view, or a
generate_leadevent). - A newsletter sign-up.
- A WooCommerce purchase (the recommended
purchaseevent, usually sent by an e-commerce integration plugin). - A click on a phone number or a “Book now” button.
For events GA4 already collects, go to Admin → Data display → Events and toggle “Mark as key event”. For a thank-you page, create a new event under Admin → Events → Create event with the condition event_name equals page_view and page_location contains /thank-you/, then mark that new event as key. Custom events only appear in the list after they have fired at least once, so trigger them yourself first.
Also define internal traffic: Admin → Data streams → your stream → Configure tag settings → Define internal traffic, add your office IP, then activate the “Internal Traffic” filter under Data filters. It starts in testing state and does nothing until you switch it to active.
Verify the data with Realtime, DebugView and Tag Assistant
Never assume the tag works because the plugin says “connected”. Check it from three angles:
- View source. Open the site in a private window, logged out, and search the page source for your Measurement ID. It should appear once. Two copies means double tracking.
- Realtime report. Reports → Realtime should show your visit within a minute or so. Standard reports can take up to a day or two to fill, so empty ones on day one are normal.
- Tag Assistant and DebugView. Open tagassistant.google.com, enter your URL and browse in the debug window. Each event then streams into Admin → Data display → DebugView with all its parameters, which is the quickest way to confirm that a form submission or purchase event carries the right values.
If nothing arrives, the usual suspects are a caching or optimization plugin that delayed or combined the script, a consent banner defaulting to denied without ever loading the tag, an ad blocker in your own browser, or the wrong Measurement ID pasted from a different property. Purge page caches after any tag change; full-page caches will happily serve the old HTML for hours.
Performance and privacy trade-offs
The GA4 tag is loaded asynchronously and is modest by modern standards, but it is still third-party JavaScript on every page. Avoid stacking analytics tools that measure the same thing, and if you use script delay features in a performance plugin, confirm afterwards that page views still register, since delayed scripts can miss visitors who leave quickly. Our speed optimization techniques article covers how to measure the real cost of third-party scripts.
Google Analytics is free and powerful, but it is not the only option. Privacy-focused tools such as self-hosted Matomo or lightweight cookieless services trade some depth for simpler compliance. For many content sites, GA4 plus a properly configured consent banner remains the practical choice, especially if you also run Google Ads or Search Console and want the data connected. Pair it with the on-page work in our WordPress SEO guide so you can see which changes move organic traffic.
Frequently asked questions
Does my theme need special support for Google Analytics?
No. Any theme that calls wp_head(), which every properly built classic and block theme does, works with all four methods. Be wary of themes that bundle their own analytics field; if you use one, do not also install a plugin.
Can I track a WordPress multisite network with one property?
Yes. A network-activated tag sends every subsite to one stream, and you can segment by hostname or page path. If each subsite belongs to a different client, give each its own property instead.
Why do GA4 numbers differ from my host’s statistics?
Server logs count every request, including bots and visitors who block scripts. Google Analytics counts browsers that ran the tag and, where required, consented. Neither is wrong; they measure different things.
Key takeaways
- Create a GA4 property and web stream first; you need a
G-Measurement ID, not aUA-one. - Choose one installation method (Site Kit, a plugin, a
wp_headsnippet or Tag Manager) and never stack them. - Make sure consent defaults load before the Google tag if you have visitors in regions that require consent.
- Mark three to five business actions as key events and filter out internal traffic.
- Verify with page source, Realtime and DebugView, and purge caches after every tag change.