How to Add Google Analytics to WordPress (2026 Guide)
Set up Google Analytics 4 on your WordPress site in under 10 minutes. Covers the Site Kit plugin method, manual gtag.js installation, and MonsterInsights for advanced tracking.
Google Analytics 4 (GA4) is the standard analytics platform for tracking website traffic, user behavior, and conversions. Setting it up on WordPress takes under 10 minutes with the right method.
What You'll Track with Google Analytics
- Users and sessions: How many people visit and how often they return
- Traffic sources: Where visitors come from (Google, social, direct, referral)
- Page views: Which pages are most popular
- Engagement: Bounce rate, time on page, scroll depth
- Conversions: Goal completions (form submissions, purchases, sign-ups)
- Real-time data: Active users right now, their location, and current pages
Prerequisite: Create a Google Analytics 4 Property
Before connecting to WordPress, you need a GA4 property.
- Go to analytics.google.com
- Sign in with your Google account
- Click Admin (gear icon, bottom left)
- Under Account, click Create Account (or use existing account)
- Under Property, click Create Property
- Enter:
- Property name: Your site name (e.g., "My Blog")
- Reporting time zone: Your local time zone
- Currency: Your local currency
- Click Next, fill in business details, click Create
- Select Web as your platform
- Enter your Website URL and Stream name
- Click Create stream
- Copy your Measurement ID (format:
G-XXXXXXXXXX)
Method 1: Site Kit by Google (Recommended for Beginners)
Google's official WordPress plugin — the easiest setup with no code required.
Installation:
- In WordPress admin, go to Plugins → Add New
- Search for Site Kit by Google
- Click Install Now → Activate
Setup:
- Go to Site Kit in the left menu
- Click Start Setup
- Click Sign in with Google and authorize with the Google account that owns your GA4 property
- Grant the requested permissions
- Verify site ownership (Site Kit handles this automatically)
- On the "What do you want to connect?" screen, check Google Analytics
- Select your GA4 property from the dropdown
- Click Configure Analytics
Benefits of Site Kit:
- Also connects Google Search Console, PageSpeed Insights, and AdSense
- Shows analytics data directly in your WordPress dashboard
- Handles tracking code placement automatically
- Excludes WordPress admins from being tracked (can be toggled)
Method 2: Manual Installation (No Plugin)
Add the Google tag directly to your WordPress theme — the cleanest method.
Get your gtag.js code:
- In GA4, go to Admin → Data Streams → [your stream]
- Under Tagging Instructions, click Install manually
- Copy the
<script>code block shown
Add to WordPress theme:
Option A — Theme header.php:
- Go to Appearance → Theme File Editor
- Select
header.php(orfunctions.php) - Paste the GA code just before
</head>
Option B — Functions.php:
- Go to Appearance → Theme File Editor
- Select
functions.php - Add this code, replacing
G-XXXXXXXXXXwith your Measurement ID:
function add_google_analytics() {
?>
<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
}
add_action('wp_head', 'add_google_analytics');
Warning: Don't edit theme files directly if using a non-child theme — updates will overwrite your changes. Use a child theme or a code snippet plugin like WPCode instead.
Option C — WPCode Plugin (Safest Manual Method):
- Install WPCode plugin (formerly Insert Headers and Footers)
- Go to WPCode → Header & Footer
- Paste the GA script in the Header section
- Click Save Changes
This method survives theme updates and is easy to manage.
Method 3: MonsterInsights (Best for Advanced Tracking)
MonsterInsights is the most popular GA plugin with 3+ million installs, offering advanced eCommerce and event tracking.
- Install MonsterInsights (free version from WordPress.org)
- Go to Insights → Settings
- Click Connect MonsterInsights
- Authorize with your Google account
- Select your GA4 property
- Click Complete Connection
MonsterInsights advantages:
- Enhanced eCommerce tracking for WooCommerce (Pro)
- Event tracking (button clicks, video plays, downloads) without code
- Author tracking, form tracking, custom dimensions
- Dashboard reports inside WordPress without opening GA
Free vs Pro:
- Free: Basic pageview tracking, audience reports, top pages
- Pro ($99.50/year): Enhanced eCommerce, form tracking, advanced reports
Method 4: Google Tag Manager
For sites with multiple tracking tags (GA4, Facebook Pixel, Hotjar, etc.), GTM is the most efficient approach.
- Create a GTM account at tagmanager.google.com
- Create a Container for your website
- Add the GTM container code to WordPress (use WPCode for header/body code)
- In GTM, create a GA4 Configuration tag with your Measurement ID
- Set the trigger to All Pages
- Submit and Publish the container
Once GTM is set up, add all future tracking tags through GTM without editing WordPress code.
Verifying Your Analytics Installation
Check with GA4 Realtime Report:
- Open GA4 in one browser
- Go to Reports → Realtime
- In a different browser or incognito window, visit your website
- The realtime report should show 1 active user in the past 30 minutes
Check with GA Debugger Chrome Extension:
- Install "Google Analytics Debugger" from the Chrome Web Store
- Enable it and reload your website
- Open Chrome DevTools → Console
- You should see GA4 event logs confirming the tag is firing
Check the network tab:
- Open DevTools → Network tab
- Filter by
google-analytics.comorgtag - Reload your page
- You should see a request to
google-analytics.com/g/collect
Exclude Your Own Traffic
You don't want your own visits inflating analytics data.
Method 1 — IP Filter (GA4):
- In GA4, go to Admin → Data Streams → [stream] → Tag Settings → Show All
- Click Define internal traffic
- Add your IP address with the rule type IP address equals
- In Admin → Data Filters, create a filter to exclude internal traffic
Method 2 — Browser Extension: Install "Block Yourself from Analytics" Chrome extension — cookies-based, simpler than IP filters.
Method 3 — Site Kit setting: In Site Kit settings, toggle Track logged-in administrators OFF.
Important Events to Track
GA4 automatically tracks:
- Page views
- Scroll depth (90% scroll)
- Outbound link clicks
- Site search (if you have a search form)
- Video engagement (YouTube embeds)
Set up manual event tracking for:
- Contact form submissions → use WPForms or Contact Form 7 events
- Button clicks (affiliate links, CTAs)
- File downloads (PDF, ZIP files)
- WooCommerce purchases (requires MonsterInsights Pro or manual GTM setup)
Already tracking your site's performance? Pair Google Analytics with a fast host to ensure the site you're measuring delivers good experiences. Hostinger starts at $2.99/month and includes everything you need to launch.
Free Download
2026 Web Hosting Comparison Cheat Sheet
- ✓11 hosts ranked by speed, uptime & price
- ✓Renewal price traps to avoid
- ✓Best host for WordPress, WooCommerce & agencies
- ✓Exclusive discount codes for 2026
Free · Join 2,400+ readers · Unsubscribe anytime