Can You Use Google Analytics on WordPress?
Yes, you can and absolutely should use Google Analytics with your WordPress website. Connecting them is one of the most important first steps for understanding your audience and growing your traffic. This tutorial will walk you through exactly how to set up Google Analytics on WordPress using several different methods, ranging from simple plugin installations to manual code placement for more advanced users.
Why Connect Google Analytics to WordPress?
Before jumping into the "how," let's quickly cover the "why." Your WordPress dashboard provides some basic stats, but they barely scratch the surface. Installing Google Analytics unlocks a treasure trove of data that helps you make smarter decisions about your website and content.
With Google Analytics, you can:
Understand Your Audience: See where your visitors come from geographically, what language they speak, and what devices (desktop, tablet, mobile) they use to browse your site.
Track Content Performance: Discover your most popular pages and blog posts. Understanding what resonates with your audience helps you create more of the content they love.
Analyze Traffic Sources: See exactly where your traffic is coming from. Are people finding you through Google search (organic), social media, links from other websites (referral), or by typing your URL directly? This tells you which marketing channels are working.
Monitor User Behavior: Learn how people interact with your site. You can see how long they stay, how many pages they visit per session, and which page they often leave from, which can highlight areas for improvement.
Measure Goals and Conversions: Set up custom goals to track important actions, like newsletter signups, contact form submissions, or ebook downloads. This helps you measure the effectiveness of your website in achieving business objectives.
In short, Google Analytics turns your website from a black box into a source of actionable insights that can directly influence your growth strategy.
First, Get Your Google Analytics Measurement ID
No matter which method you choose to install Google Analytics, you first need to generate a unique tracking code from your Google Analytics account. This code tells Google that you are the owner of the website and that it should be sending data to your specific analytics property.
If you're using a version of Google Analytics from before 2020, you might be familiar with a "Tracking ID" that started with "UA-". Google has since launched Google Analytics 4, which now uses a "Measurement ID" that starts with "G-". This guide focuses on the current GA4 setup.
Step-by-Step Guide to Finding Your Measurement ID:
Create or Log In to Your Account: Head over to the Google Analytics website and sign in with your Google account. If you don't have an account, you'll be prompted to create one for free.
Navigate to the Admin Panel: Once you're in, look for the gear icon labeled "Admin" in the bottom-left corner of the page and click it.
Create a New Property: In the 'Property' column, click the "+ Create Property" button. Enter a name for your property (usually your website's name), select your reporting time zone and currency, and click "Next."
Provide Business Details: Answer the few questions about your business category and size. This helps Google tailor your experience. Click "Create."
Set Up a Data Stream: Now you need to tell Google where to collect data from. Choose "Web" as your platform.
Enter Your Website Information: Enter your WordPress site's URL (e.g., www.yourwebsite.com) and a "Stream name" (again, your website's name is fine here). Click "Create stream."
Find Your Measurement ID: A "Web stream details" page will appear. In the top-right corner, you'll see your Measurement ID, which looks like
G-XXXXXXXXXX. Copy this ID - you'll need it for the next steps! You can also find the full tracking script by clicking "View tag instructions."
Keep this browser tab open, as you may need to copy the full code snippet in the next section.
Method 1: Add Google Analytics with a Plugin (The Easy Way)
For most WordPress users, using a plugin is the safest, fastest, and easiest way to install Google Analytics. You don't have to touch any code, and a good plugin can give you the added benefit of viewing key statistics directly within your WordPress dashboard.
Using Site Kit by Google
Site Kit is Google's official plugin for WordPress, designed to connect your site to various Google services, including Analytics, Search Console, and AdSense. It's an excellent, all-in-one choice.
In your WordPress dashboard, navigate to Plugins > Add New.
Search for "Site Kit by Google".
Click Install Now, and then Activate.
A setup wizard will appear. Click "Start Setup" and follow the on-screen prompts to sign in with your Google account and grant the necessary permissions.
Site Kit will automatically detect your Google Analytics account and property that you created earlier. Simply select it and click "Configure Analytics."
That's it! Site Kit handles everything for you and will even start showing you simplified traffic reports right inside WordPress.
Using WPCode - Insert Headers and Footers
If you prefer a more lightweight approach or already use a plugin to manage scripts, a code snippet manager like WPCode is a great option. It lets you add the tracking code without having to edit theme files directly.
Go to Plugins > Add New in your WordPress dashboard.
Search for "WPCode," install it, and activate it.
In the left-hand menu, navigate to Code Snippets > Header & Footer.
Go back to your Google Analytics tab and copy the entire "Global site tag (gtag.js)" script. It will look something like this:
Paste this entire block of code into the "Header" box within the WPCode settings.
Click Save Changes at the top of the page.
Your tracking code is now active on every page of your site.
Method 2: Add Google Analytics Manually (Advanced)
If you're comfortable editing code and prefer to avoid additional plugins, you can add the Google Analytics tracking script directly to your theme's files.
Heads-up: This method is recommended only for advanced users. A small mistake can break your website. It is highly recommended that you use a child theme when making these changes. If you edit the parent theme files directly, your changes will be completely erased the next time you update your theme.
Option A: Adding a Function to functions.php
This is the technically preferred manual method. It adds the script programmatically via WordPress hooks.
In your WordPress dashboard, go to Appearance > Theme File Editor.
From the list of theme files on the right, select Theme Functions (functions.php). Make sure you are editing your child theme's file!
Scroll to the bottom of the file and paste the following PHP code. Be sure to replace
G-XXXXXXXXXXwith your actual Measurement ID.
Click Update File to save your changes.
Option B: Editing the Theme Header (header.php)
This method is more straightforward but is slightly less robust than using the functions.php approach.
Navigate to Appearance > Theme File Editor.
Select the Theme Header (header.php) file from the list.
Find the closing
< /head >tag in the file.Paste your entire Google Analytics tracking script (the same one used in the WPCode method) right before the
< /head >tag.Click Update File.
How to Verify Your Google Analytics Is Working
After you've added the code, you need to make sure it's actually working. The easiest way to do this is with the Realtime report in Google Analytics.
Log in to your Google Analytics account and navigate to the property for your website.
On the left-hand menu, go to Reports > Realtime.
In a new browser tab or on your phone, open your WordPress website. Navigate to a few different pages.
Switch back to the Realtime report view in Google Analytics. You should see your visit show up as "1" in the "Users in Last 30 Minutes" card.
If you see activity, congratulations! Your setup is successful. It may take 24-48 hours for data to start populating in the standard reports, so don't worry if they look empty at first.
Final Thoughts
Connecting Google Analytics to your WordPress site is an essential step toward making data-driven decisions. Whether you choose the user-friendly approach of a plugin like Site Kit or the hands-on control of manual installation, the key is to get that powerful data flowing so you can better understand your traffic and audience.
Once your data starts rolling in, the next step is turning that information into insights. Instead of getting overwhelmed by the dozens of reports in standard analytics tools, you can simply ask for what you need. We built Graphed to be the easiest way to analyze your data by connecting directly to sources like Google Analytics. You just use plain English to ask questions like, "Show me my top 10 blog posts from organic search last month," or "Create a dashboard comparing traffic from social media vs. newsletters" to get instant answers and live dashboards without the steep learning curve.