How to Get Google Analytics for WordPress

Cody Schneider••8 min read

Adding Google Analytics to your WordPress site is one of the most important first steps for understanding your audience and growing your traffic. Without it, you’re flying blind, guessing what content works and where your visitors are coming from. This guide will walk you through setting up Google Analytics on WordPress using a few different methods, from the absolute easiest way for beginners to more advanced options for power users.

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, Create Your Google Analytics 4 Account

Before you can add any code to your website, you need a Google Analytics account and what's called a "property" for your site. If you already have a GA4 account set up, you can skip to the next section and grab your "Measurement ID". Otherwise, follow these steps:

Google Analytics 4 (or GA4) is the latest version, so all new setups will use this platform.

  1. Visit the Google Analytics homepage and sign in with your Google account.
  2. Once logged in, click "Start measuring."
  3. Account Creation: The first step is to create an account. Think of this as the top-level folder for all your websites or apps. Give it your business name (e.g., "My Awesome Company"). Review the data-sharing settings and click "Next."
  4. Property Creation: Now, you'll create a property. A property represents your website or app.
  5. Create a Data Stream: This is where you tell Google a little more about where the data is coming from.

After you create the stream, you'll see a panel with setup instructions and stream details. What you're looking for is the “Measurement ID”. It will be in the top right and will look like G-XXXXXXXXXX. Copy this ID — this is the key that connects your website to your new GA4 property. Keep it handy for the next steps.

Method 1: Using a Plugin (The Easiest Way)

For most WordPress users, the simplest and safest way to add Google Analytics is by using a plugin. Plugins handle all the technical details behind the scenes, so you don’t have to touch a single line of code. They often add cool features too, like showing you simplified reports right inside your WordPress dashboard.

One of the best and most trusted options is Google’s own Site Kit by Google plugin.

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 Install and Configure Google Site Kit

  1. Install the Plugin: From your WordPress dashboard, navigate to Plugins > Add New. In the search bar, type "Google Site Kit" and press Enter. You should see "Site Kit by Google" as the first result. Click "Install Now," and then "Activate."
  2. Start the Setup Process: Once activated, you'll see a new "Site Kit" menu item in your left-hand sidebar dashboard. Click "Let's set it up" from the banner and then click the button that says "Sign in with Google."
  3. Authenticate with Google: You'll be taken to Google to authorize the plugin. You'll need to grant the plugin several permissions to access your data. This is perfectly safe, as you’re giving a Google plugin access to your Google Analytics account. Follow the prompts until you are returned to your WordPress dashboard.
  4. Connect Analytics: Site Kit will automatically detect that you've already created an Analytics account and property for this site. Simply select the correct GA4 Property (using the G-XXXXXXXXXX Measurement ID) from the dropdown menu and click "Connect Service" or "Configure Analytics."

And that's it! Site Kit will automatically add the required tracking code to every page of your site. You don’t need to do anything else. As a bonus, it can also connect you to Google Search Console to show you what keywords people use to find your site.

Method 2: Manually Adding the Tracking Code (For Advanced Users)

If you're comfortable editing theme files and prefer to avoid plugins, you can add the Google Analytics tracking code directly into your WordPress theme. This method gives you more control but comes with risks. If you make a mistake, you can break your site.

A Very Important Warning: Never edit your parent theme's files directly! Any changes you make will be wiped out the next time the theme is updated. Always use a WordPress child theme for these types of modifications. If you’re not using a child theme, stick with the plugin method.

To start, you’ll need your Google tag (also called the gtag.js snippet). You can find this in your GA4 account under Admin > Data Streams > Click your stream > View tag instructions > Install manually. It will look something like this:

<!-- Google tag (gtag.js) -->
<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>

Once you have this code snippet, there are two common ways to add it.

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

Option A: Adding to header.php

The simplest manual method is adding the script to your theme's header.php file.

  1. In your WordPress dashboard, go to Appearance > Theme File Editor.
  2. From the list of theme files on the right, find and click on header.php.
  3. Paste your full Google Analytics tracking snippet right before the closing </head> tag.
  4. Click "Update File" to save your changes.

Option B: Adding via functions.php (Recommended)

A slightly cleaner approach is to use your child theme’s functions.php file. This professionally hooks your code into WordPress instead of just pasting it into a template file.

  1. Go to Appearance > Theme File Editor.
  2. Open your child theme's functions.php file.
  3. Paste the following code at the end of the file. Be sure to replace G-XXXXXXXXXX with your actual Measurement ID.
function graphed_add_google_analytics() {
    ?>
    <!-- Google tag (gtag.js) -->
    <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>
    <?php
}
add_action('wp_head', 'graphed_add_google_analytics'),

This code defines a PHP function that outputs your tracking script, and then the add_action line tells WordPress to run this function in the header section (wp_head) of every page. This is a best-practice way to add scripts in WordPress.

Method 3: Using Google Tag Manager (The Most Powerful and Flexible)

Google Tag Manager (GTM) is a free tool that acts as a middleman for all your website tracking snippets (or "tags"). Instead of adding several different bits of code to your site for Analytics, Facebook Pixels, or other marketing tools, you add GTM’s code once. Then, you manage all your other tags from the GTM interface.

While this method has the highest learning curve, it's the gold standard for businesses that plan to grow and add more tracking tools in the future. It "future-proofs" your setup and keeps your site's code clean.

  1. Create a GTM Account: Visit the Google Tag Manager website. Sign in and create a new account, giving it your company's name.
  2. Set up a Container: Under your account, you’ll create a "container." Name it after your website URL and select "Web" as the target platform.
  3. Install GTM on WordPress: Once you create the container, GTM will give you two code snippets. One goes in the <head> section of your site, and the other goes just after the opening <body> tag. You can add these snippets manually (again, using a child theme) or by using a plugin like 'GTM4WP' which makes placement super simple.
  4. Create a Google Analytics Tag in GTM:
  5. Publish Your Container: This is a key step! Changes in GTM aren't live until you hit the "Submit" button in the top right corner. Give your version a name (like "Added GA4 Tag") and click "Publish."

Now, your Google Analytics tag is being managed by Google Tag Manager. If you ever need to add another analytics tool, you just add a new tag in GTM — no more theme file editing needed.

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 That Google Analytics is Working

After you’ve implemented one of the methods above, you need to make sure data is actually arriving in your Google Analytics account. Thankfully, this is easy to do.

  1. Open your website in a new browser tab or on your phone.
  2. Go to your Google Analytics account and navigate to Reports > Realtime.
  3. You should see "1" user in the report within a minute or two. You may also see interactive cards showing which page you’re on. If you see activity, congratulations – your tracking is set up correctly!

If you don’t see any data after 5-10 minutes, clear your website’s cache and your browser cache. Ad-blockers can also sometimes prevent data from being sent to GA, so try disabling those as well for the test.

Final Thoughts

Connecting Google Analytics to your WordPress site is non-negotiable for anyone serious about growing their online presence. Whether you choose the user-friendly plugin route, the efficiency of manually adding the code, or the flexibility of Google Tag Manager, you’re now equipped to collect the data you need to make smarter marketing decisions.

Once you are collecting data, the next step is analysis - turning all those charts and numbers into actual business insights. At Graphed, we make this simple. We connect directly to your Google Analytics account and let you build reports, create dashboards, and ask specific questions about your traffic using plain English. It's like having a data analyst on your team, allowing you to ask "Which blog posts brought in the most users from the US?" and get an instant answer, no complex report-building necessary.

Related Articles