How to Connect Google Analytics 4 to WordPress

Cody Schneider9 min read

Connecting Google Analytics 4 to your WordPress site is one of the most important steps after launching. This connection unlocks a world of data about who your visitors are, how they find your site, and what content they love most. We'll walk through exactly how to set it up, covering the easiest plugin methods and the more direct manual options.

Why Connect Google Analytics to WordPress?

Before jumping into the "how," it's worth a quick reminder of the "why." Linking GA4 to your WordPress site isn't just about tracking pageviews. It’s about gaining actionable insights that can directly influence your content strategy, user experience, and overall business goals.

Once connected, you can answer questions like:

  • Where does my traffic come from? (Organic search, social media, paid ads, referrals)
  • Which blog posts or pages are most popular? (Tells you what content resonates with your audience)
  • How do users behave on my site? (Understand the path visitors take from entry to exit)
  • What are my key conversion events? (Track form submissions, button clicks, email sign-ups)
  • Who is my audience? (Demographics like age, location, and interests)

Without this data, you're essentially flying blind. By connecting GA4, you empower yourself to make data-driven decisions that will grow your website effectively.

Before You Begin: Get Your GA4 Measurement ID

To connect your site to Google Analytics, you need a unique identifier. In Google Analytics 4, this is called the "Measurement ID." It acts as the address that your website's data gets sent to. It always starts with "G-" followed by a series of numbers and letters (e.g., G-ABC123XYZ4). If you already have your Measurement ID, you can skip to the next section.

If you don’t have one yet, here's how to create a new Google Analytics 4 property and find your ID.

Step 1: Create a Google Analytics Account & Property

  1. Navigate to the Google Analytics website and sign in with your Google account.
  2. If this is your first time, you'll be prompted to start an account. If you have an existing account, click on Admin (the gear icon in the bottom-left corner).
  3. In the Account column, click Create Account. Give your account a name (e.g., your business name).
  4. Click Next to move to Property Setup. Give your property a name (e.g., your website name). Select your reporting time zone and currency.
  5. Click Next. Fill out the optional business information and click Create. Accept the terms of service.

You have now created a GA4 property.

Step 2: Set Up Your Data Stream

  1. After creating the property, you'll be prompted to "Choose a platform." Select Web.
  2. Enter your website’s URL (e.g., yourwebsite.com) and give the stream a name (e.g., "Main Website Stream").
  3. Click Create Stream.

Step 3: Find and Copy Your Measurement ID

Once you create the stream, a "Web stream details" window will appear. Your Measurement ID will be displayed prominently in the top right corner. Click the copy icon next to it to save it to your clipboard. You'll need this for all of the connection methods below.

If you need to find this later, simply navigate to Admin > Data Streams and click on your web stream to see this page again.

Method 1: Using a Plugin (Recommended for Beginners)

For most WordPress users, a plugin is the simplest, safest, and fastest way to install Google Analytics. You don't have to touch a single line of code, and many plugins offer extra features, like showing you a simplified analytics dashboard right inside WordPress.

Site Kit by Google is an excellent choice because it's Google's own official plugin and it's completely free. It connects your site to multiple Google services, including Analytics, Search Console, and AdSense.

Step-by-Step Guide for Site Kit:

  1. Log into your WordPress dashboard.
  2. Navigate to Plugins > Add New.
  3. In the search bar, type "Site Kit by Google" and press Enter.
  4. Find the plugin card and click Install Now, then click Activate.
  5. You'll now see a prompt to begin the setup. Click Start Setup.
  6. Follow the step-by-step authentication process. You will be asked to sign in with your Google account - make sure it's the same one you used to set up Google Analytics.
  7. You'll need to grant Site Kit permission to access your Google account data. It will then automatically detect your Google Analytics and Search Console accounts.
  8. Confirm the settings and your GA4 property, and click Configure.

That's it! Site Kit handles adding the tracking code to your site's header automatically. Within a few hours, you'll be able to see basic traffic stats directly in your WordPress dashboard under the "Site Kit" menu.

Method 2: Manually Adding Code via functions.php (Intermediate)

If you prefer to avoid plugins to keep your site lean, you can add the GA4 tracking code directly to your theme files. This method involves adding a small PHP snippet to your theme's functions.php file. It's the cleanest manual method because it won't be erased when you update your theme, provided you are using a child theme.

Heads Up: Messing with theme files can break your site if you make a mistake. It is strongly recommended to use a child theme for this and to always back up your site before making any changes.

Step 1: Get the Full GA4 Tracking Snippet (gtag.js)

  1. Go to your GA4 property.
  2. Navigate to Admin > Data Streams and click your web stream.
  3. Scroll down and click on View tag instructions under the "Google tag" section.
  4. Select the Install manually tab.
  5. You will see a block of JavaScript code starting with <!-- Google tag (gtag.js) -->. Copy the entire code block.

Step 2: Add the Code to functions.php

  1. In your WordPress dashboard, go to Appearance > Theme File Editor.
  2. From the file list on the right, select Theme Functions (functions.php).
  3. Scroll to the very bottom of the file and paste the following PHP code. Remember to replace YOUR_GA4_TAG_HERE with the full gtag.js snippet you copied. Be careful not to alter the single quotes in the PHP code.
function add_google_analytics_tag() {
    ?>
    
    <!-- Paste your Entire Google Tag Snippet Here -->
    <!-- For example: -->
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-ABC123XYZ4"></script>
    <script>
      window.dataLayer = window.dataLayer || [],
      function gtag(){dataLayer.push(arguments),},
      gtag('js', new Date()),
      gtag('config', 'G-ABC123XYZ4'),
    </script>
    
    <?php
}
add_action('wp_head', 'add_google_analytics_tag'),
  1. Click Update File to save your changes.

This code creates a function that outputs the GA4 tracking script and then "hooks" it into the wp_head action, which properly places it in the <head> section of every page on your site.

Method 3: Manually Adding Code via header.php (Not Recommended, But Possible)

Another manual option is to paste the tracking snippet directly into your theme's header.php file. This is a common method you'll see in older tutorials, but it comes with a major downside: If you update your theme, this file will be overwritten, and your analytics code will disappear. You can only prevent this by using a child theme.

Because the functions.php method avoids this problem more elegantly, it’s generally preferred. But if you must use this approach:

  1. Follow Step 1 above to get your full gtag.js snippet.
  2. In your WordPress dashboard, go to Appearance > Theme File Editor.
  3. From the file list on the right, select Theme Header (header.php).
  4. Find the closing </head> tag.
  5. Paste the entire gtag.js code snippet on a new line just before the </head> tag.
  6. Click Update File.

How to Verify That Google Analytics Is Working

After installing your tracking code, you should confirm it's working correctly. Don’t just assume it is! Here are a couple of ways to check.

1. Use GA4 Realtime Reports

This is the easiest way. It shows activity on your site as it happens.

  1. Log in to your Google Analytics account.
  2. In the left-hand navigation, go to Reports > Realtime.
  3. Open your WordPress website in a completely different browser window (or use an incognito window).
  4. Within a minute or two, you should see at least "1" appear in the "Users" card on the Realtime report. You may also see your location pop up on the map. If you see activity, it's working!

2. Check Your Browser's Developer Tools

For a more technical confirmation, you can check if your browser is successfully sending data to Google.

  1. Open your website in a new tab.
  2. Right-click anywhere on the page and select Inspect.
  3. Click on the Network tab in the developer tools panel.
  4. In the filter box, type "collect".
  5. Refresh your webpage.
  6. You should see one or more rows appear with a name that includes "google-analytics.com/g/collect...". If the status is 200 or 204, it means the tracking data was successfully sent.

Troubleshooting Common Issues

If you don't see any data in your Realtime report, here are a few things to check:

  • Caching Issues: If you use a caching plugin (like WP Rocket or W3 Total Cache), clear your website's cache. Then, clear your browser's cache as well. Caching can sometimes serve an old version of your site without the tracking code.
  • Plugin Conflicts: Some plugins, especially cookie consent or advanced ad blockers, can block the GA script from firing. Try temporarily deactivating other plugins to see if that resolves the issue.
  • Incorrect Tag or ID: Double-check that you copied the complete tag snippet or the correct Measurement ID without any typos. A single mistake will cause it to fail.
  • Ad Blockers: Make sure your own browser's ad blocker is turned off while testing, as many block analytics scripts by default.

Final Thoughts

Connecting your website's data to a powerful analysis tool is the foundation of a smart growth strategy. By following one of the methods above, you can quickly integrate your WordPress site with Google Analytics 4 and start turning raw visitor data into meaningful insights about your content and audience.

Of course, once your data sources are connected, the real work begins: analyzing the information. At that stage, trying to build custom dashboards or get quick answers inside Google Analytics can still feel like a chore. That's why we created Graphed. After connecting Google Analytics, you can use our platform to build dashboards or get immediate insights just by asking questions in plain English - no complicated report builders or steep learning curves needed.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.