How To Add Google Analytics To WordPress

You can add Google Analytics to WordPress in three reliable ways: using the official Site Kit plugin, pasting the Google tag directly into your theme, or deploying via Google Tag Manager. The method you choose depends on who manages your site and whether you need to connect other Google tools like Ads or Search Console.

All three methods place the Google tag (gtag.js) on your pages, but they differ in ease of setup, flexibility, and the technical skill required. Before you start, make sure you have a Google account and a GA4 property set up. This guide walks through each option with exact steps, so you can pick the one that fits your workflow.

Three Ways To Add GA4 To WordPress

There is no single "right" way to add Google Analytics to WordPress. The three methods covered here all result in a working GA4 implementation, but they differ in how much control you have and how much technical work is needed.

Site Kit by Google is the official Google Analytics WordPress plugin. It handles the entire connection for you: it places the Google tag, verifies site ownership, and pulls data into a WordPress dashboard. No code editing is required, and you can connect Search Console, AdSense, and Tag Manager from the same interface. This is the fastest path for most site owners.

Pasting the Google tag into your theme gives you direct control. You copy the gtag.js snippet from your GA4 property and insert it into your theme's header file. This method is lightweight but fragile: changing themes or updating files can remove the tag. It also requires you to manage any additional tracking code manually.

Google Tag Manager acts as a central hub for all your tags. You install the GTM container once (either manually or via Site Kit), then add and update tags through the GTM web interface. This is the most flexible option, especially if you run ads, use third-party pixels, or need custom event tracking. The table below summarizes the differences.

MethodEase of setupFlexibilityCoding requiredBest for
Site Kit by GoogleHigh, guided setup wizardModerate, connects multiple Google servicesNoneMost WordPress site owners
Pasting the Google tagMedium, requires copying and pasting codeLow, only adds the tag, manual updates neededHTML and JavaScriptDevelopers who want direct control
Google Tag ManagerMedium, initial container installation, then tag setupHigh, manage many tags, third-party pixels, custom triggersNone after container is placed (via Site Kit or manual)Marketers and developers needing advanced tracking

All three ultimately fire the Google tag on your site. You can even combine them: use Site Kit to install the Tag Manager container, then manage all other tags inside GTM. The official Google recommendation is to use Tag Manager for flexibility, but Site Kit simplifies the initial connection for WordPress users.

Site Kit By Google

Site Kit is the official Google Analytics WordPress plugin from Google. It places the Google tag on your site and gives you a dashboard with key metrics from Analytics, Search Console, and other services. Here is how to set it up for a GA4 property that starts with "G-".

Requirements

  • WordPress 5.2 or higher
  • PHP 7.4 or higher
  • A publicly accessible site (not in maintenance mode or password protected)
  • REST API available (check under Tools > Site Health)

Installation steps

  1. Log in to your WordPress admin. Make sure your site is live and publicly accessible.
  2. Go to Plugins > Add New.
  3. Search for "Site Kit by Google".
  4. Click Install Now on the Site Kit by Google plugin.
  5. After installation, go to Plugins > Installed Plugins and click Activate under Site Kit by Google.
  6. Once activated, click Start setup or go to the new Site Kit menu in the left menu.
  7. Check the box "Connect Google Analytics as part of your setup" and click Sign in with Google.
  8. Select the Google Account that has access to your GA4 property. Grant the requested permissions.
  9. Follow the prompts to verify site ownership and add your site to Search Console (if not already added).
  10. Click Set up Google Analytics. Choose your existing GA4 property from the dropdown and click Complete Setup.

After setup, the main Site Kit dashboard displays key metrics from Search Console and Analytics. It may show a "gathering data" notice for a few days if your account or site is new. You can connect additional services like AdSense or Tag Manager under Site Kit > Settings > Connect More Services.

Click path: Site Kit then DashboardSite KitDashboard
Site Kit dashboard showing Analytics and Search Console data inside WordPress.

Each WordPress admin must connect their own Google account to access the plugin. If you use a staging environment, Site Kit can display production data; see the Site Kit documentation for staging setup.

Short on time? Analytics Art can check this in your property for you.

Pasting The Tag Into Your Theme

If you prefer not to use a plugin, you can add the Google tag directly to your WordPress theme. This method uses the gtag.js library, which is a JavaScript framework for sending data to Google Analytics. You will need your GA4 measurement ID (the "G-" ID) and the full gtag.js snippet.

First, find your measurement ID and snippet. In Google Analytics, go to Admin > Data collection and modification > Data streams > your web stream > View tag instructions. Copy the snippet that starts with <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX"></script>. (See our guide on finding your GA4 measurement ID for detailed steps.)

Next, you need to place this snippet in the <head> section of every page. In WordPress, you can do this by editing your active theme's header.php file. Go to Appearance > Theme File Editor, select your theme, open header.php, and paste the snippet just before the closing </head> tag. Save the file. If you cannot access the theme editor, you can upload the modified file via FTP. The Google Analytics help article also suggests using the WordPress Editor for this purpose if you are unable to install plugins.

The gtag.js library sets first-party cookies to distinguish users and sessions. By default, it creates a _ga cookie with a 2-year expiration and a _ga_<container-id> cookie to persist session state. You can customize these settings, but that requires JavaScript knowledge. For more on how the Google tag works, read our explanation of the Google tag.

Keep in mind that if you switch themes, you must re-add the snippet. Also, make sure you do not have another plugin or method inserting the same Google tag, as duplicate tags will inflate your metrics. Use Google Tag Assistant to verify your setup.

Using Tag Manager

Google Tag Manager (GTM) is a tag management system that lets you deploy and update tags without editing your site's code each time. You can use GTM to fire the GA4 tag, along with other tags like Google Ads conversion tracking or third-party pixels.

Option A: Install GTM via Site Kit

If you already use Site Kit, you can set up Tag Manager without touching any code. Go to Site Kit > Settings > Connect More Services, find Tag Manager, and click Set up Tag Manager. Site Kit will place the GTM container code on your site automatically.

Option B: Install GTM manually

  1. Create a Google Tag Manager account and container at tagmanager.google.com.
  2. Copy the two container code snippets (one for <head>, one for <body>).
  3. Paste the first snippet high in the <head> and the second right after the opening <body> tag. In a classic theme both usually sit in header.php.

Create a GA4 tag in GTM

Once the container is installed, log in to GTM and create a new tag:

  1. Click Tags > New.
  2. Choose Google Tag as the tag type.
  3. Enter your GA4 measurement ID (G-) as the tag ID.
  4. Set the trigger to All Pages.
  5. Save and publish the container.

GTM offers advantages over direct gtag.js: you can manage multiple tags, use version control, collaborate with workspaces, and even set up server-side tagging. The Google Developers documentation notes that Tag Manager supports Google tags, third-party tags, and custom tags, while gtag.js is limited to Google products. After publishing, use the Preview mode in GTM to verify the tag fires, then check the Realtime report in GA4 to confirm data is received. For a full walkthrough, see how to set up GA4 with Google Tag Manager.

Plugin Choices And What To Avoid

Site Kit is Google's official WordPress plugin. It is free and open source, and Google says it will remain so. It anonymizes IP addresses by default when the Analytics module is activated (you can turn this off under Site Kit > Settings > Analytics), and consent mode is among its listed features.

Some users have reported that Site Kit's code can interfere with certain themes, causing layout issues. One review on the WordPress plugin directory notes that "the code in this plugin often messes with layouts that only disabling it will fix." If you experience such problems, the Site Kit documentation provides a guide on troubleshooting theme and plugin conflicts. You can also manage the code Site Kit places by going to Site Kit > Settings and reviewing connected services.

A common mistake is installing multiple plugins that all insert the Google tag. This causes duplicate pageviews and unreliable data. Always verify that only one tag fires per page. Use Google Tag Assistant or the GA4 DebugView to check. If you need to add AdSense or other Google services, Site Kit can handle them all from one interface, reducing the risk of conflicts.

Other plugins exist in the WordPress repository, but they are not officially supported by Google. When evaluating any plugin, look for recent updates, compatibility with your WordPress version, and positive reviews. For advanced setups, combining Site Kit (for basic tag placement) with Google Tag Manager (for custom event tracking) is a flexible approach. Site Kit also lists enhanced measurement among its features; see its documentation for where to switch it on. Read about Google Consent Mode v2 to understand how to manage consent for analytics and ads.

Frequently Asked Questions

How Do I Install Google Analytics On WordPress?

Install the official Site Kit by Google plugin from the WordPress plugin directory. After activation, connect your Google account and select your GA4 property during the setup wizard. The plugin adds the tracking code automatically and displays key metrics on your WordPress dashboard.

Is GA4 Free Or Paid?

The standard version of Google Analytics 4 is free. Google also offers a paid enterprise version called Google Analytics 360. The Site Kit plugin itself is free and open source, though individual Google services connected through it may have their own fees.

Where Do I Add My Google AdSense Code In WordPress?

With Site Kit, go to Site Kit > Settings > Connect More Services and set up AdSense. Site Kit inserts the AdSense code on your site. You can check your account approval status under Settings > Connected Services > AdSense and click Check your site status.

Does WordPress Have Built-In Analytics?

WordPress does not include a built-in analytics feature. To see visitor data, you need to add a tracking solution like Google Analytics. This can be done via a plugin (such as the official Site Kit plugin) or by manually inserting the tracking code into your theme files.

What Is The Official Google Plugin For WordPress?

The official Google plugin for WordPress is Site Kit by Google. It integrates Google Analytics, Search Console, AdSense, PageSpeed Insights, Tag Manager, and other Google services directly into your WordPress admin area, all from one dashboard. It is free and open source.

What Is Replacing Google Analytics?

Google Analytics 4 (GA4) has replaced Universal Analytics (UA). UA standard properties stopped processing data in July 2023. All new Google Analytics setups now use GA4, and the official Site Kit plugin connects to GA4 properties.