How to Add Google Analytics to WordPress (GA4 Step by Step)

7 min read
How to add Google Analytics to WordPress
On this page
  1. What you need before you start
  2. Step 1: Create a Google Analytics account
  3. Step 2: Create a GA4 property
  4. Step 3: Add a web data stream and find your Measurement ID
  5. Step 4: Add the Google tag to WordPress
  6. Step 5: Check that Google Analytics is working
  7. Common problems
  8. What to do next
  9. FAQ

Google Analytics shows you how many people visit your WordPress site, where they come from and which pages they read. Adding it takes about ten minutes: you create a free GA4 property, copy your Measurement ID or Google tag, and add it to your site once. We set it up on this site on 22 November 2026, and every screenshot below comes from that real setup.

Quick answer: in Google Analytics, create an account, a property and a Web data stream for your domain. Copy the Google tag from Admin → Data streams → your stream → View tag instructions → Install manually. In WordPress, install the free WPCode plugin, paste the tag into Code Snippets → Header & Footer → Header, save, clear your cache, then check the Realtime report.

What you need before you start

  • A Google account (the one you want to own the Analytics data).
  • Admin access to your WordPress dashboard. If you are not sure how to get in, see how to log in to WordPress.
  • About ten minutes. Realtime data shows up within minutes; the standard reports can take 24 to 48 hours to fill in.

Step 1: Create a Google Analytics account

Go to analytics.google.com, sign in, and click Start measuring (or Admin → Create → Account if you already use Analytics for another site). Give the account a name you will recognise, such as your brand or blog name. The data-sharing checkboxes below it are optional.

Google Analytics Create an account screen with the account name field

Tip: if you manage sites for clients, give each business its own account. It keeps the data separate and makes it easy to hand over access later.

Step 2: Create a GA4 property

Click Next. The property is where your site’s data lives. Use your domain as the property name, then pick the reporting time zone and currency. Choose the time zone of your main audience: a US-focused blog should report in a US time zone so “today” in your reports matches your readers’ day.

Google Analytics Create a property screen with property name, time zone and currency

The next two screens ask for your industry, business size and goals. They only change which reports Google suggests, so pick whatever fits best. Click Create and accept the Google Analytics Terms of Service for your country.

Step 3: Add a web data stream and find your Measurement ID

Google now asks where the data comes from. Choose Web, enter your site address (for example yourblog.com), give the stream a name and click Create stream. Leave Enhanced measurement switched on: it tracks scrolls, outbound clicks, site search and file downloads without any extra code.

The stream page shows your Measurement ID, a code that starts with G-. You can always find it again under Admin → Data streams.

GA4 web stream details showing the Measurement ID

To get the full tag, scroll down on the same page and click View tag instructions, then open the Install manually tab and click the copy icon.

Google tag installation instructions with the Install manually code snippet

Copy the snippet Google shows you, not one from a tutorial. The exact code changes over time: in November 2026 Google’s snippet loaded gtm.js?id=G-…, while older guides (and the tag on this site) use gtag/js?id=G-… plus a config line. Both send data to GA4. What matters is that the ID is yours.

Step 4: Add the Google tag to WordPress

There are three good ways to do this. Pick one: installing the tag twice counts every visit twice.

This is the simplest way to add code to every page without touching theme files, and it survives theme changes and updates.

  1. In WordPress, go to Plugins → Add New, search for WPCode, then install and activate it (see how to install a WordPress plugin if you need a walkthrough).
  2. Open Code Snippets → Header & Footer.
  3. Paste the Google tag into the Header box. WPCode prints it in the <head> of every page, which is where Google wants it.
  4. Click Save Changes.
WPCode Global Header and Footer with the Google tag pasted in the Header box

If you use a cache plugin such as LiteSpeed Cache, purge the cache now so visitors get pages with the new tag. Our LiteSpeed Cache settings guide shows where the Purge All button is.

Method 2: Rank Math’s Analytics module

If you already use Rank Math SEO, go to Rank Math SEO → General Settings → Analytics, click Connect Google Services and approve access with your Google account. Then choose your Analytics account, property and data stream, and switch on Install analytics code. You also get Search Console and Analytics stats inside WordPress.

One thing we noticed: a brand-new Analytics account did not appear in Rank Math’s list straight away, even after reconnecting. If that happens to you, use method 1 for now, and only switch on Rank Math’s Install analytics code later if you remove the WPCode snippet first.

Method 3: Site Kit by Google

Site Kit is Google’s own WordPress plugin. You install it, sign in with Google and it adds the tag for you, plus dashboards for Analytics and Search Console. It works well if you want everything inside WordPress. It is a heavier plugin than WPCode, and we did not use it on this site, so we cannot show you our own screenshots of it.

We do not recommend pasting the tag into your theme’s header.php: a theme update or a theme switch removes it without warning.

Step 5: Check that Google Analytics is working

Go back to the View tag instructions panel in Analytics, type your site address under Test your website and click Test. A green check means Google found the tag on your homepage.

Google tag test showing a green check for the website

Then open your site in another browser tab and, in Analytics, go to Reports → Realtime overview. Within a minute or so you should see yourself as an active user and the page you opened.

GA4 Realtime overview showing an active user on the site

The standard reports (Traffic acquisition, Pages and screens, Demographics) can take 24 to 48 hours to show data. If Realtime works, you are set.

Common problems

  • Realtime shows 0 users: clear your cache plugin and any server or CDN cache, then reload your site. An ad blocker in your own browser can also block Analytics, so test in a private window with extensions off.
  • Visits are counted twice: the tag is installed in two places (for example WPCode and Rank Math or Site Kit). Keep one and remove the other.
  • The test says no tag was found: check that the snippet is in the Header box, not the Body or Footer box, and that you saved. Make sure the ID in the code matches the one on your data stream.
  • Your own visits inflate the numbers: in Analytics, go to Admin → Data streams → your stream → Configure tag settings → Define internal traffic to exclude your IP address, then activate the internal traffic filter under Admin → Data filters.

Visitors from the EU or UK? Privacy laws there generally require consent before analytics cookies are set. A cookie consent plugin that supports Google Consent Mode handles this. This is general information, not legal advice.

What to do next

Once data starts coming in, connect Search Console too, so you can see which Google searches bring people to your site. If you are still building your site, our guide to starting a WordPress blog on Hostinger walks through the full setup, and the plugins we actually use lists the short set we install on every site.

FAQ

Is Google Analytics free?

Yes. Standard Google Analytics (GA4) is free. There is a paid version, Analytics 360, for large companies, but a blog or small business site does not need it.

Do I need a plugin to add Google Analytics to WordPress?

No, but a small plugin like WPCode is the safest way to add the code without editing theme files. Editing header.php directly works until your theme updates and overwrites it.

Where do I find my GA4 Measurement ID?

In Google Analytics, go to Admin → Data streams and click your web stream. The Measurement ID is in the top-right corner of the stream details and starts with G-.

How long does it take for data to show up?

The Realtime report updates within a minute or so. The standard reports can take 24 to 48 hours after you install the tag.

Can I use Google Analytics with Rank Math?

Yes. Rank Math’s Analytics module can add the tracking code for you and show your stats in WordPress. Just do not also paste the tag with another plugin, or every visit will be counted twice.

Leave a Reply

Your email address will not be published. Required fields are marked *