Where Does Google Analytics Code Go in WordPress?
Finding the right place to add your Google Analytics tracking code in WordPress can feel like a scavenger hunt, but it's much simpler than it looks. You don’t need to be a developer to get it done. This guide will walk you through a few tried-and-true methods, from the easiest plugin solutions to manual code snippets, so you can start tracking your website traffic today.
First, What is the Google Analytics Tracking Code?
The Google Analytics tracking code is a small block of JavaScript that you install on your website. When a visitor lands on a page, this script runs and sends valuable, anonymous information back to your Google Analytics account - things like which page they’re on, what device they’re using, and how they found your site.
For this script to work correctly, it needs to be present on every single page of your website. Luckily, a WordPress site is built using template files, so you only need to add the code once in the right spot for it to appear everywhere.
Two Types of Tracking Codes: GA4 vs. Universal Analytics
You’ll encounter two different versions of this tracking code, depending on which version of Google Analytics you’re using. Since July 2023, Google Analytics 4 is the standard, but you might still see old code snippets from the previous version, Universal Analytics (UA).
- Google Analytics 4: Uses a "Global Site Tag" (gtag.js). The ID for GA4 starts with "G-". This is the code you'll use for any new setup.
- Universal Analytics (UA): This older version used a tracking ID that starts with "UA-". While UA no longer processes new data, you might still encounter it on older sites.
We'll focus on GA4, as it's the current standard.
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 Find Your Google Analytics Tracking Code
Before you can add the code to WordPress, you need to find it in your Google Analytics account. If you haven't created a GA4 property yet, do that first.
Here’s how to locate your gtag.js snippet:
- Log in to your Google Analytics account.
- Click the Admin gear icon in the bottom-left corner.
- In the Property column, make sure your correct GA4 property is selected from the dropdown menu.
- Click on Data Streams.
- Select your website's data stream from the list. It will usually have your website's domain name.
- Under the Google tag section, click on View tag instructions.
- A new page will load. Click on the Install manually tab.
- Voila! You will see the JavaScript code snippet you need. Click the copy icon to copy it to your clipboard.
Keep this code handy for the next steps.
Method 1: Using a WordPress Plugin (The Easiest Way)
For most users, plugins are the safest and easiest way to connect Google Analytics to WordPress. They handle the code placement for you, so you never have to touch your site's files directly. This also prevents your tracking code from getting erased if you ever update your WordPress theme.
Option A: Site Kit by Google
Site Kit is the official WordPress plugin from Google. It simplifies connecting your website not only to Google Analytics but also to other Google services like Search Console, PageSpeed Insights, and AdSense, all from your WordPress dashboard.
How to Set It Up:
- In your WordPress dashboard, go to Plugins > Add New.
- Search for "Site Kit by Google" and click Install Now, then Activate.
- You'll see a banner prompting you to start setup. Click the setup button.
- Follow the on-screen instructions to sign in with your Google account - the same one you used to create your Analytics property.
- Site Kit will automatically verify your site ownership and let you choose which services to connect. Select Google Analytics, choose your account and property, and you’re done!
Option B: MonsterInsights
MonsterInsights is one of the most popular Google Analytics plugins for WordPress. It's incredibly user-friendly and adds helpful reports right inside your WordPress dashboard, so you don't even have to log in to Google Analytics to see your most important metrics.
How to Set It Up:
- Go to Plugins > Add New.
- Search for "MonsterInsights" and click Install Now, then Activate.
- A setup wizard will launch. Follow the steps to connect your WordPress site to your Google Analytics account via their guided process.
- The plugin will automatically fetch and place the correct tracking code for you.
Option C: A Lightweight Header & Footer Plugin
If you don't want a heavy-duty plugin with dashboard reports and just want to add the code snippet, a header and footer plugin is a great choice. One of the most popular is called "WPCode - Insert Headers and Footers."
How to Set It Up:
- Go to Plugins > Add New.
- Search for "WPCode," install, and activate it.
- From your dashboard menu, go to Code Snippets > Header & Footer.
- Paste your full Google Analytics tracking code snippet into the Header box.
- Click Save Changes.
Method 2: Manually Adding the Code to Your WordPress Theme Files
Quick Warning: This method is recommended only if you know what you are doing and are comfortable editing theme files. Before proceeding, make sure you have a recent backup of your site. Most importantly, always use a WordPress child theme. If you add code to your parent theme's files, it will be lost the next time the theme updates.
Option A: Add Code to header.php
The header.php file contains the <head> section of your website’s HTML structure. Placing the code here ensures it loads on every single page. This is the most common manual placement method.
- From your WordPress dashboard, navigate to Appearance > Theme File Editor.
- From the file list on the right, make sure you've selected your child theme.
- Find and click on the file named header.php.
- Scroll down in the editor until you find the closing
</head>tag. - Paste your copied Google Analytics tracking code a few lines just before the
</head>tag. - Click the Update File button.
Option B: Add Code to functions.php (A Cleaner Method)
Developers often prefer this method because it separates the tracking logic from the presentation file (header.php). It involves adding a PHP function that "hooks" into the WordPress header loading process.
Another Quick Warning: A single error in functions.php can take down your entire site. Be extremely careful when editing this file.
- Go to Appearance > Theme File Editor and again, make sure your child theme is active.
- From the file list, find and click on functions.php.
- Scroll to the very bottom of the file.
- Copy and paste the following code snippet, adding it at the very end of the file:
function add_my_ga_code() {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<!-- Paste Your Entire GA Code Snippet Here -->
<?php
}
add_action('wp_head', 'add_my_ga_code'),Make sure to replace the line <!-- Paste Your Entire GA Code Snippet Here --> with your actual tracking code from Google Analytics.
- Click Update File.
How to Check if Google Analytics Is Working
Once you’ve installed the code with one of the methods above, you’ll want to make sure it's actually working.
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.
Use the Realtime Report
The fastest way to test your connection is Google Analytics’ built-in Realtime report.
- Log in to your Google Analytics account.
- Navigate to Reports > Realtime.
- In a separate browser window (preferably an incognito/private one to avoid seeing your own logged-in activity), visit your website.
- Back in the Realtime report, you should see the number of "Users in last 30 minutes" change to at least 1.
If you see your visit, it’s working! It can sometimes take a minute or two to register, so be patient. If nothing appears after a few minutes, double-check your code placement or plugin settings.
Check the Page Source Code
You can also check your site's HTML to see if the script is physically present. Simply visit your website, right-click anywhere, and select "View Page Source." Use the Find feature (Crtl+F or Cmd+F) and search for gtag.js or your measurement ID (e.g., "G-XXXXXXXXXX"). If the code snippet appears in the source, you’ve installed it correctly.
Final Thoughts
You've successfully installed the Google Analytics tracking code on your WordPress site! Whether you chose the ease of a plugin or the control of a manual placement, you now have the foundation for collecting powerful data about your visitors. This tracking is the essential first step to understanding what's working on your site and where you can improve.
But getting the code installed is just the beginning. The real value comes from turning all that raw data into meaningful insights. Standard Google Analytics reports can be overwhelming, but we built Graphed to cut through the noise. We let you connect your data and just ask for what you want to see - "Show me my top traffic sources this month in a bar chart" or "Create a dashboard tracking blog post page views." No more digging through confusing menus, just plain-English questions and instant answers.
Related Articles
Facebook Ads for Locksmiths: The Complete 2026 Strategy Guide
Learn how to use Facebook ads for locksmiths in 2026 to generate quality leads beyond emergency services. Complete strategy guide covering audience targeting, creative best practices, campaign structure, and budget recommendations.
Facebook Ads for Tutors: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for tutors in 2026. Complete guide covering targeting, ad formats, budgets, and proven strategies that convert.
Facebook Ads for Bail Bonds: The Complete 2026 Strategy Guide
Learn the proven strategies bail bond agencies use to generate leads in 2026 despite Facebook and Google ad bans. Includes local SEO, review strategy, and Bing Ads tactics.