How to Input Google Analytics into WordPress

Cody Schneider••6 min read

Your WordPress site is live, but do you know who's visiting, where they're coming from, or what content they love? That's where Google Analytics comes in. Connecting it to WordPress is the single most important step you can take to understand your audience and grow your traffic. This guide will walk you through several ways to add Google Analytics 4 to WordPress, from plugins that do the work for you to the manual method for more control.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

First, Why Connect WordPress to Google Analytics at All?

Before jumping into the "how," let’s quickly cover the "why." Once connected, Google Analytics becomes the control panel for your website’s performance, answering questions like:

  • Who is my audience? See anonymized demographic data like your visitors’ age, gender, location, and interests. This helps you create content that truly resonates with them.
  • How do people find my website? The Acquisition report shows you exactly where your traffic is coming from - whether it’s organic search (Google), social media (Facebook, Pinterest), referral traffic from other sites, or paid ads.
  • What is my most popular content? By tracking which pages and posts get the most views and engagement, you know what your audience actually wants to see, leading to smarter strategies.
  • Are visitors engaging? Metrics like engaged sessions and average engagement time tell you if readers are actually interacting with your content and sticking around. This is a key component of SEO.
  • Am I hitting my goals? Whether you track ebook downloads, form submissions, or purchases, Google Analytics Events let you measure what matters most to your business.

Without this data, you're essentially flying blind, making educated guesses instead of data-driven decisions.

First Things First: Get Your GA4 Measurement ID

Before you can connect Google Analytics and WordPress, you need to set up Google Analytics 4 and find your Measurement ID. Here’s how to do that:

  • Sign into Google Analytics.
  • If you have multiple accounts, select the relevant one.
  • In the lower-left corner, click on Admin (the gear icon).
  • In the Property column, click on Data Streams.
  • Select the data stream relevant to your website to access a window with your Measurement ID (starts with G-).

Keep this page open and have the ID ready for a later step.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Method 1: Add GA4 Using a Plugin

For most WordPress users, a plugin is the most straightforward method for adding Google Analytics. Plugins eliminate the need to add code manually, prevent errors, and offer additional features, including basic analytics reports right on your WordPress dashboard. Two popular options include Google Site Kit and MonsterInsights. This method is suitable for those who want a hands-off approach.

Install and Activate a Plugin

  • In your WordPress admin, go to Plugins and select Add New.
  • Search for and install the Google Site Kit or MonsterInsights plugin. a. Activate the plugin upon installation. b. Configure the plugin to connect to your Google account. c. You will be asked to connect to your Google Analytics account. This is where you enter the Measurement ID.
  • Select the correct property. Once connected, select the correct Google Analytics property from the dropdown menu (there may be only one). This connects the Measurement ID to your site.

That’s it. Many plugins will do this for you automatically and add the Google Analytics tracking code to your website. You can always check your WordPress dashboard for key metrics and reports.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Method 2: Use Custom Code to Inject the Script

If you'd rather have a fully customizable solution and you're comfortable with code, you can inject the script directly into your headers using the Insert Headers and Footers plugin. This method is ideal for users who are comfortable with code but need a reliable way to manage scripts.

// Install the Insert Headers and Footers plugin: //
// In your WordPress dashboard, go to <strong>Plugins</strong> -> <strong>Add New</strong> and search for <em>Insert Headers and Footers</em>. Install and activate it. //

 // Insert the GA Code: //
 Navigate to <strong>Settings</strong> -> <strong>Insert Headers and Footers</strong>, and paste your Google Analytics tracking code in the <strong>Scripts in Header</strong> field. For 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>
 // Save Changes

Method 3: Manually Add the Code to Your Theme File

This method gives the most control and is linear with light technical weight, as the code is added directly into your theme files.

WARNING: This method is not recommended for beginners. Editing theme files directly can break your site if you make a mistake.

  • Access the Theme File: In your WordPress dashboard, go to Appearance -> Theme Editor. You may need to confirm you understand the risks involved.
  • Locate the header.php file: Find the file labeled header.php in the right-hand panel. Click to open. a. Paste the GA tracking code inside the <head></head> tags to ensure it runs on every page of your site.
  • Update the File: Click the update file button to save the changes.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

How to Verify Your GA4 Installation

Don’t just assume it works! Take a minute to verify that GA4 produces accurate readings on your site. Here are a few ways to check:

Method 1: Google Analytics Real-Time Report

  • Open Google Analytics and navigate to the Real-Time section on the left. You should see a live view of active users.
  • Open your website in a different browser and load a few pages.
  • Go back to Google Analytics and see if your activity appears in the Real-Time report. If it does, your installation is working.

Method 2: Using the Browser Developer Console

  • Open your website in Google Chrome.
  • Right-click anywhere on the page and select Inspect.
  • Navigate to the Network tab and refresh the page.
  • In the resulting data, look for requests to www.google-analytics.com and verify that they are loading without errors. If you find that, your tracking is correctly installed.

Final Thoughts

Connecting Google Analytics to WordPress isn't just a nice-to-have - it's crucial to turning your website from a hobby into a success. We’ve covered multiple methods, from easy plugins to directly editing theme files, ensuring that you can choose the best approach that fits your technical comfort and needs. By taking advantage of analytics, you are empowered to make informed decisions that can enhance your advertising, content strategies, and sales platforms.

For more insights on how to optimize your tracking and usage, try Graphed to generate actionable reports and dashboards easily from one point.

Related Articles