How do I install GA4 on a WordPress site?
Applies to: Google Analytics 4 (GA4)
Last updated: May 2025
Problem
You have a WordPress website and want to install Google Analytics 4 so you can start tracking visitors, user behavior, and conversions.
Solution
There are two main ways to install GA4 on a WordPress site:
- Using a plugin (simplest method, no code required)
- Manually adding the GA4 tracking code to your theme files
Option 1: Install GA4 Using a WordPress Plugin
This is the preferred method for most users.
Popular plugin options:
- Site Kit by Google (official plugin)
- GA Google Analytics
- MonsterInsights (premium features included)
- ExactMetrics
Steps using Site Kit:
- In your WordPress dashboard, go to Plugins > Add New
- Search for Site Kit by Google and click Install Now
- Click Activate, then run the Site Kit setup wizard
- Connect your Google account and authorize Site Kit
- Choose your GA4 property (or create one)
- Site Kit will automatically insert the GA4 tag on all pages
Once installed, GA4 data begins showing in Realtime reports and G Hub.
Option 2: Manually Add GA4 Code to Your Theme
Steps:
- In your GA4 property, go to Admin > Data Streams > Web
- Copy your Measurement ID (e.g., G-XXXXXXXXXX)
- Click View tag instructions > Install manually
- Copy the provided gtag.js code snippet
Example:
<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>
- In WordPress, go to Appearance > Theme File Editor
- Open your theme’s header.php file
- Paste the code just before the
</head>tag - Save the file
This code will now load GA4 on every page of your site.
Testing Your Installation
- Open https://analytics.google.com
- Go to Reports > Realtime
- Visit your WordPress site in a new browser tab
- Confirm your visit appears in Realtime data
You can also use the Google Tag Assistant Chrome extension to verify your tag is working correctly.
Notes
- If you change your theme later, you may need to re-add the manual code
- Plugins are the most reliable method for non-technical users
- Use only one GA4 installation method to avoid duplicate tracking




