how-to guide
How to Add Google Analytics to a WordPress Site
Three ways to get your GA4 Measurement ID onto a WordPress site, and how to pick one without ending up with two.
WordPress has no built-in Analytics field, so the tracking code has to come from somewhere — your theme, a plugin, or Tag Manager. All three work. The mistake worth avoiding is using two of them at once, which counts every visit twice.
Steps
- Get your Measurement ID first. It's in Google Analytics under Admin, Data streams, then your web stream — a code shaped like
G-XXXXXXXXXX. - Check what's already installed before you add anything. Open your live site, view the page source, and search it for
G-orgtag. If a Measurement ID is already there, you're editing that installation rather than starting a new one. - Option one, an SEO plugin you already run. Yoast, Rank Math and All in One SEO all have a field for a Google Analytics or Google tag ID. Paste the Measurement ID there. This is the best choice if one of them is already installed, because there's nothing new to maintain.
- Option two, a dedicated plugin. Site Kit by Google, or a lightweight header-and-footer scripts plugin, will insert the gtag.js snippet for you. Use this if you have no SEO plugin.
- Option three, the theme. If you're comfortable in the editor, paste GA4's gtag.js snippet into the theme's header, immediately before the closing
</head>tag. Use a child theme, not the parent — a parent theme update will wipe the change and your tracking will silently stop. - Whichever you chose, don't also add the tag through Google Tag Manager. Duplicate installations are the usual cause of doubled sessions and impossible bounce rates.
- Load your own site in a browser and check GA4's Realtime report. You should appear within about half a minute.
ask datanephew
Is Analytics installed correctly on my WordPress site?
Ask datanephew to check your site's measurement setup — it can tell you what's actually collecting on the live site rather than what you think you installed.
My numbers doubled after I set this up — what happened?
Almost always two installations firing at once, typically a plugin and a theme snippet. Ask datanephew to check what's on the page, then remove one of them.