# How to Add Google Analytics to WordPress: GA4 Setup in 3 Ways

> Source: https://mykavo.app/blog/add-google-analytics-to-wordpress  
> Author: Dakshesh  
> Published: 2026-11-26  
> Updated: 2026-11-26  
> Publisher: MyKavo (https://mykavo.app)  

## Summary

To add Google Analytics to WordPress, create a GA4 property and web data stream, copy the G- Measurement ID, then install the Google tag using Site Kit by Google, Google Tag Manager or the gtag.js snippet in your site header. Use only one method, then confirm data is arriving in GA4's Realtime report.

## Key takeaways

- Every new setup uses GA4 and a Measurement ID that starts with G-.
- Site Kit by Google is the easiest method; Tag Manager suits sites with many tags.
- Install the tag only once, or GA4 will count page views twice.
- Never paste the tag into a parent theme's header.php; updates overwrite it.
- EU and UK visitors generally need consent, so pair GA4 with a consent plugin.

To add Google Analytics to WordPress, you create a Google Analytics 4 property with a web data stream, then put its Google tag on every page of your site. You can do that with Google's free Site Kit plugin, through Google Tag Manager, or by pasting the gtag.js snippet into your site's header. All three work; the right one depends on how much control you want.

This guide walks through the GA4 setup step by step, then each installation method with exact menu paths and code, how to check that data is arriving with Realtime and DebugView, the consent rules for visitors in the EU and UK, and the mistakes that cause missing or doubled data.

> **Added the tag? Keep it there.** The free [MyKavo WordPress plugin](https://mykavo.app/wordpress-plugin) checks your pages after every update and alerts you when a script like your analytics tag goes missing. [Start monitoring free](https://mykavo.app/signup).

## Quick answer: how to add Google Analytics to WordPress

1. **Create a GA4 property** in Google Analytics (Admin > Create > Property).
2. **Add a web data stream** for your site's URL and copy the Measurement ID that starts with `G-`.
3. **Install the Google tag on WordPress** using one method: the Site Kit by Google plugin, Google Tag Manager, or the gtag.js snippet in your header through a code snippets plugin or child theme.
4. **Use only one method**, so every page view is counted once.
5. **Verify it works** by opening your site in another window and checking Reports > Realtime in GA4, or DebugView for event detail.
6. **Set up consent** if you have visitors in the EU or UK, and change data retention from 2 to 14 months.

Standard reports can take 24 to 48 hours to fill in, but Realtime should show your visit within a minute or so.

## Before you start: what you need

- **A Google account** you'll keep long term, ideally a company account with a second admin added.
- **Admin access to WordPress** so you can install a plugin or edit theme files.
- **A backup or staging site** if you plan to edit theme files. See our guides to [WordPress backups](https://mykavo.app/blog/wordpress-backup) and [staging sites](https://mykavo.app/blog/wordpress-staging-site).

**Universal Analytics is gone.** Google stopped processing data in standard Universal Analytics properties in July 2023, so old `UA-` tracking IDs collect nothing. Use GA4 and a `G-` Measurement ID.

## Step 1: Create a GA4 property and web data stream

1. Go to [analytics.google.com](https://analytics.google.com) and sign in.
2. If you're new, click **Start measuring** to create an account. Otherwise click **Admin** (the gear icon, bottom left) and choose **Create > Property**.
3. Enter a **property name**, your **reporting time zone** and **currency**. Use the time zone your business reports in, because it decides where each day starts and ends.
4. Answer the business details and objectives questions, then click **Create**.
5. When asked to choose a platform, pick **Web**.
6. Enter your website URL (for example `example.com`) and a stream name, leave **Enhanced measurement** on, and click **Create stream**.
7. Copy the **Measurement ID** shown at the top right of the stream details, such as `G-AB12CD34EF`.

**Enhanced measurement** automatically tracks page views, scrolls, outbound clicks, site search, video engagement and file downloads without extra setup.

You'll find the stream again any time under **Admin > Data collection and modification > Data streams**.

## Choose your installation method

| Method | Best for | Pros | Cons |
|-|-|-|-|
| **Site Kit by Google** | Most site owners | Official Google plugin, no code, adds Search Console too, shows stats in wp-admin | Adds a plugin; less control over custom events |
| **Google Tag Manager** | Sites with several tags or custom tracking | One container for GA4, ads and other tags; changes without editing WordPress | More setup; a second tool to learn |
| **gtag.js snippet** | Developers who want no extra plugin | Lightweight, full control | Easy to lose on theme changes; you handle consent and exclusions yourself |

Pick **one**. Running two methods at once doubles your page views.

## Method 1: Site Kit by Google (easiest)

[Site Kit by Google](https://wordpress.org/plugins/google-site-kit/) is Google's official WordPress plugin. It places the Google tag for you and connects Search Console, Analytics and other Google services.

1. In WordPress, go to **Plugins > Add New Plugin**, search for "Site Kit by Google", click **Install Now**, then **Activate**.
2. Click **Start setup** and sign in with the Google account that owns your GA4 property.
3. Grant the permissions Site Kit asks for. It verifies site ownership and connects Search Console.
4. When offered, connect **Analytics**, or later go to **Site Kit > Settings > Connect more services**.
5. Choose your GA4 account, property and web data stream. Site Kit can also create a new property if you skipped Step 1.
6. Save. Site Kit now adds the Google tag to every page.

**Exclude yourself from your data.** In the Analytics section of Site Kit's settings, you can stop tracking logged-in users or only administrators, so your own visits don't inflate the numbers.

If another plugin or your theme already adds a Google Analytics tag, remove it so page views aren't counted twice.

## Method 2: Google Tag Manager

Google Tag Manager (GTM) is a container that loads all your tags. It's worth it if you also run ads tags, a Meta Pixel or custom event tracking. Our guide to [Google Tag Manager](https://mykavo.app/blog/google-tag-manager) covers it in depth.

### Add the GA4 Google tag inside GTM

1. Create a container at [tagmanager.google.com](https://tagmanager.google.com) with **Web** as the target platform.
2. Go to **Tags > New > Tag Configuration** and choose **Google Tag**.
3. Paste your `G-` Measurement ID as the Tag ID.
4. Under **Triggering**, choose **Initialization - All Pages**, so the Google tag fires before your other tags.
5. Save the tag.
6. Click **Preview** to test with Tag Assistant, then **Submit** and **Publish** the container. Nothing goes live until you publish.

### Put the GTM container on WordPress

GTM gives you two snippets: one for the `<head>` and one immediately after the opening `<body>` tag. Install them with one of these:

- **Site Kit:** connect the Tag Manager module and pick your container. Don't also connect Analytics in Site Kit, or GA4 loads twice.
- **GTM4WP (Google Tag Manager for WordPress):** a dedicated plugin where you paste your container ID (`GTM-XXXXXXX`).
- **A code snippets plugin:** paste the head snippet into the header area and the body snippet into the body area.

**The GTM container ID starts with `GTM-`; the GA4 Measurement ID starts with `G-`.** The GTM ID goes on WordPress, and the GA4 ID goes inside GTM.

## Method 3: Paste the gtag.js snippet in your header

If you'd rather not add a dedicated analytics plugin, you can add Google's tag code to the `<head>` of every page. In GA4, open your data stream, click **View tag instructions**, choose **Install manually**, and copy the code. It looks like this:

```html
<!-- 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>
```

**Never paste it into your parent theme's header.php.** The next theme update overwrites the file and silently deletes your tracking.

### Option A: a code snippets plugin

Plugins such as **WPCode** let you add header scripts from wp-admin. Paste the Google tag into the site-wide header section. The code survives theme updates and theme switches.

### Option B: a child theme's functions.php

If you use a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/), add this to its `functions.php`, replacing the ID:

```php
<?php
// Add the GA4 Google tag to the <head> of every front-end page.
add_action( 'wp_head', function () {
    // Optional: don't track logged-in administrators.
    if ( current_user_can( 'manage_options' ) ) {
        return;
    }
    $measurement_id = 'G-XXXXXXXXXX';
    ?>
    <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_attr( $measurement_id ); ?>"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', '<?php echo esc_js( $measurement_id ); ?>');
    </script>
    <?php
}, 1 );
```

The priority of `1` outputs the tag early in the head. Skip the opening `<?php` line if your functions.php already has one. Test on staging first, because a PHP syntax error in functions.php can take the site down. If that happens, our guide to the [WordPress critical error](https://mykavo.app/blog/wordpress-critical-error) shows how to recover.

## Step 3: Verify that Google Analytics is working

### Check the Realtime report

1. Open your site in a private window (so admin exclusions and cached logins don't interfere).
2. In GA4, go to **Reports > Realtime**.
3. Within a minute or so, you should see at least one user and your page in the "Views by page title and screen name" card.

### Use DebugView for event detail

DebugView (**Admin > Data display > DebugView**) shows individual events as they arrive, but only from devices in debug mode. The easiest way to turn it on is **Tag Assistant** at tagassistant.google.com or GTM's Preview mode: connect your site URL, browse a few pages, and watch events like `page_view`, `scroll` and `user_engagement` appear.

### Check the page source

View your page source (Ctrl+U or Cmd+Option+U) and search for your `G-` ID. **It should appear in exactly one tag setup.** If you see it twice, or see both a gtag snippet and a GTM container sending to the same ID, remove one.

If data still doesn't show up, our guide on [Google Analytics not tracking](https://mykavo.app/blog/google-analytics-not-tracking) covers ad blockers, consent banners, caching and the other common causes.

## Consent for EU and UK visitors

Analytics cookies generally need visitor consent under EU and UK privacy rules (the GDPR and ePrivacy rules in the EU, UK GDPR and PECR in the UK). That means you need a cookie banner that asks before loading analytics, or loads it in a restricted way until visitors agree.

- **Use a consent management plugin.** Options such as Complianz, CookieYes and Cookiebot can block or delay Google tags until consent is given.
- **Set up Google Consent Mode.** Since March 2024, Google has required Consent Mode v2 signals for sites that use its advertising and measurement features with visitors in the European Economic Area. Many consent plugins send these signals for you, and Site Kit includes a Consent Mode setting that works with consent plugins that support the WP Consent API.
- **Expect lower numbers.** Visitors who decline aren't measured the same way, so reports will undercount.

This isn't legal advice. If you're unsure what applies to your site, ask someone qualified in privacy law for your market.

## Recommended GA4 settings after installing

- **Data retention:** under **Admin > Data collection and modification > Data retention**, change event data retention from the default **2 months** to **14 months**. This affects how far back you can run detailed explorations.
- **Internal traffic:** define your office IP addresses in the data stream's tag settings, then activate the internal traffic filter.
- **Key events:** mark important actions, such as form submissions or purchases, as key events.

## Common mistakes that break GA4 on WordPress

| Problem | Cause | Fix |
|-|-|-|
| Page views doubled | Two methods installed (for example Site Kit plus a header snippet) | Keep one method; search the page source for your G- ID |
| No data at all | Wrong ID, GTM container not published, or tag removed by a theme update | Check the ID; publish GTM; re-add the tag via a plugin or child theme |
| Data stops suddenly | Theme switched, plugin deactivated, or script removed by an optimization plugin | Check page source; exclude gtag.js from "delay JS" settings if needed |
| Realtime works, reports empty | Normal processing delay | Wait 24 to 48 hours |

## How to catch a missing analytics tag automatically

The worst analytics failures are silent. A theme update overwrites header.php or an optimization setting strips the script, and nobody notices until a monthly report shows a cliff. GA4 can't backfill visits it never received.

MyKavo watches the pages you choose and alerts you when **scripts are added or removed**, so a missing Google Analytics, Google Tag Manager or payment script raises an alert with before-and-after proof and a severity. You pick the pages, MyKavo saves an approved baseline, then re-scans on a schedule (weekly on the Free plan, daily on paid plans). The free [MyKavo WordPress plugin](https://mykavo.app/wordpress-plugin) also checks your pages after every plugin, theme and core update and names the update when something broke. For a quick one-off check of what's loading on a page, try the free [script detector](https://mykavo.app/tools/script-detector).

## Frequently asked questions

### How do I add Google Analytics 4 to WordPress?

Create a GA4 property and web data stream, copy the G- Measurement ID, then install the Google tag with Site Kit by Google, Google Tag Manager, or the gtag.js snippet in your header. Check Reports > Realtime in GA4 to confirm data is arriving.

### Can I add Google Analytics to WordPress without a plugin?

Yes. Paste the gtag.js snippet into the head of your site using a child theme's functions.php with the wp_head hook. Avoid editing the parent theme's header.php, because theme updates overwrite it.

### Is Site Kit by Google the best Google Analytics plugin?

It's the official Google plugin and the simplest option for most sites, since it places the tag and connects Search Console for you. Sites that need advanced custom events or many tags often prefer Google Tag Manager.

### Where do I find my Google Analytics Measurement ID?

In GA4, go to Admin > Data collection and modification > Data streams, click your web stream, and copy the ID starting with G- at the top right of the stream details.

### How long does it take for Google Analytics to show data?

The Realtime report usually shows visits within a minute or so. Standard reports can take 24 to 48 hours to process, so don't worry if they're empty on the first day.

### Why is Google Analytics showing double page views?

Usually the tag is installed twice, for example by Site Kit and a header snippet, or by both gtag.js and a GTM container. View the page source, search for your G- ID, and remove the duplicate installation.

### Do I need a cookie banner for Google Analytics?

If you have visitors in the EU or UK, analytics cookies generally need consent, so use a consent plugin and Google Consent Mode. Rules differ by country, so check what applies to your site.

## The bottom line

Adding Google Analytics to WordPress takes two parts: a GA4 property with a web data stream, and one clean installation of the Google tag. Site Kit is the easiest route, Google Tag Manager is best when you run several tags, and a gtag.js snippet in a child theme or snippets plugin suits developers. Verify with Realtime and DebugView, set up consent for EU and UK visitors, raise data retention to 14 months, and keep an eye on the tag so an update doesn't quietly remove it.

**Don't lose a month of data to a missing tag.** [Start monitoring your site free with MyKavo](https://mykavo.app/signup) and install the free [MyKavo WordPress plugin](https://mykavo.app/wordpress-plugin), no card needed.
