Where to Put Google Analytics in WordPress?

Cody Schneider9 min read

Adding Google Analytics to your WordPress site is one of the most important first steps you can take to understand your audience and grow your traffic. But if you're not a developer, it can be intimidating to figure out exactly where the tracking code is supposed to go. This guide will walk you through the simplest and safest methods for adding Google Analytics to WordPress, so you can start making data-driven decisions right away.

First, What Is a Google Analytics Tracking Code?

Before you can add it to your site, you need to know what you're looking for. The Google Analytics tracking code is a unique snippet of JavaScript that you place on your website. When a visitor arrives, this code runs in their browser and sends information about their activity - like which page they're on, what device they're using, and how they found you - back to your Google Analytics account.

Every website with Google Analytics has a unique code, which is how Google knows to send the data to your account and not someone else's. You simply need to get your unique code and place it on every page of your WordPress site.

Modern Google Analytics gives you two key pieces of information:

  • Measurement ID: A short identifier that looks like G-XXXXXXXXXX. This is often all you need when using a WordPress plugin.
  • Global Site Tag (gtag.js): A larger JavaScript snippet. This is what you'll use if you're adding the code manually to your theme files.

How to Find Your Tracking Code in Google Analytics

If you don't have a Google Analytics account yet, you’ll need to create one. If you already have an account setup, you can skip to step 4.

  1. Go to the Google Analytics website and sign in with your Google account.
  2. Click "Start measuring" to create a new account. You will be prompted to create both an "Account" (your business) and a "Property" (your website). Fill out the required details.
  3. On the "Data collection" step, choose "Web" as your platform.
  4. Enter your website URL (e.g., www.yourwebsite.com) and a "Stream Name" (e.g., "My Website"). Then click "Create stream."
  5. Once your data stream is created, you'll see a screen titled "Installation instructions." This page contains your unique Measurement ID at the top and the full Global Site Tag below. Keep this browser tab open, as you'll need to copy this information in the next steps.

Method 1: The Easiest Way Using a Plugin (Recommended)

For almost every WordPress user, using a plugin is the best way to add Google Analytics. It's the safest, fastest, and most beginner-friendly option. It eliminates the risk of accidentally breaking your site by editing code, and many plugins offer extra features, like showing you a simple dashboard of your traffic right inside your WordPress admin area.

We recommend using the official "Site Kit by Google" plugin, as it's built and maintained by Google and provides seamless integration not just for Analytics, but for other Google tools like Search Console and AdSense.

Step-by-Step Guide for Using Site Kit:

  1. Install and Activate the Plugin From your WordPress dashboard, navigate to Plugins > Add New. In the search bar, type "Site Kit by Google" and press Enter. Click “Install Now” and then “Activate.”
  2. Begin the Setup Wizard Once activated, you’ll see a large blue banner prompting you to "Start Setup." Click on it. This will launch the Site Kit setup wizard.
  3. Connect Your Google Account You'll be guided through an authentication process. Click "Sign in with Google" and choose the Google account you used to create your Analytics property. You will need to grant Site Kit permission to access your Google account data.
  4. Verify Site Ownership Site Kit will automatically verify that you own the website by connecting to your Google Search Console. If you don't have Search Console set up, Site Kit will help you do that with one click.
  5. Connect to Google Analytics After verifying ownership, Site Kit will prompt you to "Connect service" for Google Analytics. It should automatically detect your existing Analytics account and property that you created earlier. Select it from the dropdown lists and click "Configure Analytics."

That’s it! Site Kit automatically places the necessary tracking code in the correct location on your website. You don’t have to copy, paste, or edit any code yourself. Plus, you’ll now have a new "Site Kit" section in your WordPress dashboard menu where you can view your key traffic metrics without leaving your site.

Method 2: Manually Adding the Code to Your Theme (For Advanced Users)

If you prefer to avoid adding another plugin to your site, you can add the Google Analytics code directly into your theme's files. This method requires some comfort with editing code. If you make a mistake, you could potentially break your website, so proceed with caution.

Important: You should never edit your parent theme’s files directly. Any changes you make will be wiped out the next time your theme receives an update. Always use a child theme for customizations like this. A child theme inherits the look and functionality of the parent theme but allows you to safely modify its files.

Option A: Adding code to functions.php

The best manual method is to add the code using your child theme’s functions.php file. This is cleaner than editing the header file directly and keeps your tracking scripts separate from your theme’s display structure.

  1. Navigate to the Theme File Editor From your WordPress dashboard, go to Appearance > Theme File Editor. Make sure you read and understand the warning that pops up.
  2. Select Your Child Theme and functions.php On the right-hand side of the editor, make sure your child theme is selected from the dropdown menu. Then, click on the file named "Theme Functions" (functions.php) from the list of theme files.
  3. Add the Following PHP code Go back to your Google Analytics tab and copy the entire Global Site Tag (gtag.js) snippet. Then, paste the following PHP snippet at the very bottom of your functions.php file. Replace the placeholder comment with your actual GA code.
add_action('wp_head', 'add_google_analytics_code'),
function add_google_analytics_code() { ?> 
    <!-- PASTE YOUR GLOBAL SITE TAG (GTAG.JS) FROM GOOGLE HERE -->
    <script async src="https://www.googletagmanager.com/GTM-XXXXXXXXXX.js?id=G-YOUR_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [],
        function gtag(){dataLayer.push(arguments),}
        gtag('js', new Date()),
        gtag('config', 'G-YOUR_ID'),
    </script>
<?php }
  1. Save Your Changes After adding the code, click the "Update File" button. This function will now inject your Google Analytics script into the <head> section of every page on your site.

Option B: Adding Code to header.php

Another manual method is to paste the tracking code directly into your theme's header.php file. This is a bit more direct but is considered less optimal than the functions.php method because you are modifying a core template file.

Again, you must do this in a child theme to avoid your changes being lost.

  1. Copy Your Global Site Tag Go to your Google Analytics tab and copy the entire Global Site Tag snippet.
  2. Navigate to the Theme File Editor In WordPress, go to Appearance > Theme File Editor.
  3. Locate Your header.php File Ensure your child theme is selected, and find and click on the "Theme Header" (header.php) file in the file list on the right.
  4. Paste the Code Scroll through the file until you find the closing </head> tag. Paste your entire Google Analytics tracking script on the line just before the </head> tag.
  5. Update the File Click "Update File" to save your changes.

How to Check if Google Analytics Is Working

After installing your tracking code, you should verify it’s functioning correctly. Here are two easy ways to check:

1. Use the Real-Time Report

This is the quickest and most reliable method. Log in to your Google Analytics account. In the left-hand navigation, go to Reports > Real-time. Then, open your website in a different browser window or on your phone. In a minute or so, you should see "1" appear under "Users in last 30 minutes". You may also see your location pop up on the map. If you see activity, your tracking code is working!

2. View Your Page Source Code

Open your website in a browser (like Chrome or Firefox). Right-click anywhere on the page and select "View Page Source". This opens a new tab with your website's HTML code. Press Ctrl+F (on Windows) or Cmd+F (on Mac) to open the search box, and search for "gtag.js" or your unique Measurement ID (e.g., "G-XXXXXXXXXX"). If the script appears in the code, it has been successfully added to your site.

A Note on Caching Plugins

If you use a caching plugin on your WordPress site (like WP Rocket, W3 Total Cache, etc.), you may need to clear your cache after adding the tracking code. If you check Real-time reports and don't see any activity, this should be your first troubleshooting step. Clearing the cache ensures that the latest version of your website - with the new tracking script included - is being served to visitors.

Final Thoughts

Getting Google Analytics data from your WordPress site is foundational to understanding your visitors, yet it's only the first step. By using a plugin like Site Kit, you can add your tracking code in minutes without any risk, while manual methods using a child theme offer a plugin-free alternative for more experienced users. Now, you can begin tracking how users find you and what content they love most.

Once your tracking is set up, the real work begins: turning all that website data, along with data from your other tools like Facebook Ads, HubSpot, or Shopify, into actionable insights. Very quickly, you can find yourself spending hours logging into a dozen different platforms just to build a simple report. We built Graphed to solve this problem by connecting to all your marketing and sales data sources instantly. You can ask for dashboards in plain English, like "Show me a report comparing blog traffic from Google Analytics vs leads generated in HubSpot by landing page this month," and get a live, always-updated dashboard in seconds - no more manual CSV exports and spreadsheet wrangling required.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.