How to Install Google Analytics on WordPress: Plugins vs Manual Setup
Published:
Last Updated:
Category: Web Analytics
Authors: Shusaku Yosa
Published:
Last Updated:
Category: Web Analytics
Authors: Shusaku Yosa

There are several ways to install Google Analytics (GA4) on a WordPress site, and the one you pick has a lasting effect on how manageable things are later. A plugin gets you there in minutes, but that convenience comes at a cost.
This article compares the four installation methods available in a WordPress environment and sets out how to choose between them. It also covers the typical problems that throw measurement off for reasons specific to WordPress, and how to avoid them. Creating a GA4 account and the fundamentals of Google Tag Manager are outside its scope.
The ways to install GA4 on WordPress fall into four broad categories.
The choice comes down to how far you intend to extend measurement. If pageviews are all you need, a plugin is fine. If you plan to move into event tracking for conversions or clicks, use GTM.
Work through these conditions.
When in doubt, choose GTM. Migrating from a plugin to GTM later is possible, but it is a common source of double-counting errors, and the effort involved usually exceeds what it would have cost to start with GTM.
Site Kit by Google is the official WordPress plugin from Google. Alongside GA4, it brings Search Console, PageSpeed Insights, and AdSense into the WordPress admin interface.
Being the official plugin makes it dependable, and having Search Console queries alongside GA4 metrics on one screen is genuinely useful. Since no theme files are edited, there is no risk of the tag disappearing on a theme update.
The reports shown in the admin interface, however, stay at a summary level. Any deeper analysis means opening GA4 itself, so it is best not to expect too much from what you can see inside WordPress.
Site Kit has a setting to insert the Google Analytics code, and it is enabled by default. If a GA4 tag is also firing through GTM, the same pageview is sent twice and your numbers roughly double.
Site Kit does display a warning that an existing tag was found on the page, but this warning is frequently missed, and the double counting goes unnoticed.
If you are using GTM alongside it, disable Site Kit's code insertion as follows.
After changing the setting, open the GA4 realtime report and confirm your own visit is counted once. Checking how many times gtag.js loads in your browser's developer tools is another effective method.
Dedicated plugins such as MonsterInsights and ExactMetrics install GA4 and additionally surface detailed reports inside the WordPress admin. Some offer extras such as e-commerce purchase data or form submission tracking.
The in-admin reporting is richer than Site Kit's, but the main features are typically reserved for paid tiers. Check what the free version actually covers before committing.
The same caution about duplication with GTM or theme-level tags applies here. Installing several plugins that each output a GA4 tag, resulting in triple counting, does happen in practice.
If you would rather not add another plugin, you can output the tag from the theme. This approach carries clear risks.
Many themes provide a dedicated field for a measurement ID or header tag. Entering the GA4 measurement ID, which begins with G-, in the theme settings completes the installation.
Older themes may still have a field for the legacy Universal Analytics tracking ID beginning with UA-, but the GA4 measurement ID alone is sufficient now. If the theme only offers a UA field, it most likely does not support GA4, so choose a different method.
If you are editing theme files, always do it in a child theme. Editing the parent theme directly means your changes are overwritten when the theme updates, and the tag disappears. Going weeks without noticing that measurement has stopped is a common outcome.
The tag also disappears the moment you switch themes. This is why GA4 installation is so often forgotten during a site redesign, leaving a gap in the data.
For these reasons, installing directly in the theme is not recommended unless you have a specific constraint that rules out adding any plugins.
Using GTM takes more effort upfront but is the most manageable option over the medium to long term.
You install the GTM container snippet on WordPress and create the GA4 configuration tag within GTM. The snippet itself can be placed through Site Kit, a theme settings field, or a dedicated plugin, whichever you prefer.
If you plan to run advertising or track conversions on a WordPress site, building on GTM from the start makes subsequent work considerably easier.
Even when the installation itself is correct, measurement can still go wrong in a WordPress environment for the following reasons.
If you use a caching plugin such as WP Super Cache or W3 Total Cache, cached HTML from before the change may continue to be served immediately after installing the tag, so measurement never starts.
Always clear the cache after installing the tag. If measurement still does not begin, check whether JavaScript minification or concatenation is enabled in the caching plugin's settings. Where these features interfere with the tag, you will need to exclude it from their scope.
When your own visits are included in measurement, the numbers skew badly, particularly in the early period when traffic is low. The standard remedy is to define internal traffic in GA4 and exclude it.
In the GA4 admin, go to Data Streams, select the relevant stream, open the tag settings, and then Define internal traffic, where you register the IP addresses to exclude.
Note that this assumes a static IP. It will not work on home or mobile connections with dynamic addressing, in which case you will need to look at exclusion via a GTM custom variable or a cookie.
Depending on the installation method, the WordPress admin and post preview screens can end up within the measurement scope. Since these are not real user behaviour, your own editing work accumulates as pageviews.
Most plugins have an option to exclude administrator visits from measurement, so check for it after installing. If you are writing the tag into the theme directly, you will need conditional logic to exclude the admin screens.
Once installation is complete, check these three things.
The third point is the one most often missed. Depending on how the theme is structured, the tag may not be output on certain templates, leaving some pages outside the measurement scope.
For installing GA4 on WordPress, what matters is less the method itself than choosing with your future measurement scope in mind. If traffic numbers are the goal, a plugin is sufficient, but if conversion tracking or advertising is on the roadmap, it is worth accepting the upfront effort and building on GTM.
Installing directly in the theme risks losing the tag on updates or theme changes, and should be avoided without a specific reason.
Whichever method you choose, verify three things without exception: double counting, the effect of caching, and internal traffic exclusion. Skip these checks and start collecting, and the accumulated data itself becomes unreliable, with no way to correct it retrospectively.

A breakdown of GA4's free tier limits based on official documentation: sampling, BigQuery export caps, 14-month data ret...

A clear explanation of time on page and how it relates to GA4's average engagement time. Covers how to think about avera...
A clear explanation of what a tracking code is, where to place gtag.js and GTM snippets (inside the head element, as hig...