How to add Google Analytics 4 to WordPress (and not slow it down)
Four ways to add GA4 to WordPress, the plugin and Tag Manager methods step by step, plus the performance and consent details most guides skip.

Editorial opinion based on hands-on experience — not financial, investment, or professional advice. Some links may be affiliate links; see our disclosure.
- Universal Analytics is gone — GA4 is the only version Google runs now, and it's a different data model, not just a new tag.
- You have four ways to add it: a plugin, Google Site Kit, manual code in a child theme, or Google Tag Manager. GTM is the most flexible; a plugin is the fastest.
- Analytics scripts are render-blocking weight if you add them carelessly. Load the tag asynchronously and you keep your Core Web Vitals intact.
- Wherever you put the code, keep it theme-independent — never paste a tracking snippet into a theme you might replace, or your data vanishes the day you switch.
01What GA4 is, and why Universal Analytics is gone
| Check | Good sign | Fix before moving on |
|---|---|---|
| Backup | You can roll back the site or setting | No restore point exists |
| Staging | Change is tested on a copy first | Live site is the first test |
| Mobile | The result works on a narrow viewport | Layout only works on desktop |
| Performance | No large new asset or plugin is added casually | The change slows every page |
Google Analytics 4 (GA4) is the current and only version of Google Analytics. The previous version, Universal Analytics, stopped processing new data in July 2023 and its data was later shut off entirely. If you're setting up analytics today, GA4 is the only option — there is no choice to make about version.
GA4 is not just a renamed tag. It uses an event-based data model: every interaction — a pageview, a scroll, a click, a download — is recorded as an event rather than the old sessions-and-pageviews structure. That makes it more flexible, but it also means old tutorials referencing "UA-" tracking IDs are outdated. GA4 uses a Measurement ID that looks like G-XXXXXXXXXX.
Before you touch WordPress, create a GA4 property at analytics.google.com, add a web data stream for your site, and copy the Measurement ID. That ID is the one thing every install method below needs.
02The four ways to add GA4 to WordPress
There's no single "correct" method — there are four, and the right one depends on how much you want to manage and how much else you plan to track. They all end with GA4 collecting data; they differ in flexibility and overhead.
1. A dedicated analytics plugin
Plugins built for GA4 ask for your Measurement ID and handle the rest. It's the fastest route and the friendliest for non-developers — many also surface basic reports inside your WordPress dashboard. The trade-off is one more plugin to keep updated, and some bundle features you'll never use.
2. Google Site Kit
Site Kit is Google's own official WordPress plugin. It connects Analytics, Search Console, and PageSpeed Insights through a guided sign-in, so you authenticate with your Google account instead of pasting an ID. It's a solid, trustworthy default — especially if you also want Search Console data — though it pulls in more than just analytics.
3. Manual code in a child theme
You can add the GA4 gtag snippet directly to your site's <head> via your child theme's functions.php or a header hook. No plugin overhead, full control. The catch: it requires comfort with code, and if you paste it into the wrong place it becomes theme-dependent — more on that danger below.
4. Google Tag Manager (GTM)
GTM is a container you install once, then manage all your tags (GA4, ads pixels, custom events) from a web dashboard without ever editing the site again. It's the most flexible and the most future-proof if you'll run more than one tracking tag — but it's also the most setup to learn upfront.
03Step by step: the plugin method
This is the path most WordPress sites should take. It's quick, reversible, and survives theme changes because the tracking lives in a plugin, not your theme files.
- Create the GA4 property — at analytics.google.com, add a property and a web data stream for your domain, then copy the
G-XXXXXXXXXXMeasurement ID. - Install the plugin — from Plugins → Add New, search for a reputable GA4 / Google Analytics plugin, install and activate it.
- Connect it — open the plugin's settings and either paste your Measurement ID or sign in with the Google account that owns the property.
- Enable async loading — if the plugin offers an option to load the script asynchronously or move it out of the critical path, turn it on.
- Verify — open your site in a private window, then check GA4's Realtime report for your own visit (covered below).
That's the whole job. Resist enabling every extra tracking feature the plugin offers on day one — each one adds events and weight you may not need.
04Step by step: the Google Tag Manager method
GTM is worth the extra setup if you'll ever run conversion pixels, custom events, or multiple tags. You install GTM once, then GA4 becomes a tag inside it — and every future change happens in GTM, never in WordPress.
- Create a GTM container — at tagmanager.google.com, make a container for your site and copy the two snippets it gives you (one for
<head>, one for the top of<body>). - Add the snippets to WordPress — use a header-and-footer plugin, Site Kit's GTM option, or a child-theme hook to place both snippets. A plugin keeps it theme-independent.
- Add a GA4 Configuration tag — inside GTM, create a new tag of type Google Analytics: GA4 Configuration, paste your Measurement ID, and set the trigger to All Pages.
- Preview — use GTM's Preview mode to confirm the tag fires on your site before going live.
- Publish — click Submit in GTM to push the container live. Changes take effect without touching WordPress again.
One rule that prevents double-counting: if you load GA4 through GTM, do not also add a raw GA4 snippet or an analytics plugin. Pick one path. Two copies of the tag means every pageview is counted twice and your data is quietly wrong.
05The performance angle: don't let analytics slow your site
Every tracking script is third-party JavaScript your visitor's browser has to fetch and run. Add it carelessly and it competes with your real content for load time, dragging down the Core Web Vitals — largest contentful paint and interaction responsiveness especially — that affect both user experience and rankings.
- Load it asynchronously — the official gtag snippet already uses
async, and good plugins do too. Never load analytics as a render-blocking script in the critical path. - Don't stack tags — GTM plus a plugin plus a manual snippet is three copies of overlapping work. One method only.
- Be wary of heavy add-ons — dashboard-reporting and heatmap features inside analytics plugins can add real weight. Enable only what you'll actually look at.
- Lean on caching and a CDN — server-level caching on a managed host like Cloudways, plus a CDN, blunts the cost of third-party scripts by making everything else load faster around them.
After you add GA4, re-run your homepage through PageSpeed Insights. A single, async analytics tag should barely move the needle. If your score drops noticeably, you've stacked tags or enabled something heavy — back it out.
06Privacy and consent basics
Analytics collects data about real people, which brings rules. Depending on where your visitors are — the EU, UK, California and more — you may be legally required to ask for consent before any tracking cookies fire. This is genuinely your responsibility, not the plugin's.
- Cookie consent — add a consent banner that actually blocks GA4 until the visitor agrees, rather than one that just displays a notice while tracking anyway. Google's Consent Mode is designed to work with this.
- IP anonymization — GA4 does not log or store full IP addresses by default; it's anonymized at collection. That's a privacy improvement over old setups, but it's worth knowing rather than assuming.
- Data retention — in GA4's admin settings you can set how long event-level data is kept. Choose a retention period that matches your privacy policy.
- Disclose it — your site's privacy policy should name that you use Google Analytics and why. Most consent-banner tools help generate this language.
If you operate where consent law applies, treat the consent banner as part of the install, not an optional extra. Tracking before consent is the kind of mistake that's cheap to avoid and expensive to fix.
07Keep it theme-independent
Here's the mistake that quietly destroys analytics histories: pasting your tracking code into a theme. Many themes offer a "header scripts" or "custom code" box in their options panel, and it's tempting to drop the GA4 snippet there. It works — until the day you change themes.
The moment you switch or rebuild your theme, any code stored in that theme's settings disappears with it. Your tracking silently stops, and you often don't notice until weeks of data are missing. The same is true of pasting the snippet straight into a parent theme's files, which an update will also overwrite.
- Best: a dedicated analytics plugin or Google Site Kit — fully decoupled from your theme.
- Also safe: a header-and-footer code plugin, or GTM installed via a plugin — the tag lives outside the theme.
- Only if you must code it: put it in a child theme so a parent-theme update can't wipe it, and document that it's there.
- Avoid: the theme's own "custom code" box, or editing the parent theme directly — both tie your data to a theme you may replace.
The principle is simple: your analytics should outlive any single theme. Store it somewhere a theme switch can't touch, and a redesign never costs you your data trail.
08Verifying it actually works
Don't assume the tag fired just because the setup wizard said "connected." Confirm it with data before you walk away — a silent failure here means weeks of empty reports.
- Realtime report — open your site in a private/incognito window, then check Reports → Realtime in GA4. You should appear as an active user within seconds.
- Google Tag Assistant — Google's free Tag Assistant tool connects to your site and confirms the GA4 tag is present and firing correctly.
- Browser network tab — open developer tools, reload your site, and look for a request to
google-analytics.comorgoogletagmanager.com. If it's there, the tag is loading. - GTM Preview mode — if you used Tag Manager, its built-in Preview shows exactly which tags fire on each page.
Realtime is the fastest check, but give standard reports 24–48 hours to populate fully — GA4 processes most non-realtime data on a delay, so an empty report on day one isn't necessarily a broken install.
09FAQ
Can I still use Universal Analytics?
No. Universal Analytics stopped collecting data in 2023 and its properties were shut down afterward. Any "UA-" tracking ID is dead. GA4 with a G- Measurement ID is the only working version.
Do I need Google Tag Manager, or is a plugin enough?
A plugin is enough for most sites that only run GA4. Choose GTM when you'll manage several tags — ad pixels, custom events, multiple platforms — and want to change them without editing your site. Use one or the other, never both for the same GA4 tag.
Will adding GA4 hurt my page speed?
A single, asynchronously loaded GA4 tag has a small impact. Speed problems come from stacking multiple tracking methods or enabling heavy reporting add-ons. Keep it to one async tag and your Core Web Vitals should hold.
Where should the GA4 code live so I don't lose it?
In a plugin, in Site Kit, or in a child theme — anywhere decoupled from your active theme's settings. Never in the theme's "custom code" box, because switching themes erases it along with your tracking.
Do I legally need a cookie consent banner?
It depends on where your visitors are. EU, UK, and California rules, among others, can require consent before tracking cookies fire. This is a legal question for your situation — this guide is an honest how-to, not legal or financial advice, so check what applies to you before relying on any default.


