How to Get Google Analytics for WordPress
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.
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.
- Visit the Google Analytics homepage and sign in with your Google account.
- Once logged in, click "Start measuring."
- 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."
- Property Creation: Now, you'll create a property. A property represents your website or app.
- 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.
How to Install and Configure Google Site Kit
- 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."
- 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."
- 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.
- 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.
Option A: Adding to header.php
The simplest manual method is adding the script to your theme's header.php file.
- In your WordPress dashboard, go to Appearance > Theme File Editor.
- From the list of theme files on the right, find and click on
header.php. - Paste your full Google Analytics tracking snippet right before the closing
</head>tag. - 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.
- Go to Appearance > Theme File Editor.
- Open your child theme's
functions.phpfile. - Paste the following code at the end of the file. Be sure to replace
G-XXXXXXXXXXwith 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.
- Create a GTM Account: Visit the Google Tag Manager website. Sign in and create a new account, giving it your company's name.
- 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.
- 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. - Create a Google Analytics Tag in GTM:
- 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.
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.
- Open your website in a new browser tab or on your phone.
- Go to your Google Analytics account and navigate to Reports > Realtime.
- 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
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.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?