How do I install GA4 on a WordPress site?

Applies to: Google Analytics 4 (GA4)
Last updated: May 2025


Problem

You have a WordPress website and want to install Google Analytics 4 so you can start tracking visitors, user behavior, and conversions.


Solution

There are two main ways to install GA4 on a WordPress site:

  1. Using a plugin (simplest method, no code required)
  2. Manually adding the GA4 tracking code to your theme files

Option 1: Install GA4 Using a WordPress Plugin

This is the preferred method for most users.

Popular plugin options:

  • Site Kit by Google (official plugin)
  • GA Google Analytics
  • MonsterInsights (premium features included)
  • ExactMetrics

Steps using Site Kit:

  1. In your WordPress dashboard, go to Plugins > Add New
  2. Search for Site Kit by Google and click Install Now
  3. Click Activate, then run the Site Kit setup wizard
  4. Connect your Google account and authorize Site Kit
  5. Choose your GA4 property (or create one)
  6. Site Kit will automatically insert the GA4 tag on all pages

Once installed, GA4 data begins showing in Realtime reports and G Hub.


Option 2: Manually Add GA4 Code to Your Theme

Steps:

  1. In your GA4 property, go to Admin > Data Streams > Web
  2. Copy your Measurement ID (e.g., G-XXXXXXXXXX)
  3. Click View tag instructions > Install manually
  4. Copy the provided gtag.js code snippet

Example:

<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>
  1. In WordPress, go to Appearance > Theme File Editor
  2. Open your theme’s header.php file
  3. Paste the code just before the </head> tag
  4. Save the file

This code will now load GA4 on every page of your site.


Testing Your Installation

  • Open https://analytics.google.com
  • Go to Reports > Realtime
  • Visit your WordPress site in a new browser tab
  • Confirm your visit appears in Realtime data

You can also use the Google Tag Assistant Chrome extension to verify your tag is working correctly.


Notes

  • If you change your theme later, you may need to re-add the manual code
  • Plugins are the most reliable method for non-technical users
  • Use only one GA4 installation method to avoid duplicate tracking