How to Set Up Google Analytics 4 on WordPress (3 Easy Ways)

Set up Google Analytics on WordPress

Google Analytics tells you how many people visit your blog, where they come from, which posts they read, how long they stay, and what they do on the page. It is free, and it takes about 15 minutes to set up on WordPress. This guide covers Google Analytics 4 (GA4), the only version that exists now: Universal Analytics, which the original version of this post described, stopped collecting data in 2023 and its “UA-” tracking IDs no longer work.

Below: creating a GA4 property, three ways to connect it to WordPress (from easiest to most manual), how to check it works, and the settings worth changing on day one.

Step 1: Create a Google Analytics 4 Property

  1. Go to analytics.google.com and sign in with your Google account.
  2. Click Start measuring (or Admin > Create > Account if you already have one). Name the account (your name or business).
  3. Create a property: name it after your blog, choose your time zone and currency.
  4. Answer the business questions (size, goals); they only change which reports are shown by default.
  5. Choose Web as the platform, enter your site URL and a stream name, and leave Enhanced measurement on. It automatically tracks scrolls, outbound clicks, site search, file downloads, and video engagement.
  6. Click Create stream. Copy the Measurement ID, which starts with G-. You need it in the next step.

Step 2: Connect GA4 to WordPress

Use only one of these methods; adding the tag twice double-counts every visit.

Option A: Site Kit by Google (easiest)

Site Kit is Google’s official plugin. Install and activate it, click Start setup, sign in with the same Google account, and choose to set up Analytics. It can create the GA4 property for you or connect the one you just made, adds the tracking code automatically, and also connects Search Console, so you see both in the WordPress dashboard. It is the best option for beginners.

Option B: Your SEO plugin or theme

If you already use an SEO plugin, you may not need another one. Rank Math connects GA4 in its Analytics module (Rank Math > General Settings > Analytics) and shows traffic beside your keyword data. All in One SEO and MonsterInsights do the same. Many themes (Kadence, Astra, GeneratePress Premium, Divi) also have a field for the tracking code or a hooks area where you can paste it.

Option C: Add the code manually

In GA4, open your web stream and click View tag instructions > Install manually. Copy the code, which looks like this:

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

The safe way to add it is with the free WPCode plugin: go to Code Snippets > Header & Footer, paste it in the Header box, and save. Do not edit your theme’s header.php file directly, as the old version of this guide suggested; the change is lost the next time the theme updates. If you use Google Tag Manager, add GA4 as a tag inside GTM instead (see our Google Tag Manager guide).

Step 3: Check That It Works

  1. Open your blog in a private browser window and click around for a minute.
  2. In GA4, go to Reports > Realtime. You should appear as an active user within a minute or two.
  3. For a deeper check, install the free Google Tag Assistant Chrome extension or use GA4’s DebugView.
  4. Standard reports fill in within 24 to 48 hours.

Step 4: Settings Worth Changing on Day One

  • Data retention: Admin > Data collection and modification > Data retention. Change from 2 months to 14 months so your explorations can look back further.
  • Exclude your own visits: Admin > Data streams > your stream > Configure tag settings > Define internal traffic, then activate the filter under Data filters.
  • Link Search Console: Admin > Product links > Search Console links, so you see search queries alongside behavior.
  • Mark key events: if you have a newsletter signup or purchase, mark that event as a key event (Admin > Events) so GA4 reports conversions.
  • Consent: if you have visitors from the EU or UK, use a cookie consent plugin that supports Google Consent Mode v2 (Complianz, CookieYes, or Site Kit’s consent mode setting) before collecting analytics data.

The Reports You Will Actually Use

  • Reports > Acquisition > Traffic acquisition: where visitors come from (organic search, social, referral, direct).
  • Reports > Engagement > Pages and screens: your most visited posts and how long people engage with them.
  • Reports > Engagement > Events: outbound clicks (useful for affiliate links), scrolls, and downloads.
  • Search Console reports (after linking): which Google searches lead to which pages.

Simpler Alternatives

GA4 is powerful but complex. If you only want visitor counts and top posts, Jetpack Stats shows them in the WordPress dashboard, and privacy-friendly tools such as Plausible and Fathom give a one-page dashboard without cookies, so no consent banner is needed. Many bloggers run one of these alongside GA4. Whichever you use, also verify your site in Google Search Console and submit your sitemap.

Frequently Asked Questions

Is Google Analytics free?

Yes. GA4 is free for websites of any normal size. The paid Analytics 360 is for very large enterprises.

My old tracking ID starts with UA-. What should I do?

Universal Analytics stopped processing data in July 2023, so a UA- code collects nothing. Create a GA4 property, connect it with one of the methods above, and remove the old code.

Why are my visitor numbers lower than in my other stats plugin?

Ad blockers and visitors who decline cookies are not counted by GA4, and different tools define a “visit” differently. Look at trends over time rather than comparing exact numbers between tools.

Do I need a plugin to use Google Analytics?

No, but a plugin such as Site Kit or WPCode is the safest way to add the code, because it survives theme updates and theme changes.

Comments

11 responses to “How to Set Up Google Analytics 4 on WordPress (3 Easy Ways)”

Leave a Reply

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

  1. Siobhan du to it Avatar
    Siobhan du to it

    I’m trying option 3 but under dashboard and appearance I don’t have editor… Help?

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      It seems that your theme doesn’t have the editor option. Try any of these plugins: http://wordpress.org/plugins/tags/google-analytics

  2. fahim mahmud chisti Avatar
    fahim mahmud chisti

    i completed add my word-press blog Google Analytic for see your article but whats plugin batter for word-press
    (seo by yoast) or (All in One SEO Pack ) which is batter

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Here at RoadToBlogging, I am using All in One SEO Pack.

      1. Rajesh Rao Avatar
        Rajesh Rao

        I saw the seo by yoast being suggested by wordpress guys themselves.

  3. Vk Verma Avatar
    Vk Verma

    Hi.. i read ur article… this is very interesting… but i have one for step, anlytics code can be paste in Text widget also.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      I didn’t know it could be done such way. Thanks for sharing.

  4. Rahul Pahal Avatar
    Rahul Pahal

    Nice step by step guide for installing Google Analytics. Snapshots make it more comfortable to understand. It will definitely help out the newbie bloggers.

  5. seo company Avatar
    seo company

    i think all in one SEO pack is best option to install analytic. i used this and i also use wp editor

  6. Raplus Avatar
    Raplus

    Hey Istiak,

    I think that Option #3 is the best option because we can use option #3 for any theme.

    Try Histats also. It is the best alternative for Google Analytics. Sometimes, it is better than Google Analytics.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Yeah, options #3 is the best option if the user knows what he/she is doing.

      Never tried Hitstats. But I found Clicky useful.