The fastest way to add Google Analytics to WordPress is a dedicated plugin like Site Kit by Google, MonsterInsights, or Analytics for WordPress. If you want zero dependencies and full control over where the tracking code loads, paste the GA4 gtag.js snippet directly into your theme's header. Both work. The plugin route is faster to set up and gives you reports inside wp-admin; the manual route is one less plugin to keep updated.
Before you start: get your GA4 measurement ID
Create a GA4 property at analytics.google.com if you don't have one, then add a "Web" data stream for your domain. Google gives you a measurement ID that looks like G-XXXXXXXXXX. You'll need this for either method below.
Method 1: with a plugin
From wp-admin, go to Plugins → Add New and search for one of these:
- Site Kit by Google - official Google plugin, connects your Google account directly, shows Analytics and Search Console data in wp-admin.
- MonsterInsights - popular third-party option, free tier covers basic GA4 setup, paid tiers add ecommerce and form tracking.
Install, activate, then follow the plugin's setup wizard. It walks you through authorizing with your Google account and picking (or creating) the GA4 property. The plugin inserts the tracking snippet into every page automatically, no code editing required.
This is the right choice if you want in-dashboard reports, don't want to touch theme files, or you're not comfortable editing PHP. It's also the safer option if you update themes often, since manual snippet edits get wiped out on a theme update unless you're using a child theme.
Method 2: manual snippet, no plugin
Copy the gtag.js snippet from your GA4 property (Admin → Data Streams → your stream → View tag instructions → Install manually). It looks like this:
<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>
Then add it to your theme's <head> section, right before the closing </head> tag. Two ways to do that:
- wp-admin → Appearance → Theme File Editor, open
header.php, paste the snippet before</head>. Works, but if you're not on a child theme, a theme update overwrites this and you lose tracking silently. - A child theme's
functions.php, hooked intowp_headinstead of editing the template file directly. This survives parent theme updates. Add this tofunctions.php:
function flashcloud_add_ga4() {
?>
<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', 'flashcloud_add_ga4');
Use the portal's File Manager tile (Services → your hosting → File Manager) or an FTP client to reach these theme files if you'd rather not use the in-admin theme editor.
Verify it's actually tracking
Load your site in an incognito window, then check GA4's Reports → Realtime view. You should see yourself as an active user within a minute or two. If nothing shows up:
- View page source and confirm the
gtag.jsscript tag is actually present in the HTML. If it's missing, the snippet didn't save, or a cache is serving an old version of the page. - Check for a caching plugin or server-level page cache holding a stale copy. Purge it and reload.
- Confirm you used the measurement ID from the right GA4 property. If you manage multiple sites, double-check which ID you copied.
- Ad blockers and privacy extensions block
gtag.jsin the browser you're testing with. Try a different browser or disable the extension for the test.
A note on performance and duplicate tracking
Only run one tracking method at a time. If you install a plugin and later add the manual snippet (or vice versa), you'll double-count every pageview and your bounce rate and session numbers will be wrong. Check your theme's header and your active plugins before troubleshooting numbers that look off.
The gtag.js snippet is small and loads async, so it won't meaningfully affect page speed either way. If you're chasing every millisecond, the plugin route adds a small amount of admin-side overhead (settings pages, wp-admin queries) that the manual snippet doesn't, but it has no effect on your actual page load time for visitors.