How to Put Google Analytics Code into WordPress
Connecting Google Analytics to your WordPress site is one of the first and most important steps in understanding your audience. It's how you discover what content people love, where they come from, and how they interact with your website. This guide will walk you through a few simple methods to add the Google Analytics code to WordPress, from the easiest plugin-based solutions to manual options for those who prefer more control.
First, Let's Find Your Google Analytics Tracking Code
Before you can add Google Analytics to WordPress, you need to grab your tracking information. What you're looking for is either a "Measurement ID" or a small piece of JavaScript code called the "Global Site Tag" (gtag.js). The Measurement ID is a simple string of characters (e.g., G-XXXXXXXXXX) often used by plugins, while the full code snippet is used for manual installation.
Here’s how to find them in your Google Analytics 4 account:
- Log in to your Google Analytics account.
- Click the Admin gear icon in the bottom-left corner.
- Ensure you've selected the correct Account and Property in the respective columns. If you have a brand-new account, Google likely guided you through creating these already.
- In the Property column, click on Data Streams.
- Select the data stream for your website. It will likely be labeled with your website's URL.
Finding the Measurement ID
Once you're in your data stream details, you’ll see the Measurement ID at the top right. It starts with "G-". You can simply click the copy icon next to it. This is what you'll need for most plugin-based methods.
Finding the Global Site Tag (gtag.js)
For manual methods, you'll need the full code snippet. From the same data stream details page:
- Scroll down to the heading Google tag and click on View tag instructions.
- A new screen will appear. Under the tab that says Install manually, you'll see a box containing the JavaScript code snippet. This is your Global Site Tag.
- Click the copy icon to copy the entire code block to your clipboard.
Now that you have your Measurement ID and code snippet, you're ready to add them to WordPress. Let’s explore the best ways to do this.
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: Use a WordPress Plugin (The Easiest & Recommended Way)
For the vast majority of WordPress users, a plugin is the simplest, safest, and most effective way to install Google Analytics. You won’t have to touch any code, the setup is guided, and you often get helpful dashboards right inside WordPress. This also prevents your tracking code from being accidentally removed when you switch or update your theme.
Option A: Site Kit by Google
Site Kit is the official WordPress plugin from Google. Its primary job is to connect your site to various Google services - Analytics, Search Console, PageSpeed Insights, and AdSense - in just a few clicks. It’s free, reliable, and gives you a great overview of your site's performance without leaving your WordPress dashboard.
Here’s how to set it up:
- From your WordPress Dashboard, go to Plugins > Add New.
- Search for "Site Kit by Google."
- Click Install Now and then Activate.
- You'll see a new Site Kit menu item in your dashboard. Click it to start the setup wizard.
- The wizard will guide you through connecting your Google account. You’ll need to grant the plugin permissions to access your Google Analytics and Search Console data.
- Site Kit will automatically find your Google Analytics property. Simply confirm it’s the correct one, and the plugin will handle the rest, placing the necessary tracking code on your site.
That's it! Now you can view key metrics from Google Analytics directly within your WordPress dashboard.
Option B: MonsterInsights
MonsterInsights is another incredibly popular and user-friendly plugin for Google Analytics. It's focused solely on Analytics and offers more advanced tracking features that are easy to enable, such as event tracking for downloads, affiliate links, and outbound link clicks, which can be complex to set up manually.
The setup is very similar to Site Kit:
- In your WordPress Dashboard, navigate to Plugins > Add New.
- Search for "MonsterInsights."
- Click Install Now and Activate.
- Find the new Insights item on your dashboard menu and start the launch wizard.
- The wizard will ask you a few questions about your website and then guide you to connect your Google account.
- Authorize the connection, select the correct GA4 property when prompted, and complete the setup.
MonsterInsights will add the tracking code for you and begin feeding powerful, easy-to-read reports directly into your WordPress admin area.
Method 2: Manually Add the Code to a Headers & Footers Plugin
Maybe you don't need a full-featured plugin with dashboards and just want a lightweight way to add the tracking script. Instead of editing theme files directly (which is risky), a simple code snippets or headers/footers plugin lets you safely inject code into your site's header.
This method gives you control without the danger of breaking your site or losing your code when you update your theme.
- From your WordPress dashboard, navigate to Plugins > Add New.
- Search for "WPCode – Insert Headers and Footers" or a similar lightweight plugin.
- Install and activate the plugin.
- Go to the plugin's settings page, often found under Code Snippets > Header & Footer in your dashboard menu.
- Copy your entire Global Site Tag (gtag.js) snippet from your Google Analytics account.
- Paste the entire snippet into the box labeled "Header."
- Click Save Changes.
The plugin will now automatically insert the Google Analytics code into the <head> section on every page of your site. This is a clean, simple solution when you just need to get the script in place.
Method 3: Add the Code via Your Theme Options
Many modern WordPress themes come with a built-in feature to add tracking scripts or other custom code. This is a great middle-ground solution as it’s managed by the theme, is safe from theme updates, and doesn’t require an extra plugin.
The exact location of this setting varies by theme, but here are the general steps:
- In your WordPress dashboard, look for your theme’s options panel. This might be under Appearance > Customize or a dedicated top-level menu item named after your theme (e.g., Avada, Divi, GeneratePress).
- Search through the theme settings for a section called Integrations, Scripts, Header/Footer, or Analytics.
- Here, you should find a text box for adding scripts to the website header.
- Copy your full Global Site Tag (gtag.js) snippet from Google Analytics.
- Paste the entire snippet into the header scripts box.
- Save your changes.
If you're not sure if your theme has this feature or where to find it, a quick look at your theme's documentation should point you in the right direction.
How to Verify Google Analytics is Working
After installing the code, it’s always a good idea to confirm that it's working correctly and that Google is receiving data from your site. This only takes a minute.
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.
Check the Realtime Report
The most reliable method is to check the Realtime report in Google Analytics.
- Open your website in a new tab or in an incognito browser window. This ensures you appear as a new visitor.
- In your Google Analytics dashboard, navigate to Reports > Realtime.
- You should see at least '1' in the "Users in last 30 minutes" card. You might also see your city appear on the map.
If you see activity, congratulations! Your tracking code is working. It can sometimes take a few minutes to appear, so be patient. If you’re not seeing any data after five or ten minutes, an ad-blocker may be preventing the script from running. Try loading the site on a different device or browser.
View Your Site’s Page Source
For a more technical check, you can look for the code snippet in your website's HTML source. Right-click on a page of your website and select “View Page Source.” Use the search function (Ctrl + F or Cmd + F) and search for either “gtag.js” or your Measurement ID (e.g., “G-XXXXXXXXXX”). If the code appears in the source, it's installed on the page.
Final Thoughts
Getting Google Analytics data flowing is a critical first step, and as you can see, WordPress offers flexible methods to fit any comfort level. For an easy, future-proof solution, using a plugin like Site Kit by Google or MonsterInsights is almost always the best path. Once your data is being collected, the real work of turning that data into actionable insights begins.
That next step is exactly what prompted us to build Graphed. Marketers and business owners shouldn't have to jump between a dozen tabs - from Google Analytics to their ad platforms and CRM - just to understand performance. We make it easy by connecting all your data sources in one place. You can ask for reports and build dashboards in simple, natural language, freeing you from tedious manual reporting so you can focus on making smarter, data-driven decisions that grow your business.
Related Articles
How to Create Facebook Ads API for Claude Code
Create a Meta Marketing API access token that never expires, using a system user, so Claude Code can pull Facebook ad reports and manage campaigns.
ClickHouse vs Postgres: When to Switch to Columnar
Comparing ClickHouse vs PostgreSQL means matching storage architecture to workload. Row storage wins for transactions. Columnar wins for scan-heavy analytics.
Google Ads for Orthodontists: Get More Booked Consults
Most orthodontic Google Ads campaigns waste money on low-intent searches. The problem is structure, not the platform.