Connect WordPress Google Analytics: Complete Guide for GA4 in 2025
Last updated: 31 December 2025
Connect WordPress Google Analytics: Complete Guide for GA4 in 2025
Want to know how many visitors your WordPress site has and what they do? Then you need Google Analytics. Since 2023, Google Analytics 4 (GA4) is the standard - Universal Analytics no longer works. In this guide, you'll learn step by step how to connect Google Analytics to WordPress, both with and without a plugin. We'll also cover event tracking, privacy and GDPR compliance.
What is Google Analytics 4 and Why Do You Need It?
Google Analytics 4 (GA4) is the latest version of Google's free analytics tool. It shows you:
- How many visitors your site has
- Where they come from (Google, social media, direct)
- Which pages are most popular
- How long people stay on your site
- What actions people perform (fill forms, click buttons)
GA4 is different from the old Universal Analytics:
- Event-based tracking: everything is seen as an event
- Cross-platform: track users across website and app
- Privacy-first: less dependent on cookies
- Machine learning: automatic insights and predictions
- Better reporting: more flexible data analysis
For WordPress sites, GA4 is essential to make data-driven decisions about your content, design and marketing.
Create and Set Up GA4 Account
Before connecting GA4 to WordPress, you first need to create an account. This takes just a few minutes.
Step 1: Create Google Analytics Account
- Go to analytics.google.com
- Log in with your Google account
- Click "Start measuring"
- Enter an account name (e.g., your company name)
- Configure account privacy settings
- Click "Next"
Step 2: Create Property
A property is your website within Google Analytics:
- Give your property a name (e.g., "My Website")
- Choose your time zone and currency
- Click "Next"
Step 3: Fill in Business Details
Google asks about your business type and goals. This is optional but helps Google show you relevant features. Fill in what fits you.
Step 4: Select Platform
- Choose "Web" as platform
- Enter your website URL (e.g., https://yoursite.com)
- Give your data stream a name (usually your domain name)
- Click "Create stream"
You'll now see a Measurement ID in the format G-XXXXXXXXXX. You need this to connect GA4 to WordPress. Keep it safe.
Method 1: Connect GA4 with a Plugin (Easiest)
For most WordPress users, a plugin is the easiest way. We'll discuss three popular options.
Site Kit by Google (Free, Official)
Site Kit is Google's official WordPress plugin. It connects not only Analytics but also Search Console, AdSense and PageSpeed Insights.
Installation:
- Go to Plugins > Add New in WordPress
- Search for "Site Kit by Google"
- Click "Install" and then "Activate"
- Click "Start setup" and log in with your Google account
- Give Site Kit access to your Google services
- Select or create your Analytics property
- Complete the setup wizard
Advantages:
- Official Google plugin, always up-to-date
- See reports directly in WordPress dashboard
- Integrates multiple Google tools
- No code needed
Disadvantages:
- Heavier than other plugins
- Fewer configuration options
- Requires Google account login
Site Kit is ideal if you want to use multiple Google tools and see reports in WordPress.
MonsterInsights (Freemium)
MonsterInsights is the most popular Analytics plugin for WordPress with over 3 million installations.
Installation:
- Install and activate MonsterInsights
- Go through the setup wizard
- Connect your Google Analytics account
- Choose your GA4 property
- Configure tracking settings
Advantages:
- User-friendly dashboard in WordPress
- Enhanced tracking for downloads, affiliate links
- E-commerce tracking (Pro version)
- Extensive reporting
Disadvantages:
- Free version has limited features
- Pro version from €99.50 per year
- Can slow down site if not properly configured
MonsterInsights is perfect if you want extensive reporting in WordPress without having to write code.
GA Google Analytics (Free)
A lightweight alternative is the GA Google Analytics plugin by Jeff Starr.
Installation:
- Install and activate GA Google Analytics
- Go to Settings > GA Google Analytics
- Paste your Measurement ID (G-XXXXXXXXXX)
- Choose your tracking method (gtag.js recommended)
- Configure options like exclude admin tracking
- Save settings
Advantages:
- Super fast and lightweight
- No external requests
- Works with GA4 and Universal Analytics
- Free without limitations
Disadvantages:
- No reporting in WordPress
- No enhanced tracking features
- Minimal interface
This plugin is ideal if you only want to add the tracking code without extra features.
Which Plugin to Choose?
- Beginners: Site Kit by Google - official and easy
- Advanced users who want reporting in WP: MonsterInsights Pro
- Performance-minded: GA Google Analytics - fast and lightweight
- Budget: Site Kit or GA Google Analytics - both free
Check our list of best WordPress plugins for more recommendations.
Method 2: Manually Connect GA4 with Code
If you don't want a plugin, you can add the tracking code manually. This is faster and you have full control.
Option A: Code in header.php
Warning: never edit theme files directly - use a child theme or custom plugin.
- Go to Appearance > Theme File Editor
- Open header.php
- Add this code just before
</head>:
<!-- Google Analytics 4 -->
<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>
Replace G-XXXXXXXXXX with your own Measurement ID.
Disadvantages of this method:
- Code disappears with theme updates
- Doesn't work with all themes
- Error-prone for beginners
Option B: Code Snippets Plugin (Recommended)
A better way is to use the Code Snippets plugin:
- Install "Code Snippets" plugin
- Go to Snippets > Add New
- Give your snippet a name: "Google Analytics 4"
- Choose location: "Site Head"
- Paste this code:
<!-- Google Analytics 4 -->
<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>
- Activate the snippet
Advantages:
- Survives theme updates
- Easy to turn on/off
- No theme files to modify
Option C: Google Tag Manager
Google Tag Manager (GTM) is a container for all tracking codes. It gives you the most flexibility.
- Create a free GTM account at tagmanager.google.com
- Create a container for your website
- Add GTM code to your site (via plugin or manually)
- Add a GA4 tag in GTM with your Measurement ID
- Publish your container
GTM is more powerful but has a learning curve. It's ideal if you want to manage multiple marketing tools (Facebook Pixel, LinkedIn Insight, etc.).
Set Up Event Tracking
GA4 is all about events. Some events are tracked automatically, others you need to set up yourself.
Automatic Events
GA4 automatically tracks:
- page_view: page viewed
- scroll: user scrolls 90% of page
- click: outbound links
- video_start/complete: YouTube videos
- file_download: PDFs and other files
- form_start/submit: forms (requires enhanced measurement)
Check in GA4 via Configure > Data Streams > Enhanced measurement if these are enabled.
Set Up Custom Events
For specific actions you can add custom events. For example, tracking a button click:
gtag('event', 'button_click', {
'event_category': 'CTA',
'event_label': 'Buy Now Button',
'value': 1
});
Add this to your button with an onclick attribute or via JavaScript.
MonsterInsights Event Tracking
MonsterInsights Pro can automatically track:
- Downloads (PDF, ZIP, etc.)
- Outbound links
- Affiliate link clicks
- Form submits
- E-commerce transactions
This works without writing code via the plugin settings.
Google Tag Manager Events
In GTM you can create triggers for:
- Element clicks (buttons, links)
- Form submits
- Scroll depth
- Timer events
- Custom JavaScript
This gives you full control without having to place code in your theme.
Solve Common Issues
No Data in Google Analytics
If you don't see data after 24-48 hours:
- Check if your Measurement ID is correct
- Test with browser extension "Google Analytics Debugger"
- Check if you exclude admin traffic (and if you're logged out)
- Check browser console for JavaScript errors
- See if your AdBlocker blocks GA
Double Tracking
Seeing double numbers? Then Analytics is set up twice:
- Check if you have multiple plugins with Analytics
- Search your theme code for gtag or analytics.js
- Remove duplicate codes
Events Not Coming Through
If custom events aren't tracked:
- Check JavaScript console for errors
- Test events with GA4 DebugView (in GA4: Configure > DebugView)
- Check if event name is correct (no spaces or special characters)
Privacy and GDPR Compliance
Google Analytics and privacy are a hot topic. This is how you stay on the right side of the law.
Cookie Notice Required
In the EU you must ask visitors for permission for tracking cookies. Use a cookie banner plugin like:
- Complianz (free + pro)
- CookieYes
- GDPR Cookie Consent
- Borlabs Cookie (German, very compliant)
The banner must give visitors the choice to refuse tracking. Only after "Accept" may you load Analytics.
IP Anonymization
Anonymize IP addresses to protect privacy. In GA4 this is enabled by default, but check it via:
GA4 Admin > Data Settings > Data Collection > IP Anonymization
Google Consent Mode
Google Consent Mode adjusts tracking based on cookie preferences. It works with modern cookie banner plugins.
Advantages:
- Respects privacy choices
- You lose less data than total blocking
- Remains GDPR compliant
MonsterInsights Pro and Complianz support Consent Mode out-of-the-box.
Data Processing Agreement
Sign a Data Processing Agreement (DPA) with Google. This is mandatory under GDPR. Do this via:
- Log in to Google Analytics
- Go to Admin > Account Settings
- Scroll to "Data Processing Amendment"
- Accept the terms
Consider Server-Side Tracking
For maximum privacy you can consider server-side tracking. This sends data via your own server to Google, giving more control. This requires technical knowledge and is complex to set up.
Also check our guide on WordPress security for more privacy best practices.
Frequently Asked Questions
Do I have to pay for Google Analytics?
No, Google Analytics 4 is completely free for most websites. There is a paid version (Analytics 360) for enterprise with more than 10 million hits per month, but for 99% of sites the free version is more than sufficient.
Can I still use Universal Analytics?
No, Universal Analytics stopped collecting data since July 2023. You must switch to GA4. Old data remains available for six months but is then deleted. Switch now if you haven't already.
How long does it take before I see data?
You see real-time data within seconds to minutes. For full reports it can take 24-48 hours before all data is processed. Be patient and don't check every hour - that doesn't provide useful insights.
Do Analytics plugins slow down my site?
Yes, every plugin adds overhead. Heavy plugins like MonsterInsights can add 50-200ms to load time. Lightweight options like GA Google Analytics have minimal impact. Manual code is fastest but requires technical knowledge.
Should I exclude logged-in admins from tracking?
Yes, otherwise you pollute your data with your own visits. Most plugins have an option for this. Manually you can also exclude your IP address in GA4 via Admin > Data Settings > Data Filters.
Does Google Analytics work with caching plugins?
Yes, Analytics works fine with caching. The JavaScript code is executed on the client-side, not on the server. So whether your page is cached or not doesn't matter for tracking.
Is Google Analytics GDPR proof?
This is debatable. Some EU countries (Austria, France) have ruled that GA violates GDPR because data goes to American servers. Use cookie banners, IP anonymization and Consent Mode to be as compliant as possible. Alternatives: Matomo, Plausible, Fathom.
Can I track multiple sites in one GA4 account?
Yes, create a separate property for each site within one account. This keeps data separated but you manage everything centrally. This is more convenient than creating a separate Google account for each site.
Was this article helpful?
Compare hosting packages directly to find the best choice for your situation.
Related articles
What is web hosting? Explanation for beginners
Discover what web hosting is and how it works. Complete explanation about servers, domains and different hosting types for beginners.
What is VPS Hosting?
VPS hosting explained: what is a Virtual Private Server, who is it suitable for and what are the advantages compared to shared hosting?
What is an SSL Certificate?
Everything about SSL certificates: what is SSL, why do you need it and how do you recognize a secure website? Essential for every website.
What is Uptime in Web Hosting?
What does uptime mean in web hosting? Learn about uptime percentages, SLA guarantees and why 99.9% uptime is important for your website.
How much storage do I need for my website?
Discover how much disk space you really need for your website. Practical guide with examples per website type.