How to Find Google Analytics Code in WordPress
Trying to find where your Google Analytics tracking code is hiding in your WordPress dashboard can feel like searching for a needle in a haystack. The good news is that it’s usually in one of a few common places. This guide will walk you through exactly where to look for your Google Analytics code, from the simplest methods to the more technical ones.
First, What Is the Google Analytics Tracking Code?
The Google Analytics tracking code is a special snippet of JavaScript that you place on your website. Its job is to collect data about how visitors interact with your site - what pages they view, how long they stay, where they came from - and send that information back to your Google Analytics account for reporting.
There are two main versions of this code you might run into:
Google Analytics 4: This is the current version. The code is called the Google tag (gtag.js) and it uses a Measurement ID that looks like G-XXXXXXXXXX.
Universal Analytics (UA): This is the older, now-retired version. The code used a library called analytics.js and had a Tracking ID that looked like UA-XXXXXXX-X.
Even though Universal Analytics stopped collecting data in mid-2023, you might still find its old code on a site, especially if it hasn’t been updated in a while.
Here’s a quick look at what the full GA4 tracking script typically looks like:
Why Might You Need to Find This Code?
There are several common reasons why you’d need to locate your Google Analytics code:
You're updating your site: If you're switching WordPress themes, you need to make sure the tracking code moves with the new theme so you don’t lose any data.
Setting up integrations: Tools like Google Search Console or Google Ads sometimes require you to verify ownership or link accounts using your GA property.
Troubleshooting tracking issues: If your reports look strange or you suspect data isn't being collected properly, the first step is to check if the code is installed correctly.
Confirming a GA4 migration: If you've recently moved from Universal Analytics to GA4, you'll want to find the old UA code and make sure it's been removed or replaced correctly.
Duplicate tracking: Sometimes, a new plugin or theme update can accidentally add a second instance of the tracking code, which can skew your data by double-counting pageviews.
Method 1: Check Your Plugins First
For most WordPress users, the easiest way to add the Google Analytics code is with a plugin. This is the first and most likely place your code is hiding. Your task is to check which plugins you have installed that might handle this task.
In your WordPress dashboard, navigate to Plugins > Installed Plugins. Look for anything with "Analytics," "Stats," "Header," "Footer," or "Scripts" in the name. Here are a few common suspects:
A. Dedicated Analytics Plugins
These plugins are built specifically to connect your site to Google Analytics and offer detailed reports right in your dashboard.
MonsterInsights: This is one of the most popular analytics plugins. To find your code, go to Insights > Settings in your WordPress dashboard. The plugin usually authenticates directly with Google, but it will display your Measurement ID or let you manually enter it in the "General" or "Advanced" tabs.
Site Kit by Google: Google's own official plugin for WordPress connects your site to multiple Google services. Navigate to Site Kit > Settings > Connected Services. Click on ‘Analytics’ to see your account details and Measurement ID.
GA Google Analytics: This is another well-known plugin. Its settings are typically found under Settings > Google Analytics. The settings page should have a clear field showing the GA Tracking ID.
B. General Script or Code Insertion Plugins
Many people use plugins that aren't specific to analytics but are designed to add any kind of code snippet to your website’s header or footer. This keeps custom code separate from your theme files, which is a good practice.
WPCode - Insert Headers and Footers: This is arguably the most popular plugin for this job. Check for it by navigating to Code Snippets > Header & Footer or Code Snippets > All Snippets. Look for a snippet named "Google Analytics" or similar. The full JavaScript code will be pasted in one of the boxes labeled "Header."
Simple Custom CSS and JS: Similar to the above, this plugin allows you to add custom code. Look for a JS snippet named something similar to "Analytics."
Method 2: Check Your Theme Settings
If you’ve checked your plugins and found nothing, the next stop is your WordPress theme’s settings panel. Many modern, feature-rich themes - especially premium themes from marketplaces like ThemeForest - include a dedicated section for adding tracking codes directly.
This is convenient because you don’t need an extra plugin, but it also means the code can get forgotten if you ever change themes.
How to check:
From your WordPress dashboard, go to Appearance > Customize.
Once the Customizer loads, look for sections with names like:
“Theme Settings” or “Theme Options”
“General Settings”
“Header Options”
“Scripts” or “Code”
“Analytics” or “Integrations”
Go through these sections until you find a field or textarea labeled something like "Header Scripts," "Footer Scripts," or "Google Analytics Tracking Code." This is where you’ll likely find the JavaScript snippet or just the Measurement ID (
G-XXXXXXXXXX).
The exact location varies greatly between themes, so you may need to click around a bit to find it. But this approach is usually much safer than digging into the actual code files of your theme.
Method 3: Check Your Theme’s Code Files (The Technical Approach)
If your search turns up empty after checking plugins and theme options, it’s possible a developer manually hardcoded the Google Analytics script directly into your theme’s source files. This isn't a recommended practice, as any changes can be overwritten during a theme update, but it's still a common place to look.
Quick warning: Be careful editing theme files. A small mistake can break your site. It's always a good idea to have a recent backup before making any changes here. If your site uses a child theme, check its files first before looking in the parent theme.
You can access these files by going to Appearance > Theme File Editor from your WordPress dashboard.
A. The Header File (header.php)
This is the most common place for manually added tracking scripts. The header.php file contains the HTML for the top part of your site, including the crucial <head> area. The Google Analytics code needs to be placed just before the closing </head> tag.
Steps:
In the Theme File Editor, select your active theme (or child theme).
Find and click on the
header.phpfile in the list on the right.Scan the contents of the file. Look for the tracking script snippet we showed earlier - you're looking for code containing
gtag.jsand your GA Measurement ID.
B. The Functions File (functions.php)
A slightly more advanced way developers add the code is by using the functions.php file. This method hooks the script into WordPress’s standard loading process, usually with a function called wp_head.
Steps:
In the Theme File Editor, click on the
functions.phpfile.Scan the contents of the file for a function that might add scripts. Search for terms like "gtag," "_analytics_script," or similar. The code might look something like this:
Method 4: Confirm with Your Browser's Developer Tools
This final method won't tell you where the code is in your WordPress backend, but it will confirm if the code is present and loading on your live website. It's the most reliable way to check what a visitor’s browser is actually seeing.
Open your website in a web browser with developer tools available, like Chrome.
Right-click anywhere on the page and select View Page Source or Inspect. "View Page Source" opens a new tab with the site's raw HTML, which is often easier to search.
From "View Page Source": Press
Ctrl+F(on Windows) orCmd+F(on Mac) to open the find bar.From "Inspect Element": Go to the
Elementstab and then pressCtrl+F(Windows) orCmd+F(Mac).
In the search box, type G- (for a GA4 ID) or UA- (for an older analytics ID). Alternatively, you can search for
gtag.js.If you see the JavaScript snippet displayed, it confirms that Google Analytics is successfully installed and communicating from your site. Now you just have to pinpoint its location using the methods above.
If nothing appears, it means the analytics code is not currently operating on that page - even if you think you’ve already added it.
Still Can't Find It? Next Steps
If you've investigated every nook and cranny and still can't find your Google Analytics code, it’s likely it isn't installed. Here are a few paths forward:
If you find a code starting with "UA," you'll want to get this replaced with the updated GA4 code. To do so, find the old code in your site and replace it with the new one using the installation process provided by Google.
In the case of duplicate tracking codes, you may have added a plugin that inadvertently included one. Decide on one method of installation - preferably using a plugin - and remove any other code snippets. Otherwise, your events might be counted twice.
No code at all? Simply install it! Get the GA4 code from your Google Analytics account. For a hassle-free installation, consider using a code management plugin like WPCode. This keeps your code separate from theme files, protecting it from accidental deletion during a theme update.
Final Thoughts
Tracking down your Google Analytics code in WordPress involves a top-down search starting from the easiest spots to the most technical. You should always begin by checking your plugins, followed by your theme’s settings panels, before ever resorting to exploring your site’s code files like header.php.
Once you’ve got your Google Analytics tracking working correctly, the challenge becomes making sense of all the information you’re collecting. This is where we designed Graphed to help. We created it to be the easiest way to connect your data sources - including Google Analytics - and build real-time monitoring reports and dashboards using simple, natural language. It’s like having a data analyst on your team without the hours of manual report pulling.