To add Google Analytics to WordPress, create a GA4 property with a Web data stream, copy the Measurement ID that starts with G-, then load Google’s gtag.js snippet on every page. You can do that with a plugin, through Google Tag Manager, by hooking into wp_head in a child theme, or through a field your theme already provides.
wp_head) and check Reports → Realtime within 30 minutes. Pick one method only — two installs double-count every page view.This guide assumes you have a live WordPress site and admin access, plus a Google account. You do not need a paid plan: GA4 is free at the volumes a normal blog or small business site produces. If you are still building on your machine, tracking a localhost install is mostly pointless, so finish setting up WordPress on a local host first and add analytics once the site is public.
analytics.js is obsolete. GA4 is the only version, and Google now calls the snippet the Google tag rather than the Analytics tag, because the same ID can also feed Google Ads.Step 1: Create a GA4 property and a Web data stream
Sign in at analytics.google.com. If this is your first property, the onboarding wizard walks you through it. Otherwise:
- Click the gear icon for Admin in the bottom left.
- Click Create at the top, then choose Property.
- Name the property after your site, set the reporting time zone and currency, and click Next. Get the time zone right — it decides where your “days” start, and changing it later leaves a seam in the data.
- Answer the industry and business-size questions, then click Create and accept the terms.
- Under Data collection and modification, open Data streams, click Add stream and pick Web.
- Enter your URL and a stream name. Leave Enhanced measurement on.
- Click Create stream.
Enhanced measurement is worth understanding before you start building anything custom. With the toggle on, GA4 already collects page_view, scroll, outbound click, view_search_results, file_download, form_start, form_submit and the video events without a line of code. Most people who ask how to track a custom event in Google Analytics find half of what they wanted is already there.
Step 2: Find your Measurement ID
Open Admin → Data collection and modification → Data streams and click the stream. The Measurement ID sits at the top right of the stream details panel and looks like G-XXXXXXXXXX. That single string is all any plugin needs. If you want the full snippet instead, click View tag instructions and then Install manually.
The four install methods compared
| Method | Difficulty | Survives theme updates? | Extra features | Page weight |
|---|---|---|---|---|
| Plugin (Site Kit or a GA4 plugin) | Easiest | Yes | Dashboard reports, logged-in exclusion, consent hooks | Highest — plugin PHP plus the tag |
| Google Tag Manager container | Medium | Yes, if added by plugin or child theme | Every other pixel and tag from one place, versioning | One extra container request |
gtag.js via wp_head in a child theme | Needs PHP comfort | Yes (child theme) / No (parent theme edit) | None — you build what you need | Lowest |
| Theme’s built-in analytics field | Easiest | Yes, but dies if you switch themes | None | Lowest |
Method 1: A plugin
Site Kit by Google is the safe default. It is Google’s own plugin, sits on more than five million sites, and connects Search Console, Analytics, PageSpeed Insights, AdSense and Tag Manager behind one OAuth flow. Install it from Plugins → Add New, run the setup wizard, sign in with the Google account that owns the property, and pick your property and Web data stream from the dropdowns. Site Kit writes the tag for you and pulls a summary of your traffic into the WordPress dashboard.
Dedicated GA4 plugins are lighter and give you more control over things like ecommerce parameters or custom dimensions. Whichever you pick, remember the settings live in your database, not in a file — useful context when you are hunting down a stale ID later and wondering where WordPress plugin settings are stored.
page_view hits, a bounce rate that looks impossibly good, and session numbers you cannot trust.Method 2: Google Tag Manager as the container
If you expect to add more than one tracking tool — a conversion pixel, a heatmap script, a chat widget — put Tag Manager in first and let GA4 live inside it. You install one container, then add and remove everything else from the Tag Manager interface without touching WordPress again. The full walkthrough is in our guide to installing Google Tag Manager on WordPress correctly, including the second snippet that most tutorials get wrong. The same container is how you would later add something like the TikTok pixel without another plugin.
Method 3: The gtag.js snippet in wp_head
This is the lightest option and the one I use on sites where speed matters more than convenience. Put it in a child theme’s functions.php, or in a code-snippets plugin such as WPCode if you would rather not touch theme files at all. Editing the parent theme directly works until the next theme update wipes it out.
<?php
// Child theme functions.php
// Replace G-XXXXXXXXXX with your own Measurement ID.
add_action( 'wp_head', 'geekblog_ga4_tag', 1 );
function geekblog_ga4_tag() {
// Keep your own admin sessions out of the data.
if ( is_user_logged_in() ) {
return;
}
?>
<!-- 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
}The priority of 1 pushes the tag near the top of <head>, which is what Google asks for. The async attribute means it will not block rendering.
Method 4: Your theme’s built-in field
Plenty of commercial themes ship a “Google Analytics” or “Header scripts” box in their options panel. Paste the Measurement ID or the whole snippet, save, done. It is fine, and it is the fastest route for a non-technical client. The catch is portability: switch themes and your tracking silently disappears. Most other content systems have the same trade-off, so if you are weighing platforms, our walkthrough of how to create a Joomla website covers where the equivalent template and plugin hooks live there.
Step 3: Verify the tag is actually firing
Do all three of these, in order. They catch different failures.
- Realtime report. Open your site in a private window, click through two pages, then look at Reports → Realtime in GA4. You should see yourself within a minute or two. Google says collection can take up to 30 minutes to begin on a brand new stream.
- Tag Assistant. Go to tagassistant.google.com, click Add domain, enter your URL and click Connect. A debug window opens and lists every Google tag on the page, each event, and any errors. This is where duplicate tags become obvious — you will see two containers or two G- IDs side by side.
- View source. Load your homepage, view source, and search for
gtag/js?id=. Exactly one hit is correct. Zero means the tag never rendered; two means you installed it twice.
Exclude your own traffic
An analytics account that counts your own editing sessions is worse than useless on a low-traffic site. Two filters fix it.
Logged-in users. The is_user_logged_in() check in the snippet above handles this. Most GA4 plugins offer the same thing as a checkbox, usually phrased as excluding administrators and editors.
Your IP address. In GA4, open Admin → Data collection and modification → Data streams, click the stream, then Configure tag settings → Show more → Define internal traffic → Create. Add your office and home IP ranges. That rule stamps matching hits with a traffic_type of internal but does not remove them yet. Then go to Admin → Data collection and modification → Data filters, create an Internal Traffic filter, and switch it from Testing to Active. Google notes it takes roughly 24 to 36 hours to take effect.
Test data filter name dimension before you activate it. Active filters permanently drop data, and a wrong IP range means a chunk of real visitors vanishes with no way to get them back.Consent mode and why US publishers still need a cookie notice
Google’s consent mode lets the tag load in a restricted state until a visitor makes a choice, and it is mandatory if you serve visitors in the EEA or UK. In the US there is no federal equivalent, but that does not mean you can ignore it. More than twenty states have now enacted comprehensive consumer privacy laws, and several more took effect in January 2026. Most give residents the right to opt out of the sale or sharing of personal data and targeted advertising, and several require you to honor a browser-level opt-out signal such as Global Privacy Control.
Practically: if you only run plain GA4 with no advertising features, a clear privacy policy and a working opt-out link are usually enough. The moment you switch on Google Signals, remarketing, or an ad pixel, you are into “sharing for targeted advertising” territory and you want a consent banner that actually gates the tags. A consent management plugin that supports Google consent mode is the cheapest way to do it properly. The IAPP state privacy legislation tracker is the reference I check when a client asks which states apply to them.
Connect Search Console
Do this while you are in the Admin screen. Go to Admin → Product links → Search Console links and link the Search Console property for the same domain. You need Editor access in Analytics and verified owner status in Search Console. Once linked, the Google Organic Search Queries and Google Organic Search Traffic reports appear in GA4, which is what lets you see the query that earned a session next to what that session did. Data takes about 48 hours to show up.
Troubleshooting
No data after 24 hours
Check the page source for gtag/js?id= first. If the snippet is missing, a caching or optimization plugin is probably stripping or deferring it — purge the cache and exclude the tag from JavaScript minification and delay-until-interaction settings. If the snippet is present, confirm the ID in your source matches the ID in the data stream character for character. A trailing space pasted into a theme field breaks it silently.
Duplicate page views
Almost always two installs. Common combinations: Site Kit plus a standalone GA4 plugin, a theme field plus a plugin, or a GA4 tag inside Tag Manager while gtag.js is also hardcoded. Remove one. Tag Assistant will show you both.
Ad blockers and browser protections
Expect to lose traffic. Blockers, Safari’s tracking prevention and privacy-focused browsers all drop GA4 requests, and the gap is real — a technical audience blocks far more than a general one. Your GA4 numbers are a consistent sample, not a census. Compare GA4 trends against server logs or Search Console clicks rather than treating either as absolute truth.
“Data stream is not receiving traffic”
This banner in the stream details usually means the tag has genuinely never fired, not that something subtle is wrong. Work through it in this order: is the site public and not password-protected, is the tag on the page, is the tag on the page the visitor actually loads (a cached AMP or mobile variant may differ), and is your own traffic already being filtered out by an internal-traffic rule you forgot about.
Old UA property still connected
If a plugin or theme field still holds a UA- code, delete it. It does nothing, adds a request, and confuses whoever inherits the site. If you need to confirm what is stored where, our guide to running a database query in WordPress shows how to search the options table for a stray ID.
Frequently asked questions
Do I need a plugin to add Google Analytics to WordPress?
No. A plugin is the easiest route, but the gtag.js snippet in a child theme’s wp_head hook does the same job with less overhead. Use a plugin if you want in-dashboard reports and a checkbox for excluding logged-in users; skip it if page weight is your priority.
Where do I find my GA4 Measurement ID?
In Google Analytics, open Admin → Data collection and modification → Data streams, click your web stream, and read the Measurement ID at the top of the stream details panel. It starts with G- followed by ten characters. That is the only value most plugins ask for.
Is Google Analytics still free in 2026?
Yes. The standard GA4 property is free and covers the event volumes typical WordPress sites generate. Google sells Analytics 360 for enterprises that need higher limits, longer retention and service guarantees, but nothing about basic web tracking sits behind a paywall.
How long until data appears in GA4?
Realtime usually shows a visit within a minute or two, and Google allows up to 30 minutes for collection to begin on a new stream. Standard reports lag further: expect up to 24 to 48 hours before the main reports and comparisons look complete.
Should I use Google Tag Manager instead of installing GA4 directly?
Use Tag Manager if you will run more than one tag, want version control, or need to hand tag changes to a marketer without deploy access. For a single GA4 install on a small site, direct installation is simpler and one request lighter.
Will Google Analytics slow down my WordPress site?
Barely, if installed correctly. The gtag.js file is small and loads asynchronously, so it does not block rendering. The real cost comes from stacking a heavy plugin on top of it, or from delay-until-interaction settings that push the tag so late that you lose short visits entirely.
Wrapping up
For most people the answer is Site Kit by Google, one property, one data stream, and an internal-traffic filter you actually verified. It takes fifteen minutes and it will not break when you update your theme. Choose the wp_head snippet instead if you care about every kilobyte, and choose Tag Manager if you already know you will be adding more tags.
Whatever you pick, install it once, verify it in Tag Assistant, and resist the urge to add a second plugin “just to be sure”. Then spend your time on the part that pays: turning the numbers into decisions, which is where our guide to using Google Analytics for marketing picks up.

