How to Get Tracking Code in Google Analytics

Cody Schneider8 min read

You’ve started your Google Analytics account, you've clicked around the dashboard, but you're hitting a wall. Your reports are empty, and GA insists that it isn't receiving any data from your website. This is an incredibly common roadblock, and the solution is almost always the same: your Google Analytics tracking code isn't installed. This article is your step-by-step guide to finding that all-important code snippet and getting it onto your site so you can start collecting data.

First, What Is a Google Analytics Tracking Code?

Before we go hunting for it, let's quickly clarify what this code actually is. The Google Analytics tracking code is a small piece of JavaScript that you place on your website. When a user visits a page, this script runs in their browser and sends key information back to Google Analytics - things like which page they're on, what device they're using, and where they came from.

Without this code, your website and your Google Analytics account can't talk to each other. It’s the critical link that makes all of your website reporting possible.

There Are Two Versions: GA4 and Universal Analytics

You'll hear two terms thrown around: Google Analytics 4 and Universal Analytics (UA). GA4 is the current version, and all new properties are created with it. It uses a Measurement ID that looks like this: G-XXXXXXXXXX.

Universal Analytics is the older, now-retired version. While it no longer processes new data, you might still run across it on older websites or in tutorials. It used a Tracking ID that looks like this: UA-XXXXXXXXX-X. This guide will show you where to find the code for both, focusing primarily on the modern GA4 setup.

How to Find Your Google Analytics 4 Tracking Code

Finding your code in GA4 involves navigating to your "Data Stream" settings. This sounds technical, but it’s just a few simple clicks. A data stream is essentially the source of data for your reports - in this case, your website.

Here’s the exact process:

  1. Log in to your Google Analytics account.
  2. In the bottom-left corner, click on the Admin gear icon. This will take you to the settings backend.
  3. You'll see two columns: Account and Property. Make sure you have the correct account and property selected for the website you want to track.
  4. In the Property column, click on Data Streams.
  5. You should see your website listed as a data stream. Click on it.
  6. A new panel will appear with details about that stream. Look for the "Web stream details" section, and you'll find your Measurement ID (starting with "G-"). This is the ID you'll use for many plugins and integrations.
  7. To get the full code snippet, scroll down to the "Install your Google tag" section and click View tag instructions.
  8. Finally, in the new screen, click the Install manually tab. This is where you'll find the complete JavaScript tracking code.

Here’s what the GA4 tracking script, also called the Global Site Tag (gtag.js), looks like:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [],
  function gtag(){dataLayer.push(arguments),}
  gtag('js', new Date()),

  gtag('config', 'G-XXXXXXXXXX'),
</script>

You can use the copy button to grab the entire snippet cleanly.

For Legacy Users: How to Find Your Universal Analytics (UA) Tracking Code

If you're managing an older site or just need to find the historical tracking details, you might need to locate the old Universal Analytics code. The process is similar but uses slightly different menu names.

Note: Universal Analytics stopped processing new data on July 1, 2023. These instructions are for reference only.

  1. Log in to Google Analytics and go to the Admin section.
  2. Select the correct Universal Analytics account and property.
  3. In the Property column, click on Tracking Info, then select Tracking Code from the dropdown menu.
  4. This page will show you both your Tracking ID (starting with "UA-") and the full Global Site Tag that contains it.

Okay, I Have the Code. Now What?

Finding the code is only half the battle. Next, you need to add it to your website so it can start collecting data. The right method depends on your website platform and your comfort level with editing code. Here are the three most common ways to do it.

Method 1: Using a Plugin or Integration (The Easiest Way)

Most modern website builders and Content Management Systems (CMS) have a dedicated spot for your Google Analytics ID. This is the simplest and safest option because you don’t have to touch any code yourself.

  • WordPress: Use a plugin like a dedicated GA integration plugin or an all-in-one SEO tool. These plugins typically create a settings field where you simply paste your GA4 Measurement ID (the one starting with "G-"). The plugin handles placing the full script correctly in your site’s code.
  • Shopify: Shopify has a built-in Google Analytics integration. You just need to go to your Online Store preferences, find the Google Analytics section, and paste your GA4 Measurement ID there.
  • Squarespace and Wix: These platforms also have straightforward marketing or analytics integrations where you can paste your Measurement ID to enable tracking.

Method 2: Manually Adding the Code to Your Site’s HTML

If your site doesn't have an easy integration, or if you prefer having direct control, you can add the script manually. The rule is simple: The entire JavaScript snippet should be pasted just after the opening <head> tag on every single page of your website.

Why after the opening <head> tag? Placing it high up ensures it loads as quickly as possible, giving it the best chance to track every pageview before a user clicks away.

If you have a theme settings file, header.php file, or another template that controls the global header of your site, that’s the perfect place to add it. You only need to add it there once, and it will appear on every page.

Warning: Be very careful when editing your website’s code. A small mistake can break your site's layout or functionality. If you’re not comfortable, it’s best to use a plugin or ask a developer for help.

Method 3: Using Google Tag Manager (The Advanced & Recommended Way)

Google Tag Manager (GTM) is a free tool that acts as a central hub for all your tracking scripts, known as "tags." Instead of adding dozens of scripts directly to your website code for analytics, ads, and other tools, you just add one GTM script. Then, you manage all your other tags from within the GTM interface.

While an overkill for a simple blog, it’s a best practice for businesses that plan to run ads or use multiple analytics tools.

The high-level steps are:

  1. Set up a Google Tag Manager account and container for your website.
  2. Install the GTM container script on your website (this is the last time you'll need to edit code!).
  3. Inside GTM, create a new tag. Choose the "Google Analytics: GA4 Configuration" tag type.
  4. In the tag configuration, paste your GA4 Measurement ID.
  5. Set the tag’s "trigger" to fire on "All Pages."
  6. Publish your GTM container, and you're good to go.

How Do I Know if It’s Working?

After you’ve installed the code, you'll naturally want to confirm it’s actually working. No need to wait 24 hours for reports to populate, you can check it instantly.

Go to your Google Analytics property and navigate to Reports > Realtime. Then, open your own website in a different browser tab or on your phone (using cellular data, not your office Wi-Fi, is a good test). Within a minute or two, you should see yourself pop up as an active user on the Realtime report. If you see activity, congratulations - you have successfully installed your tracking code!

If nothing shows up, double-check that you've pasted the correct ID or full script, clear your website's cache, and ensure the code is in the <head> section of your site’s output HTML.

Final Thoughts

Getting your Google Analytics tracking code installed is a foundational step for understanding your website's performance. By following the steps above, you can find your unique tracking ID or code snippet for GA4 and implement it using the method that best fits your platform, whether that’s a simple plugin, manual installation, or Google Tag Manager.

Now that your data is flowing, the real work begins: turning dense dashboards into clear, actionable insights. Instead of spending hours trying to wrangle GA reports, we built Graphed to do the heavy lifting for you. Simply connect your Google Analytics account, and you can start asking questions in plain English, like "show me our top 10 landing pages by sessions" or "create a pie chart of our visitors by country." Graphed instantly builds the exact reports and dashboards you need, saving you from navigating the complexities of standard analytics tools.

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.