How to Activate Google Analytics on WordPress
Connecting Google Analytics to your WordPress site is one of the most important first steps you can take to understand your audience and grow your traffic. This article walks you through creating a Google Analytics account and guides you through three different methods for installing the tracking code on your WordPress website.
First Things First: Create Your Google Analytics 4 Property
Before you can add Google Analytics to WordPress, you need an account and a tracking code. If you already have a Google Analytics 4 property set up, you can skip this section and go find your "Measurement ID" or Global Site Tag. If you’re starting from scratch, follow these steps.
- Create an Account: Go to the Google Analytics homepage and click “Start measuring.” If you're logged into a Google account, you'll be taken to the account creation screen.
- Account Setup: Give your account a name. This is the top-most level of organization, useful if you manage multiple businesses. Your company name is a good choice here.
- Property Setup: Now, create a "Property." This will be your website. Give it a descriptive name (like your site name), select your reporting time zone, and choose your currency.
- Business Details: Provide some basic information about your industry and business size. Under "Business objectives," select the goals most relevant to you, such as "Generate leads" or "Drive online sales."
- Choose a Platform: You will be asked to set up a "data stream," which is just an industry term for a source of data. Since you're tracking a website, click on “Web.”
- Set up Web Stream: Enter your website’s URL (e.g., www.yoursite.com) and give the stream a name (again, your site name is fine). Click “Create stream.”
- Find Your Tracking Info: This is the key step! Google will now show you a screen with all your web stream details. At the top right, you'll see your Measurement ID, which looks like
G-XXXXXXXXXX. Further down, under "Installation instructions," you'll find the Global Site Tag (gtag.js). This is a snippet of JavaScript code. Keep this page open, you'll need one of these two things for the next steps.
With your GA4 property created and your tracking information handy, you're ready to connect it to your WordPress site.
3 Ways to Add Google Analytics to WordPress
There isn't just one "right" way to add Google Analytics to your site. The best method for you depends on your technical comfort level and what WordPress theme you’re using. We’ll cover three popular methods, starting with the easiest.
Method 1: The Easiest Way: Using a WordPress Plugin
For most users, especially those not comfortable with code, a plugin is the simplest and safest way to go. Google’s official plugin, Site Kit, is an excellent free option that not only installs Analytics but also connects your site to other essential Google services like Search Console and PageSpeed Insights.
Here’s how to set it up:
- Navigate to Plugins: From your WordPress dashboard, hover over “Plugins” in the left-hand menu and click “Add New.”
- Search for Site Kit: In the search bar on the top right, type “Site Kit by Google.”
- Install and Activate: Find the correct plugin in the search results, click "Install Now," and then click "Activate."
- Start the Setup Wizard: After activation, you’ll see a banner at the top of your screen prompting you to start the setup. Click the button to begin.
- Connect Your Google Account: Site Kit will then walk you through a multi-step process to connect your Google account. You’ll be asked to sign in and grant permissions for Site Kit to access your data. This is what allows it to automatically find your Analytics and Search Console properties.
- Finish the Wizard: Follow the on-screen prompts. Site Kit will verify you own the site, connect Search Console, and then ask to connect to Analytics. Since you already created your GA4 property, Site Kit will find it and configure it for you automatically. That’s it! The plugin handles adding the tracking code to every page of your site without you ever touching a line of code.
Method 2: Using Your Theme's Header/Footer Script Settings
Many modern WordPress themes come with a built-in feature to add tracking scripts like Google Analytics. This method is great because it doesn't require an extra plugin and is still quite simple.
Because every theme is different, the exact location of this setting varies. However, the general process is usually the same.
- Locate Your Theme Options: Look around your WordPress dashboard for "Theme Options," "Theme Settings," or navigate to “Appearance” -> “Customize.”
- Find the Scripts Section: Hunt for a section labeled “Scripts,” “Header/Footer Code,” “Integrations,” or perhaps even “Google Analytics.”
- Get the Global Site Tag: Go back to your Google Analytics “Web Stream” page. This time, instead of the Measurement ID, find the section for the Global Site Tag (gtag.js) and click "View tag instructions". You will see a box that starts with
<!-- Global site tag (gtag.js) - Google Analytics -->. Copy this entire code snippet. - Paste and Save: Paste the full code snippet into the designated "Header Scripts" box within your theme settings and click "Save" or "Publish." This action inserts the code into the
<head>section of every page, allowing Google Analytics to track user activity.
Method 3: Adding the Code Manually (For Advanced Users)
If your theme doesn’t have a script injection feature and you prefer to avoid plugins, you can add the code manually. This method gives you complete control but comes with a risk: if done incorrectly, you can break your site.
Important Warning: Always back up your site before editing theme files. It is also strongly recommended to use a child theme for any modifications. If you add code directly to your parent theme's files, your changes will be completely erased the next time your theme updates.
Option A: Edit Your functions.php File (Recommended Manual Method)
This is the proper way to add scripts to a WordPress site. You’ll add the GA tracking code using a PHP function.
- Navigate to “Appearance” -> “Theme File Editor.”
- On the right side, find and click on
functions.php. - Scroll to the very bottom of the file.
- Copy and paste the following code snippet, but remember to replace
G-XXXXXXXXXXwith your actual Measurement ID.
function ns_google_analytics() { ?>
<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', 'ns_google_analytics' ),After pasting the code, click "Update File." This function hooks into the wp_head action, which properly places the tracking script in your site’s <head> block.
Option B: Edit Your header.php File
This is a more direct but slightly less robust method. It involves placing the Global Site Tag directly into your theme’s header file.
- Go to “Appearance” -> “Theme File Editor.”
- On the right side, find and click on
header.php. - Locate the closing
</head>tag in the file. - Get the full Global Site Tag (gtag.js) code from your Google Analytics Web Stream details page.
- Paste the entire code block on the line just before the
</head>tag. - Click "Update File" to save your changes.
How to Verify Your Google Analytics Installation
After installing your tracking code, you need to make sure it’s actually working. Giving it 24-48 hours for data to fully populate is a good idea, but you can check for real-time data immediately.
The best way to confirm the setup is with the Realtime report in Google Analytics.
- Log in to your Google Analytics account and navigate to the correct property.
- In the left-hand navigation, click “Reports” and then click “Realtime.”
- In a separate browser window (an Incognito or Private window is best to avoid being logged in as a WordPress admin), visit your website. Click on a few pages.
- Switch back to the Google Analytics Realtime report. You should see the “Users in last 30 minutes” card show at least 1 user. You can also see which pages you visited show up in the "Views by Page title" card.
If you see your own visit appear on this report, congratulations! You have successfully installed Google Analytics on your WordPress site.
Final Thoughts
Connecting Google Analytics to your website is the first step toward making data-driven decisions. Whether you choose the simplicity of a plugin like Site Kit, the convenience of your theme's settings, or the direct control of manual editing, getting that tracking code installed properly opens up a world of insight into who your visitors are and what they care about most.
Once your data is flowing into Google Analytics, the next challenge is making sense of it. Instead of getting lost inside the complex GA4 interface, we built Graphed to simplify the whole process. We let you connect your Google Analytics account in seconds and then just ask for the reports you need in plain English. You can get instant answers and beautiful, real-time dashboards without the steep learning curve.
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?