Guides · Parhum Khoshbakht

How to Add Google Analytics to WordPress (Updated May 2026)

Three methods to install Google Analytics 4 on WordPress in 2026 — plugin, manual code, and Google Tag Manager — with the honest trade-offs each one carries.

If you’ve decided to add Google Analytics 4 to your WordPress site, this guide covers the three methods that actually work in 2026: a plugin, a manual code snippet, or Google Tag Manager. Each takes 5–15 minutes. Each has trade-offs that nobody warns you about until you’re already invested.

We’ll walk through all three, then close with what GA4 won’t tell you about your visitors — and why that matters more than most setup guides admit.

Before you start

You’ll need three things:

  1. Admin access to your WordPress site — installing a plugin or editing functions.php requires the manage_options capability.
  2. A Google Analytics 4 property — if you don’t have one, sign in to analytics.google.com, click Admin → Create, choose Web as the platform, enter your site URL, and copy the Measurement ID (format: G-XXXXXXXXXX). GA4 replaced the older Universal Analytics in July 2023, so you can’t use a UA-XXXXX-X ID anymore.
  3. A consent management plugin (CMP) if you serve EU/UK/Swiss/California visitors. GA4 sets cookies and identifies returning visitors, which is regulated under GDPR, ePrivacy, and CCPA. We’ll cover this in step 5.

The whole process takes about 15 minutes for the easiest method, longer if you’re going through Google Tag Manager.

The plugin route is the easiest and what most WordPress site owners pick. Two plugins dominate this space:

Google Site Kit (free, official)

Google Site Kit is Google’s own WordPress plugin. It connects your site to GA4, Search Console, AdSense, and PageSpeed Insights using a single OAuth flow.

  1. Install: in /wp-admin, go to Plugins → Add New, search “Google Site Kit,” click Install then Activate.
  2. Connect: a setup wizard launches automatically. Click Start setup, sign in with the Google account that owns your GA4 property, and authorize Site Kit.
  3. Select your GA4 property from the dropdown. Site Kit creates the Measurement ID linkage automatically — you don’t need to copy G-XXXXXXXXXX manually.
  4. Click Configure Analytics, accept the data-collection terms, and Site Kit injects the GA4 tag into your site’s <head>.

That’s it. GA4 starts collecting data immediately. You’ll see a Site Kit dashboard widget in /wp-admin showing top pages, search queries, and pageview trends without leaving WordPress.

Why this works well: it’s official, it’s free, and Site Kit handles updates as Google releases new APIs. If GA4’s setup process changes (it has changed three times since 2022), Site Kit absorbs the change.

Trade-off: Site Kit fetches GA4 data via Google’s APIs server-to-server, so the in-WordPress dashboard is comprehensive but you’re still locked into GA4’s data model — sampling, retention limits, consent-banner requirements all apply.

MonsterInsights (free + paid)

MonsterInsights is the most-installed third-party GA plugin (3M+ active installs). It wraps GA4 with curated dashboards and pre-built event tracking for forms, e-commerce, affiliate links, and YouTube embeds.

  1. Install from Plugins → Add New, activate.
  2. Run the setup wizard, sign in with Google, choose your GA4 property.
  3. Pick a tracking profile (most sites: “Publisher” or “eCommerce”).

The free Lite version handles basic GA4 reporting. Most useful features (form tracking, custom event dashboards, e-commerce integration) require Pro at $99.50/yr or higher.

Why people pick this over Site Kit: MonsterInsights has nicer dashboards inside /wp-admin and pre-built reports for things you’d otherwise configure in GA4 manually (scroll depth, file downloads, outbound link clicks).

Trade-off: the same as Site Kit (GA4 underneath), plus the upsell pressure inside the plugin’s UI. The free version is genuinely useful for basic pageview reporting; serious analytics work pushes you to a paid tier.

Method 2: Manual code in functions.php

If you want to avoid adding another plugin, you can paste the GA4 tracking code into your theme’s functions.php (or a custom plugin):

add_action( 'wp_head', 'add_ga4_tracking', 1 );
function add_ga4_tracking() {
    ?>
    <!-- Google tag (gtag.js) -->
    <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
}

Replace G-XXXXXXXXXX with your actual Measurement ID. Save the file. GA4 starts collecting data on the next pageview.

Why this works: no plugin overhead, no admin UI, zero abstraction. The script runs exactly as Google documents it.

Trade-off: you lose the Plugin’s UI and dashboard. You’ll be reading your stats on analytics.google.com, not in /wp-admin. You also have to remember to maintain this snippet manually if Google changes the tag format. We’ve seen the gtag snippet change three times since 2020.

Important: edit the file via SFTP or a child-theme functions.php — never edit your active theme’s functions.php directly via the WordPress code editor unless you have a way to recover from a fatal error. A typo will white-screen your site.

Page-builder shortcut: Elementor / Divi / Beaver Builder

All three major page builders ship a “Custom Code” or “Header/Footer Scripts” panel where you can paste the GA4 snippet without editing functions.php:

  • Elementor: Site Settings → Custom Code → Add New → Header
  • Divi: Theme Options → Integration → “Add code to the head”
  • Beaver Builder: Settings → Tools → Custom Code

Same snippet as above. Same trade-offs.

Method 3: Google Tag Manager (most flexible)

Google Tag Manager (GTM) is a tag-routing layer between your site and Google services. Install GTM once, then add or modify GA4 (and other tags) inside GTM’s UI without touching site code again.

  1. Sign in to tagmanager.google.com, create a container for your domain, and copy the GTM container snippet (two scripts: one for <head>, one for <body>).
  2. Paste the GTM snippets into your site — either via a plugin (the Google Tag Manager for WordPress plugin handles this), or manually in functions.php using wp_head and wp_body_open.
  3. Inside GTM, click Tags → New, choose Google Analytics: GA4 Configuration, paste your Measurement ID, set the trigger to All Pages, and Publish the workspace.

GA4 starts firing.

Why pick this over a direct plugin? If you’ll add more tracking later (Meta Pixel, LinkedIn Insight, conversion tracking for ad campaigns), GTM lets you manage all of them from one UI without site code changes. For a site that only uses GA4, GTM is over-engineered.

Verifying your installation

Whichever method you used, verify it’s working before you walk away:

  1. Open your site in a private/incognito window so cookies don’t taint the test.
  2. Browse 2-3 pages.
  3. Open GA4 → Reports → Realtime.

You should see your active session within 30 seconds. If you don’t, the most common causes are:

  • Ad blocker blocking the test session. Disable uBlock Origin / AdGuard / Brave shields for your site temporarily, refresh, and try again.
  • Caching plugin serving a pre-tag-install version of the page. Clear the WordPress cache (W3 Total Cache, WP Rocket, etc.) and the CDN cache (Cloudflare).
  • Wrong Measurement ID. Double-check G-XXXXXXXXXX matches the one in your GA4 property.
  • Consent Mode blocking. If you’ve already installed a CMP, accept cookies in your private window before testing.

GA4 sets cookies (_ga, _ga_<container_id>, _gid) and identifies returning visitors. Under GDPR (EU), ePrivacy (EU), and CCPA (California), you must:

  1. Show a consent banner before any GA4 cookie is set, with clear “Accept” / “Reject” options that are equally prominent.
  2. Block GA4 from firing until the user consents.
  3. Respect refusal — if a user clicks “Reject,” GA4 should not load.
  4. Implement Google Consent Mode v2 so GA4 reports anonymized aggregated data when consent is denied (still useful for high-level trends).

WordPress CMP plugins that handle this correctly:

  • Complianz (wordpress.org/plugins/complianz-gdpr) — most popular, generates a region-aware banner based on visitor IP geolocation.
  • CookieYes — paid, well-maintained, handles GTM-based blocking automatically.
  • Iubenda — enterprise-focused, tighter on legal exactness.

Without a CMP, you’re exposed to fines under GDPR (up to €20M or 4% of global revenue) and similar penalties under CCPA. This isn’t theoretical — French and Italian DPAs have ruled GA4 implementations non-compliant in 2022 and 2023, requiring sites to switch tools or implement strict server-side proxying.

What GA4 won’t tell you

Now the part most setup guides skip: GA4 has known data-quality issues that aren’t fixable with a better install.

1. Ad-blocker invisibility. uBlock Origin, AdGuard, Brave’s built-in shields, and Firefox’s Strict Tracking Protection block GA4 by default. As of 2026, 30–50% of visitors have one of these blockers active, and they never appear in your GA4 data. You’re optimizing for a subset of your real audience and don’t know it.

2. Consent-banner attrition. Once you correctly implement consent, a chunk of your remaining visitors will click “Reject” or close the banner. Common rejection rates are 20–40% depending on banner design. Combined with ad-blockers, you may be capturing data from only 30–50% of real visitors.

3. GA4’s sampling and learning curve. GA4’s event-based model is fundamentally different from the page-view model most site owners learned with Universal Analytics. Sampling kicks in on standard accounts above 10M events/month, replacing real numbers with extrapolations. The Engagement metric replaces familiar pageviews. Custom dimensions cost extra setup. None of this is obvious from the install guide.

4. Tracker overhead. The GA4 tag is ~28 KB gzipped on top of GTM’s ~14 KB if you used GTM. On cellular connections, this competes with your site’s critical scripts for the network budget. Most sites won’t notice; performance-sensitive sites (e-commerce, news, anything where Core Web Vitals matter for SEO) will.

5. Schrems II and EU data transfers. GA4 data routes through Google’s US infrastructure. The European Court of Justice’s Schrems II ruling and subsequent DPA decisions have flagged this as a GDPR transfer issue. The Data Privacy Framework (DPF) provides a partial fix as of 2024, but the legal landscape remains in flux.

The honest alternative: skip GA4 entirely

If your reasons for installing GA4 are “everyone uses it” and “I want to know how my site is doing,” there’s a genuinely better path: a privacy-first analytics plugin that captures 100% of visitors, requires no consent banner, and runs at a fraction of the page weight.

Statnive is the analytics tool we make at this site. It’s cookieless, self-hosted in your WordPress database, ships a 2.4 KB gzipped tracker, and surfaces the metrics that actually map to revenue (not bounce rate or time-on-site). It activates in two minutes — no setup wizard, no Google account, no Measurement ID to copy.

For a side-by-side breakdown of when GA4 makes sense vs when a privacy-first alternative wins, see Statnive vs Google Analytics or the full ranked list of GA alternatives for WordPress.

If you’ve already decided GA4 is the right call for your specific situation — running a Google Ads campaign that needs GA4 conversion tracking, or working with an agency whose reports rely on GA4 — the install guide above is the cleanest path. If you’re choosing GA4 by default, it’s worth pausing for an hour to consider what you’re trading.

FAQ

Do I need to add Google Analytics to WordPress at all?

Not necessarily. You need some analytics to make decisions about your site. Google Analytics is one option among many, and it’s not the lightest, the most private, or the most useful for revenue-focused decisions. If you specifically need GA4 (because you’re running Google Ads, or because your agency requires it), the guide above is the install path. If you just want to know what’s working on your site, a privacy-first alternative is often a better fit.

Can I add GA4 without a plugin?

Yes — Method 2 above pastes the GA4 snippet directly into functions.php. This avoids adding another plugin but requires comfort editing PHP files via SFTP. Pageview tracking works identically; you lose the in-WordPress dashboard you’d get from Site Kit or MonsterInsights.

How long until GA4 data appears?

Realtime data appears within 30 seconds of a pageview. Standard reports (top pages, channels, demographics) take 24–48 hours to populate for new properties. This is normal — GA4 batches and processes data overnight before reporting it in non-realtime views.

Can I add Google Analytics to a specific Elementor page only?

Yes — Elementor’s Site Settings → Custom Code panel supports per-page-template injection, but in practice you almost always want analytics site-wide. Per-page tracking is fragile (visitors who navigate around your site disappear and reappear in your data). Install GA4 globally via one of the three methods above.

What happens if I remove Google Analytics later?

Your historical data stays in your GA4 account — it’s stored on Google’s servers, not your site. Deactivating the plugin or removing the gtag code stops new data collection but doesn’t affect what’s already there. Most teams switching from GA4 to a privacy-first alternative run both for 30–60 days, verify the new tool captures the data they actually use, then deactivate GA4.


Published May 9, 2026. WordPress versions tested: 6.4–6.5. GA4 setup process verified against the May 2026 Google Analytics Admin UI.

Get Statnive Free