If you have a WordPress, you know how crucial it is to understand your visitors. Google Analytics 4 (GA4) is the free reference tool for this: it tells you how many people visit your website, where they come from, which pages they read, and at what point they leave. In this guide, we will connect Google Analytics 4 to WordPress step-by-step, with the three real methods you can use (Site Kit, Google Tag Manager, and manual code), verification that the data is actually arriving, and the legal notice you shouldn't skip if your audience is in Spain or the European Union.
What is a GA4 property and how to create it
Before touching anything in WordPress, you need a GA4 property. In Google Analytics, a property is the container that receives and processes your website's data. Each property has a Measurement ID with the format G-XXXXXXXXXX, and that identifier is what links your WordPress with Analytics.
To create it:
- Go to analytics.google.com with your Google account and click on Admin (the gear icon in the bottom left corner).
- Click Create > Property. Give it a recognizable name (e.g., your website's domain), select Spain as time zone and euro as currency.
- Complete the business details and, in the data collection step, choose Web.
- Enter your site's URL and a name for the data stream. When you save it, Google will show you the measurement ID
G-XXXXXXXXXX.
Note down that ID: you will need it in any of the three following methods. Keep in mind that the old Universal Analytics version (IDs starting with UA-) stopped processing data in 2023, so today everything goes through GA4.
Method 1: Connect Google Analytics 4 to WordPress with Site Kit (recommended)
Site Kit by Google is the official Google plugin for WordPress and the easiest way if you don't want to touch code. In addition to Analytics, it integrates Search Console, AdSense, and PageSpeed Insights into your own WordPress dashboard.
- In your WordPress, go to Plugins > Add New y busca “Site Kit by Google”. Instálalo y actívalo.
- Click the button Start setup and log in with the same Google account where you created the GA4 property.
- Grant the permissions requested by the wizard and verify site ownership (Site Kit does this automatically).
- Inside Site Kit, go to Settings > Connect more services > Analytics, choose your account, your GA4 property, and your web data stream, and confirm.
Site Kit will insert the Google tag for you on all pages of the site, without duplicates and without you having to edit the theme. In 24-48 hours you will start to see summarized reports within WordPress itself, although the complete data will always be on analytics.google.com.
Method 2: Google Tag Manager
If, in addition to Analytics, you are going to use advertising pixels (Meta, Google Ads), custom events, or heat map tools, it's worth using Google Tag Manager (GTM): a single container from which you manage all your tags without touching the website every time.
- Create an account and a web container in tagmanager.google.com. You will get an ID with the format
GTM-XXXXXXX. - Insert the container into WordPress with a plugin like GTM4WP or with a snippet manager. If you already use WPCode, you can paste the two snippets that GTM gives you (one in the
<head>and another after the opening of the<body>) in a couple of snippets with the correct location. - Inside GTM, create a tag of type Google Tag, paste your measurement ID
G-XXXXXXXXXXand assign it the trigger All Pages. - Use the Preview of GTM to check that the tag fires and, when everything works, click Submit to publish the container.
The advantage is clear: the next time you need to add another tag, you'll do it from GTM in two minutes, without installing more plugins or editing templates.
Method 3: Insert the gtag code manually
If you prefer not to rely on any analytics plugin, you can paste the global tag (gtag.js) directly into the <head> of your website. This is the official snippet, replacing G-XXXXXXXXXX with your measurement ID:
<!-- 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>
Where to paste it? The cleanest way is to use a snippet manager like WPCode, the snippet manager that has become essential in WordPress, creando un snippet de tipo HTML con ubicación “Site Wide Header”. Evita editar header.php of the theme directly: you would lose the code in the next theme update, unless you use a child theme. And very important: use only one method. If you install Site Kit and also paste the gtag manually, you will count each visit twice and your data will be inflated.
Verify that data is arriving: the real-time report
Connecting Google Analytics 4 to WordPress doesn't end when you save changes: you need to check that data is flowing. The fastest way:
- Open your website in a browser incognito window (this avoids filters and session caches).
- In GA4, go to Reports > Realtime. You should see at least 1 active user (you) within the next 30 seconds, along with the page you are visiting.
- As an extra check, the Chrome extension Tag Assistant confirms which Google tags are loading on the page.
If real-time doesn't show anything, check three usual suspects: a cache plugin serving an old version of the page (purge the cache), an ad blocker in your own browser, or a wrongly copied measurement ID. Standard reports (Acquisition, Engagement, etc.) take 24 to 48 hours to populate, so don't be alarmed if they appear empty on the first day.
Basic events that GA4 measures automatically
Unlike the previous version, GA4 measures everything as events. With the enhanced measurement activated (it is by default in the web data stream), it will automatically record without any configuration:
page_view: each page view.scroll: when the user reaches 90% of the page.click: clicks to external domains.file_download: PDF, ZIP, and other file downloads.video_startand related: embedded YouTube video plays.view_search_results: internal searches on your website.
When you want to measure something business-related (submitting a contact form, clicking a purchase button), you can create custom events from GTM or mark them as key conversions in GA4 without touching the website code.
GDPR and consent: mandatory in Spain
Google Analytics uses cookies, and in Spain the LSSI and GDPR require prior user consent before loading them. In practice, this means you need a real, not decorative, cookie banner: one that blocks the Analytics tag until the visitor accepts. Plugins like Complianz o CookieYes solve it well in WordPress and integrate the Google Consent Mode (Consent Mode v2), which adjusts tag behavior according to what the user has accepted. Complete the work with a published cookie policy and, in GA4, review Admin > Data Settings to adjust data retention (default 2 months; you can increase it to 14).
And with the data in hand, it's time to optimize
Once GA4 is connected, the interesting part begins: identifying your most visited pages, seeing which channels bring quality traffic, and detecting where navigation gets stuck. If you discover that users abandon due to slowness, we have a practical guide for speed up WordPress with PHP settings in 3 steps. And if you want that traffic to grow, combine analytics with good on-page SEO: we tell you how to install and configure Yoast SEO in WordPress.
Frequently Asked Questions
Is it complicated to connect Google Analytics 4 to WordPress?
No. With Site Kit by Google, the complete process takes less than 10 minutes and doesn't require touching code: you install the plugin, log in with your Google account, connect the Analytics service, and the plugin itself inserts the tag across the entire site. Methods with Google Tag Manager or manual gtag code require a bit more care, but are still affordable for any user following the steps in this guide.
What kind of data can I get with GA4?
GA4 records users, sessions, page views, acquisition channels (organic search, social media, direct traffic, campaigns), approximate demographic data, and events: outbound clicks, file downloads, scroll depth, video plays, and internal searches. You can also define key conversions (form submissions, purchases) and leverage funnel and user path reports to understand the complete journey within your website.
Can I use Google Analytics 4 without a cookie banner?
If your audience is in Spain or the EU, no. GA4 uses cookies and regulations require prior, informed, and revocable consent. The practical solution is a consent plugin (Complianz, CookieYes) that blocks Analytics until acceptance and implements Google's Consent Mode v2. The alternative would be a cookie-less analytics tool, but you would lose integration with the Google ecosystem.