Wordpress

How to Add and Verify Google Analytics 4 in WordPress

January 9, 2013
Updated

To add and verify Google Analytics in WordPress today, you set up a Google Analytics 4 (GA4) property and either connect it with Google's free Site Kit plugin or paste the Google tag into your site's <head>. You then confirm it works in the GA4 Realtime report, where data can take up to 30 minutes to start showing.

This guide covers both methods for WordPress 7.1, based on Google's own setup instructions. If you are following an older tutorial that uses a tracking ID starting with UA-, stop there: that version of Analytics no longer exists.

What happened to Universal Analytics?

Universal Analytics, the version with UA- tracking IDs, is gone. According to Google's Universal Analytics sunset notice, standard Universal Analytics properties stopped processing data on July 1, 2023, and Analytics 360 properties with a current contract got a one-time extension to July 1, 2024. From the week of July 1, 2024, the Universal Analytics interface and API were shut down and access to its data ended.

So if your site still has a UA- snippet in its header, it is collecting nothing. Remove it and set up GA4 instead. GA4 IDs are called Measurement IDs and start with G-.

How do I create a GA4 property for my site?

Do this first, whichever WordPress method you choose. These steps follow Google's guide to setting up Analytics for a website.

  1. Go to analytics.google.com and sign in. If it is your first time, select Start measuring.
  2. Create an account, then create a property: give it a name, and pick your time zone and currency.
  3. Answer the questions about your business and how you plan to use Analytics.
  4. Choose Web as the platform, enter your site's URL and a stream name, and create the stream. Google recommends leaving enhanced measurement turned on, since it collects page views and other events automatically.
  5. Under the stream details, note your Measurement ID (it starts with G-).

Method 1: How do I connect GA4 with Site Kit?

Site Kit by Google is Google's official WordPress plugin. It places the Google tag for you and shows Analytics and Search Console data in your WordPress dashboard, with no code editing. When we checked the Site Kit listing on wordpress.org on 2026-11-06, it was at version 1.191.0, updated on 2026-11-02, tested with WordPress 7.1.4, and active on more than 5 million sites.

Google's Site Kit setup guide for G- tags gives these steps. Your site must be publicly reachable, not in maintenance mode or behind a password.

  1. In WordPress, go to Plugins, then Add New, search for "Site Kit" and select Install Now on Site Kit by Google.
  2. Select Activate, then open Site Kit in the left menu.
  3. Tick Connect Google Analytics as part of your setup and select Sign in with Google.
  4. Choose the Google account that owns your GA4 property and grant the permissions it asks for.
  5. Select Proceed to verify site ownership, then Allow to give access to your Google account data.
  6. Select Add site to add the site to Search Console.
  7. Select Set up Google Analytics, choose your GA4 property, and select Complete setup.

Site Kit's own FAQ notes that it can take a few days after connecting for data to appear in its dashboard; the Realtime report in Google Analytics shows visits sooner.

Method 2: How do I add the Google tag manually?

If you prefer no plugin, Google's instructions say to paste your Google tag immediately after the <head> tag on every page of your site. In GA4, open your web stream, select View tag instructions, choose Install manually and copy the snippet. It looks like this, with your own ID:

<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>

Where you paste it depends on your theme:

  • Classic themes: Google's article on setting up the Google tag with the WordPress editor says to go to Appearance, then Theme File Editor, open Theme Header (header.php), paste the snippet and select Update File. Do this in a child theme. The WordPress developer handbook explains that a child theme lets the parent theme update without losing your changes, while edits made directly to the parent are overwritten.
  • Block themes: these have no header.php, so the step above does not apply. Use Site Kit, or a header-and-footer code plugin such as WPCode, which lets you paste code like the Google tag into the site header without editing theme files.

What we checked: on 2026-11-06 we looked at the files of Twenty Twenty-Five 1.5, which is the default theme in WordPress 7.1.4. It has no header.php file at all; its header is a block template part (parts/header.html). So on a fresh WordPress install, Google's Theme File Editor method has nowhere to go, and Site Kit is the simpler route.

Only use one method. If Site Kit is placing the tag, do not also paste a manual snippet with the same ID, or the tag loads twice on every page.

How do I verify Google Analytics is working?

  1. Open your website in a browser (a private window is fine).
  2. In Google Analytics, open the Realtime report.
  3. You should see at least one active user within a few minutes. Google says data collection may take up to 30 minutes to begin.

If nothing appears after 30 minutes, view your page source and search for your G- ID. If it is missing, the tag is not on the page; if it appears twice, remove one copy.

If you would rather not use Google at all, see our guide to Google Analytics alternatives.

FAQ

Can I still use my old UA- tracking code?

No. Standard Universal Analytics stopped processing data on July 1, 2023, and access ended from the week of July 1, 2024. Replace the old snippet with a GA4 Google tag.

Is Site Kit free?

Yes. Site Kit by Google is a free plugin from Google on wordpress.org.

Where do I find my GA4 Measurement ID?

In Google Analytics, go to Admin, then Data streams, and open your web stream. The Measurement ID starting with G- is shown in the stream details.

Why does GA4 show no data after I added the tag?

Wait up to 30 minutes, then check the Realtime report. If it is still empty, confirm the tag is in the page source once, and that the ID matches your property. If you use a caching plugin, clear its cache so visitors get the updated page.

Muhammad Dilawar
Muhammad Dilawar
Muhammad Dilawar is a WordPress developer and technical SEO specialist with over 12 years of experience building, optimizing and maintaining websites. He works with WordPress, WooCommerce, server optimization, DNS, SSL, Cloudflare, website security and performance, and is a Top Rated freelancer on Upwork with a 100% recommendation rate.
More from Muhammad Dilawar →