Check my theme free
HomeGuides & How-toArticle
Guides & How-to

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.

How to add Google Analytics 4 to WordPress (and not slow it down) — conceptual editorial illustration
Representative demo screenshot, captured by the ThemeBurn Speed Lab.

Editorial opinion based on hands-on experience — not financial, investment, or professional advice. Some links may be affiliate links; see our disclosure.

Bottom line up front
  • 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

How to add Google Analytics 4 to WordPress (and not slow it down): quick implementation checklist
CheckGood signFix before moving on
BackupYou can roll back the site or settingNo restore point exists
StagingChange is tested on a copy firstLive site is the first test
MobileThe result works on a narrow viewportLayout only works on desktop
PerformanceNo large new asset or plugin is added casuallyThe 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-XXXXXXXXXX Measurement 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.

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.com or googletagmanager.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.

Alex Tarlescu
Operator — websites, domains & web platforms

I build, buy, and run theme-based websites and online stores — including on platforms whose themes were later abandoned. The migration and recovery advice here is the advice I follow on my own sites.