How to Add Google Analytics Code in Yoast SEO
Looking to connect Google Analytics to your WordPress site using the Yoast SEO plugin? You've probably seen older guides showing a simple box in Yoast's settings, but that feature has since been removed, causing a lot of confusion. This tutorial clarifies why that change happened and walks you through the current, best methods for adding your tracking code correctly.
Why Bother Connecting Google Analytics to WordPress?
Before we jump into the "how," it's helpful to remember the "why." Connecting Google Analytics to your site is like turning the lights on in a dark room. Suddenly, you can see who's visiting, where they're coming from, and what they do once they're there. It provides essential data that helps you make smarter decisions instead of just guessing.
Once you're tracking data, you can answer questions like:
- How many people are visiting my site? Track daily, weekly, and monthly traffic trends.
- Where do my visitors come from? See if your traffic is coming from Google search, social media, other websites, or direct visits.
- Which pages or posts are most popular? Find out what content resonates with your audience so you can create more of it.
- Is my traffic growing? Compare performance over time to see if your marketing efforts are paying off.
- What is the user journey on my site? See which pages people land on first and where they go next.
Without this data, you’re flying blind. With it, you can double down on what works, fix what doesn’t, and get a real sense of your website's performance.
First, Get Your Google Analytics 4 Measurement ID
No matter which method you use to connect Google Analytics, you’ll need a unique code from Google. In the past, this was called a "Tracking ID" (it looked like UA-12345678-1). But with the latest version, Google Analytics 4, it’s now called a “Measurement ID” and looks like G-XXXXXXXXXX.
If you don't have a Google Analytics account yet, you'll need to create one first. Just head to the Google Analytics website and follow the prompts. If you already have one, here’s how to find your Measurement ID.
Step-by-Step: Finding Your GA4 Measurement ID
- Log in to your Google Analytics account.
- If you have multiple properties, make sure you've selected the correct one in the top-left corner.
- Click on the Admin icon (the gear icon ⚙️) in the bottom-left corner of the page.
- In the ‘Property’ column, click on Data Streams.
- You should see your website listed as a data stream. Click on it.
- A pane will slide out from the right. Your Measurement ID (starting with "G-") will be listed in the top right. Copy this — you'll need it soon.
In this same view, under "Google tag," you can click on View tag instructions to get the full tracking script snippet (the gtag.js script). Some methods require the full script, while others only need the Measurement ID, so it’s good to know where to find both.
An Important Update: Yoast SEO and Google Analytics
Here's the part that trips most people up. For years, the Yoast SEO plugin had a dedicated field where you could paste your Google Analytics UA code. It was simple and convenient. However, this feature has been removed from Yoast SEO.
Why did they do this? The main reason is that the web has evolved. Google’s shift from Universal Analytics to Google Analytics 4 brought a new, more complex tracking script (gtag.js). Adding this new script is best handled by methods that specialize in code placement or integrate more deeply with Google's services.
Yoast’s team recognized that their core focus is on-page SEO, not script management. They decided to streamline the plugin by removing this feature, guiding users toward more robust and appropriate solutions for adding tracking codes. So, if you're pulling your hair out looking for that Google Analytics field in Yoast, you can stop looking! Let's cover the three best alternatives.
The Modern Way: 3 Best Methods to Add Google Analytics
Since the Yoast method is no longer an option, here are the most effective and popular ways to get your site connected to Google Analytics.
Method 1: Site Kit by Google (The Easiest & Recommended Option)
This is the official Google plugin for WordPress. It's free, secure, and the most straightforward way to connect your site not just to Google Analytics, but also to Search Console, AdSense, and PageSpeed Insights without ever touching any code.
How to Set It Up:
- From your WordPress dashboard, go to Plugins > Add New.
- Search for "Site Kit by Google" and click Install Now, then Activate.
- Once activated, you’ll see a banner at the top of your dashboard. Click the Start Setup button.
- You'll be guided through a simple setup wizard. It will ask you to sign in with the Google account you use for Google Analytics. Grant the necessary permissions when prompted.
- Site Kit will automatically verify that you own the website.
- Next, it will scan for existing Google services connected to your site. It will likely find your Google Analytics property automatically. Just confirm that it’s the correct one and click Configure.
- That’s it! Site Kit will place the GA4 tracking code on every page of your site for you. You’ll also get a new dashboard right inside WordPress showing high-level stats from Analytics and Search Console.
Method 2: Using a Header and Footer Code Plugin
If you prefer a lightweight solution and don't need the extra features of Site Kit, a simple code insertion plugin is a great choice. It gives you a safe place to add scripts like the Google Analytics tag without the risk of breaking your theme files.
How to Set It Up with WPCode:
- From your WordPress dashboard, go to Plugins > Add New.
- Search for "WPCode – Insert Headers and Footers" and install and activate it.
- In your Google Analytics account, go back to Admin > Data Streams, click your stream, and select View tag instructions.
- Under the "Install Manually" tab, copy the entire global site tag (the code that starts with
<!-- Google tag (gtag.js) -->). - Back in WordPress, navigate to Code Snippets > Header & Footer from the left-hand menu.
- Paste the entire Google Analytics script into the Header box.
- Click Save Changes.
This plugin now ensures that your GA4 tracking code is loaded correctly in the <head> section of every page on your site.
Method 3: Add the Code Manually (Advanced Users Only)
This method involves editing your theme’s header.php file directly. It’s effective but comes with a major warning: if you make a mistake, you can break your website. Only do this if you are comfortable editing PHP files and always use a child theme. If you edit the parent theme directly, your changes will be overwritten the next time the theme is updated.
How to Do It in a Child Theme:
- Make sure you have a child theme created and activated. If not, stick to methods 1 or 2.
- Go to your Google Analytics account and copy the full
gtag.jsscript, just as you would for the plugin method. - In your WordPress dashboard, go to Appearance > Theme File Editor.
- On the right side, under Theme Files, find and click on Theme Header (header.php). Make sure you are editing the file from your child theme, not the parent.
- Find the closing
</head>tag in the file. - Paste your full Google Analytics tracking snippet on a new line just before the
</head>tag. - Click the Update File button.
<!-- This is where other code in your header will be -->
<!-- YOUR COPIED GOOGLE ANALYTICS TAG GOES HERE -->
</head>This method works perfectly, but its manual nature makes it more prone to human error.
How to Verify That It's Working Correctly
Congratulations, you’ve installed the code! But how do you know it’s actually working? Here’s a quick way to check.
- Log in to your Google Analytics account.
- In the left-hand menu, navigate to Reports > Real-Time. This view shows activity on your site as it happens.
- Now, open your website in a new browser tab or on your phone (if you’re not logged in as the admin, that’s even better).
- Click around a few pages on your site.
- Switch back to the Real-Time report in Google Analytics. You should see at least one active user (that's you!) on your site. If your visit appears, everything is set up correctly. This can sometimes take a minute or two to appear.
Final Thoughts
While many online tutorials still reference Yoast SEO's old Google Analytics feature, it's important to know that functionality has been removed. The best and most reliable ways to connect your WordPress site and GA4 today are by using an official plugin like Site Kit, a lightweight code snippet plugin, or by manually adding the code to a child theme for full control.
Once you start collecting powerful data from Google Analytics, the next challenge is making sense of it all. To simplify your reporting, our platform helps you connect data sources like Google Analytics, Shopify, or your CRM in just a few clicks. Using simple, natural language, you can ask Graphed to instantly create real-time dashboards and reports, so you can stop wrestling with raw data and spend more time uncovering actionable insights. Check out Graphed to see how easy analytics can be.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.