How to Get a Google Analytics Code

Cody Schneider8 min read

To start understanding your website visitors, you need to add a Google Analytics tracking code to your site. This short snippet of code is the key to unlocking valuable data about your traffic, but finding it isn't always obvious. This guide will show you exactly where to find your tracking code for a brand-new or existing Google Analytics 4 account, where to place it on your site, and how to make sure it's working correctly.

What Exactly Is a Google Analytics Code?

The Google Analytics code is a unique piece of JavaScript that you install on your website. When a visitor lands on a page, this script runs in their browser, collecting anonymous information about their session and sending it back to your Google Analytics account. It’s what powers all the reports you see, from page views and session duration to user demographics and traffic sources.

With the shift from the old Universal Analytics to the new Google Analytics 4, the terminology has changed slightly. You'll likely encounter two main types of identifiers:

  • Measurement ID: This is the modern standard. It starts with "G-" followed by a series of letters and numbers (e.g., G-XYZ123ABC). If you're setting up a new account, this is the one you’ll be working with. It's associated with a full Javascript snippet called the Google tag (gtag.js).
  • Tracking ID (Universal Analytics): This is the identifier from the previous generation of Google Analytics. It always starts with "UA-" (e.g., UA-1234567-1). While Google stopped processing data for standard UA properties in July 2023, you might still need to find this ID if you're working with an older website or an integration that hasn't fully updated to GA4.

For the rest of this guide, we'll focus primarily on finding the GA4 Measurement ID and its corresponding code, as this is what you’ll need for any new setup.

Setting Up a New Google Analytics 4 Account

If you're starting from scratch, you first need to create a Google Analytics account. This process will guide you right to the tracking code you need.

Step 1: Go to the Google Analytics Website

Head over to the Google Analytics homepage and sign in with your Google account. If it's your first time, you’ll be prompted to start the setup process.

Step 2: Create Your Account

Click "Start measuring." The first screen will ask for an Account name. This is typically your business name or organization.

Step 3: Create a Property

A "property" represents your website or app. Here you'll enter:

  • Property name: Usually your website’s name (e.g., "My Awesome Blog").
  • Reporting time zone &amp, Currency: Select the options that best match your business operations. This ensures that your daily reports align with your calendar and financial data is displayed correctly.

Step 4: Answer Business Questions

Google will ask for some optional details about your industry category and business size. This helps them provide more relevant benchmarking data. You'll also be asked to select your business objectives (e.g., "Generate leads" or "Drive online sales").

Step 5: Set Up a Data Stream

This is the most important step for getting your code. A "data stream" is simply the source of data flowing into your GA4 property. You’ll be asked to choose a platform. For a website, click "Web".

You’ll then need to enter your website's URL and give the stream a name (the default, your website name, is usually fine). Make sure "Enhanced measurement" is turned on, this automatically tracks things like clicks, scrolls, and video views without any extra setup.

Step 6: Find Your Code

After clicking "Create stream," you'll be taken to the "Web stream details" page. Here it is! You'll see your Measurement ID (starting with "G-") in the top right. Below that, under the "Install your Google tag" section, you’ll find the full JavaScript snippet. This is the complete code you need to copy.

<!-- 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>

Keep this tab open as we'll cover where to paste this code shortly.

Finding Your GA4 Code in an Existing Account

Already have a GA4 property but can't find that code snippet again? Don't worry, it's just a few clicks away.

  1. Log in to Google Analytics.
  2. Click the Admin gear icon in the bottom-left corner of the page.
  3. In the "Property" column, make sure the correct GA4 property is selected.
  4. Click on Data Streams.
  5. Select the web data stream you want to track (most businesses will only have one here).
  6. This brings you back to the "Web stream details" page. Your Measurement ID ("G-...") is in the top right. To get the full code, click View tag instructions and select the "Install manually" tab.

From there, you can copy the full JavaScript snippet just like in a new setup.

What If I Still Need My Old Universal Analytics ID?

If you're still working with old systems that require a "UA-" tracking ID, you can find it in your Universal Analytics property (as long as you had one set up before).

  1. Navigate to the Admin section.
  2. In the "Property" dropdown menu, choose your Universal Analytics property. Its name will likely have a "UA-" prefix.
  3. Under the "Property" column, click Tracking Info.
  4. Click Tracking Code. The next page will display your UA Tracking ID and the corresponding code snippet.

How to Install Your Google Analytics Code

Now that you have your code, you need to get it onto your website. The goal is to make sure the script is present on every single page you want to track. The best method depends on how your website is built.

Method 1: Using a CMS or Website Builder Integration

This is the easiest and most common route. Most website platforms like WordPress, Shopify, Squarespace, and Wix have built-in features for Google Analytics.

They simplify the process so you don't have to touch any code files. Instead of pasting the entire script, you usually just need to copy your Measurement ID (the one starting with "G-") and paste it into a designated field in your website’s settings.

  • For WordPress: You can use a plugin like "GA Google Analytics" or check your theme's settings. The plugin will provide a specific field to paste your "G-" ID.
  • For Shopify: Under Online Store » Preferences, there is a dedicated "Google Analytics" section where you paste your Measurement ID.
  • For Squarespace: Go to Settings » Code Injection and paste your full tracking script into the Header field.

Method 2: Manually Adding the Code to Your Site Files

If you have a custom-built website, you'll need to add the code directly to your site’s files. The Google tag needs to be placed just after the opening <head> tag on every page.

If your website uses a common header template file (like header.php in a classic WordPress theme), you can simply add the code once in that file, and it will appear across your entire site. Be careful when editing theme files, as a mistake could break your site. If you're not comfortable with this, the plugin method is much safer.

Method 3: Using Google Tag Manager

For those managing multiple tracking scripts (like Facebook Pixel, Google Ads conversion tags, etc.), Google Tag Manager (GTM) is the most powerful and organized solution.

With GTM, you install the Tag Manager script on your site once. Then, you add your Google Analytics tag (and all other tags) from within the GTM interface. This keeps your site code clean and allows you to manage all your tracking snippets from one central dashboard without ever needing a developer.

How to Verify Your Installation is Working

Once the code is installed, you should confirm it's collecting data. The easiest way is with Google Analytics' own Realtime report.

  1. Install the GA code on your website and save the changes.
  2. Log in to your Google Analytics account.
  3. On the left navigation pane, go to Reports » Realtime.
  4. Open your website in a different browser tab or on your phone.

Within a minute or two, you should see your visit appear in the Realtime report. If you see activity - congratulations, your tracking code is working!

Final Thoughts

Getting your Google Analytics code and installing it on your site is the essential first step to data-driven decision-making. You now know how to create a new GA4 account, find the Measurement ID and code snippet, and add it to your website so you can start gathering valuable traffic data.

Once that data starts pouring in, the next challenge is making sense of it. Instead of getting lost inside the dozens of complex reports in Google Analytics, we built Graphed to make getting insights easy. Simply connect your Google Analytics account, and you can start asking questions in plain English like, "Which landing pages are performing best?" or "Create a dashboard showing my traffic sources this month." We turn your data into clear answers and visualizations instantly, so you can spend less time searching for reports and more time acting on what they tell you.

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.