Google Analytics 4 (GA4) is Google's latest analytics platform, replacing Universal Analytics with an event-based tracking model that provides deeper behavioral insights, cross-device tracking, and built-in support for privacy consent regulations like GDPR.
This guide covers three methods to install GA4 on WordPress — from the simplest plugin approach to manual code and Google Tag Manager. Choose the method that matches your skill level.
Before you start: Create a GA4 Property at analytics.google.com first. You'll need the Measurement ID (format: G-XXXXXXXXXX) for all three methods below.
Step 1: Create a GA4 Property
- Go to analytics.google.com and sign in
- Click Admin (gear icon, bottom left)
- Under Property, click Create Property
- Enter your property name, timezone, and currency
- Select your industry and business size
- Choose Business Objective (select "Get baseline reports" if unsure)
- Select Platform: Web
- Enter your website URL and stream name → click Create stream
- Copy the Measurement ID (G-XXXXXXXXXX) — you'll need this below
Which Method Should You Choose — Plugin vs Manual gtag
Before you start, it helps to understand the big picture. There are two broad ways to add GA4 to WordPress: using a plugin (such as Site Kit by Google or MonsterInsights) or embedding the gtag.js snippet yourself in your theme or page header (the manual approach). Each option trades off ease of use, page weight, and how much control you keep over the code.
The plugin route is ideal if you never want to touch code, because everything is configured through a setup wizard. MonsterInsights additionally surfaces reports right inside your WordPress dashboard and offers ready-made event tracking (outbound link clicks, file downloads), although many advanced features live behind its paid tiers. Google's own Site Kit is completely free and wires up Consent Mode v2 for you automatically.
Embedding gtag.js yourself is lighter because it adds no extra plugin, reduces the risk of plugin conflicts, and gives you full control over where the snippet loads. The trade-off is that you must maintain it yourself when Google updates the snippet, and if you place it in the wrong spot (for example, not inside the <head>) some pages may not be tracked.
| Criteria | Plugin (Site Kit / MonsterInsights) | Manual gtag in theme / header |
|---|---|---|
| Setup difficulty | Very easy, wizard-based | You edit code yourself |
| Coding required | None | Copy the gtag.js snippet |
| Impact on site speed | Adds a plugin (slight overhead) | Lightest — no plugin |
| Consent Mode v2 | Automatic with Site Kit | Configure it manually |
| Reports in WP Admin | Yes (Site Kit / MonsterInsights) | No — view in GA4 only |
| Best for | Beginners / no-code users | Developers / lightweight sites |
Quick takeaway: If you're just starting and want the fastest path, choose Site Kit; if you want reports inside WordPress with ready-made events, choose MonsterInsights; if you prioritize a lightweight site and full control, embed gtag.js through your theme or a header-insertion plugin.
Method 1 — Site Kit by Google Plugin (Easiest)
Site Kit is Google's official WordPress plugin that connects GA4, Search Console, PageSpeed Insights, and AdSense in one place. No code needed.
- WordPress Admin → Plugins → Add New
- Search for "Site Kit by Google" → Install → Activate
- Click Start Setup → Sign in with Google
- Grant the required permissions
- In Connect Services, select Analytics
- Choose your GA4 Property → click Configure Analytics
- Site Kit automatically adds the tracking code to every page
Site Kit advantage: Automatically handles Consent Mode v2, updates the tracking code when GA4 changes, and shows Analytics data directly in the WordPress dashboard.
Method 2 — Manual Code Installation
Use this if you prefer not to add an extra plugin or need direct control over the tracking code.
Method 2a — via functions.php
Add the following to your Child Theme's functions.php (replace G-XXXXXXXXXX with your Measurement ID):
function add_ga4_tracking() {
if (!is_admin()) { ?>
<!-- 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 }
}
add_action('wp_head', 'add_ga4_tracking', 1);
Method 2b — via Insert Headers and Footers plugin
- Install the Insert Headers and Footers plugin
- Go to Settings → Insert Headers and Footers
- Paste the GA4 script into the Scripts in Header section
- Save — GA4 will now run on every page
Method 3 — Google Tag Manager (GTM)
Use GTM if you need to manage multiple tags (GA4, Facebook Pixel, conversion tracking) from a single interface, without editing WordPress code.
- Create a GTM account at tagmanager.google.com
- Create a Container → Platform: Web
- Copy the Container ID (GTM-XXXXXXX)
- Install the GTM4WP plugin on WordPress and enter the Container ID
- In the GTM Console → New Tag → Google Analytics: GA4 Configuration
- Enter your Measurement ID → Trigger: All Pages → Save
- Click Submit to publish
Verify GA4 Is Working (Realtime & DebugView)
Once installation is done, don't assume data will simply appear. Confirm the tracking code actually fires on every page first. Follow these steps:
- Open GA4 → Reports → Realtime, then open your own site in another tab.
- Wait about 10–30 seconds. If you see "1 user in last 30 minutes" or more, tracking is active.
- Click through 2–3 pages on your site and confirm the
page_viewevent count increases in Realtime. - Install the Google Tag Assistant Chrome extension and load your site — if the GA4 tag shows "Connected," the code is firing correctly.
- Open GA4 DebugView (Admin → DebugView) to inspect individual events in real time — ideal for debugging custom events.
If DebugView shows nothing, install the GA Debugger extension, or temporarily add debug_mode:true to your gtag('config', ...) call to force events into DebugView.
Installed but seeing no data? The most common causes are an incorrect Measurement ID (transposed digits), a tracking code that isn't in the <head> of every page, an ad blocker or privacy extension in your test browser, or a caching plugin serving an old page without the code. Clear your cache and retest in an Incognito window.
PDPA / Consent and GA4 (Cookie Consent)
GA4 uses cookies to identify users and sessions, so if your site has visitors from Thailand or Europe you should request consent before collecting data, to comply with Thailand's PDPA and the EU's GDPR.
The key tool is Google Consent Mode v2, which adjusts how GA4 collects data based on consent state. For example, before a user accepts, GA4 can send only anonymized, cookieless pings instead of setting full cookies.
How to stay compliant with PDPA/GDPR
- Default
analytics_storageandad_storageto "denied" before the user grants consent. - Add a cookie consent banner (a plugin like CookieYes or Complianz, or your own banner) so users can accept or reject.
- When the user accepts, call
gtag('consent', 'update', {...})to switch the state togranted. - Publish a Privacy Policy that clearly states what you collect, why, and that you use GA4.
Example of a "denied by default" Consent Mode setup (place it before gtag.js loads):
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied',
'wait_for_update': 2000
});
</script>
Site Kit advantage: It supports Consent Mode v2 automatically. Just install a compatible cookie-consent plugin and it links the consent state to GA4 — no need to hand-write gtag('consent', ...) yourself.
GDPR/Privacy note: If your site has visitors from the EU, configure Google Consent Mode v2 so GA4 respects cookie consent preferences. Site Kit handles this automatically.
Comparison of All Three Methods
| Method | Ease | Extra Plugin | Best For |
|---|---|---|---|
| Site Kit Plugin | Very Easy | Site Kit | Most users |
| Manual (functions.php) | Moderate | None | Developers |
| Google Tag Manager | Moderate | GTM plugin | Multiple tags |
Frequently Asked Questions About GA4 on WordPress
How is Google Analytics 4 different from Universal Analytics?
GA4 uses event-based tracking instead of Universal Analytics' session-based model, giving deeper behavioral insight, cross-device tracking across web and app, machine-learning analysis, and built-in privacy consent support for PDPA/GDPR. Universal Analytics has already stopped collecting data, so GA4 is now the current standard.
Can I run multiple analytics plugins at once?
Not recommended. If you add GA4 through both Site Kit and a manual gtag.js snippet at the same time, events are double-counted, inflating your pageview and user numbers. Pick one method. If you switch to Site Kit, remove any GA4 code you added another way first.
Do I need a child theme when embedding gtag.js manually?
Always use a child theme when editing functions.php. If you edit the parent theme directly, your tracking code disappears every time the theme updates. A child theme — or a header-insertion plugin like Insert Headers and Footers — keeps the code in place across updates.
Does installing GA4 noticeably slow down my site?
gtag.js loads asynchronously, so it doesn't block page rendering and the speed impact is minimal. For the lightest setup, embedding gtag.js yourself adds no new plugin, while using a plugin trades a small amount of extra script loading for convenience — generally without a meaningful impact on Core Web Vitals.
WordPress Hosting Ready to Use — From 500 THB/year
AsiaGB Hosting supports WordPress with SSD storage, PHP 8.3, DirectAdmin, and Softaculous 1-click install. GA4 tracking works out of the box with any installation method.
View Hosting Plans →