Sub topic 2
Find and understand the Measurement ID
This chapter assumes you have a Google account, can open the Google Analytics Admin area, and know that a script tag in a page's head loads code. It also assumes you have created a GA4 property and a web data stream, as covered in the previous chapter. Here you will locate the Measurement ID, learn what it identifies, and learn how to avoid the common mistakes people make with it.
What the Measurement ID is
The Measurement ID is a string that tells Google where to send the data a page collects. It looks like G-XXXXXXXXXX: the letter G, a hyphen, and a run of uppercase letters and digits. Each web data stream has exactly one Measurement ID.
When the Google tag runs in a browser, it adds this ID to every hit it sends. Google's collection servers read the ID and route the hit to the matching data stream, and so to the matching property. The ID works like a mailing address for the data. It does not prove who sent the data, and it does not grant any access to your reports.
The prefix G- marks the ID as belonging to a GA4 web stream. Other Google products use other prefixes, so the prefix helps you spot a wrong ID quickly.
| Prefix | Belongs to | Example use |
|---|---|---|
| `G-` | GA4 web data stream | Google tag, plugins, Tag Manager |
| `UA-` | Universal Analytics property (retired) | Old tags that no longer collect data |
| `GTM-` | Google Tag Manager container | The Tag Manager snippet |
| `AW-` | Google Ads account | Conversion tracking and remarketing |
If you paste a UA- ID into a tag, no data reaches GA4. If you paste a GTM- ID where a G- ID is expected, the same thing happens.
Where the ID sits in the hierarchy
An account contains properties. A property contains data streams. A web data stream has one Measurement ID. The ID therefore identifies a stream, not a property and not an account.
The property also has a numeric Property ID and, for app streams, a Firebase App ID. The Property ID is used for the Data API and for some third-party connectors. It is not the same thing as the Measurement ID, and tools that ask for one will not accept the other.
One property can hold several streams, for example one web stream and one Android stream. Each stream has its own identifier. Two sites that share one web stream also share one Measurement ID, and their data is combined in a single property. Whether to combine them is a design decision. It is covered in later chapters on property structure and data filtering, but remember here that the ID you choose to install decides where the data lands.
Find the Measurement ID in the Admin area
You need at least the Viewer role on the property to see the ID. To change stream settings, you need Editor or higher.
- Sign in to Google Analytics and open the account and property you want.
- Select Admin (the gear icon at the bottom left).
- In the Property column, select Data streams.
- Select the web data stream by name. A details panel opens.
- Find Measurement ID at the top right of the panel. Use the copy icon next to it to copy the value.
The same panel shows the stream name, the stream URL, and the Enhanced measurement switch. It also has Configure tag settings under Google tag, which you will use in later chapters.
Some accounts arrive at the same panel from the setup flow. If you just created the stream, the "Web stream details" screen appears right away and shows the ID.
Find the Google tag ID from the tag setup screen
The same stream details panel contains View tag instructions. This screen offers installation guidance for several methods. Under the manual option, it shows the full Google tag snippet with your Measurement ID already filled in.
You can copy the snippet from this screen instead of editing the placeholder yourself. This avoids typing errors. The snippet from the screen has the same structure as the standard one:
<!-- 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>The Measurement ID appears twice. The first time is in the src URL of the loader script, as ?id=G-XXXXXXXXXX. The second is in the gtag('config', ...) call. Both must hold the same value. Replacing only one of them is a frequent mistake, and it produces confusing results.
Here is what happens in each case:
- If the
srcID is wrong or missing, the loader fetches the wrong configuration, or none at all. The tag may not run correctly. - If the
configID is wrong, the tag runs but sends data to the wrong stream, or to nowhere. - If both are wrong but valid for another stream, data silently goes to that other stream.
The last case is the hardest to notice because nothing looks broken. Your reports stay empty while another property receives your traffic.
Using the ID in each installation method
Each installation method asks for the ID in a different place. The ID itself does not change.
| Method | Where the ID goes |
|---|---|
| Manual snippet | In the `src` URL and in `gtag('config', ...)` |
| Platform integration | In a settings field, often labeled "Measurement ID" or "Google Analytics ID" |
| Google Tag Manager | In the **Tag ID** field of a Google tag, inside the container |
For platform integrations, check the label carefully. Some platforms still show a field that expects an old UA- ID, and others accept only G- IDs. Some platforms also ask for the Property ID or a connection through your Google account instead of a pasted ID. Follow the platform's own instructions for the exact field. The later chapters on each method go through them in detail.
In Google Tag Manager, the Google tag takes the Measurement ID as its Tag ID. A Tag Manager container has its own GTM- ID, which is a different value that goes in the container snippet on your pages. Mixing up these two IDs is a common error. Keep the roles clear:
- The
GTM-ID loads the container on your page. - The
G-ID, entered in the Google tag inside the container, tells that tag which stream to use.
Is the Measurement ID a secret?
No. The Measurement ID appears in your page source, so anyone can read it by viewing the page. Treat it as public information, in the same way as a site's public URL.
That has a practical consequence. Anyone can send fake hits to your stream by using your ID, and this is sometimes called ghost spam or referral spam. Knowing the ID does not let anyone read your data, change settings, or sign in to your account. It only lets them send data to your stream.
To limit the effect of junk hits:
- Use internal traffic and data filters, covered in later chapters, to exclude unwanted data.
- Review your reports for unexpected hostnames. A hostname that is not one of your own sites usually points to spoofed or copied traffic.
- Use the Measurement Protocol API secret only on servers. Unlike the Measurement ID, the API secret is intended to be private. It authorizes server-to-server hits and should never be placed in page code.
Separate IDs for separate environments
A single ID per site is simple, but a development or staging site that uses the production ID will pollute production reports. Test visits, QA clicks, and automated test runs all count as real traffic.
The common solution is one of these:
- Create a separate property and web stream for staging, with its own Measurement ID. Use that ID on the staging site only.
- Use one stream and configure the tag to load only on the production hostname.
- Use one stream and add a data filter that marks traffic from the test hostname as internal or developer traffic.
Option 1 gives the cleanest separation. The cost is a second property to maintain. Option 2 is easy to do when the ID comes from a build setting or an environment variable. A small example of option 2 is shown below. It builds the loader only on the production host.
<script>
(function () {
var measurementId = 'G-XXXXXXXXXX';
if (location.hostname !== 'www.example.com') {
return;
}
var loader = document.createElement('script');
loader.async = true;
loader.src = 'https://www.googletagmanager.com/gtag/js?id=' + measurementId;
document.head.appendChild(loader);
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', measurementId);
})();
</script>Replace www.example.com with your production hostname and G-XXXXXXXXXX with your own ID. On any other hostname, nothing loads and nothing is sent. Keep in mind that this check runs in the browser, so it is a convenience for keeping data clean and not a security control.
Changing or moving an ID
The Measurement ID of an existing stream does not change. If you want a different ID, you create a new stream, which generates a new ID. Then you replace the old ID in your tag or integration.
Keep these points in mind when you replace an ID:
- Data already collected stays in the old stream. It does not move to the new one.
- The new stream starts with no history, so comparisons across the switch need both properties or both streams.
- Deleting a stream removes its ID. Tags that still use it will keep sending hits to nowhere.
Because of the cost, choose the property and stream structure carefully before you roll the ID out to many pages.
Common mistakes with the Measurement ID
| Mistake | Symptom | Fix |
|---|---|---|
| Using a `UA-` ID | No data in GA4 | Replace with the `G-` ID from the web stream |
| Using the `GTM-` ID in the Google tag | No data in GA4 | Put the `G-` ID in the tag, and the `GTM-` ID in the container snippet |
| Changing only one of the two IDs in the snippet | Missing or misrouted data | Update both the `src` URL and the `config` call |
| Copying the ID from the wrong property | Data appears in another property | Check the property name in the Admin header before copying |
| Leaving a placeholder such as `G-XXXXXXXXXX` | No data | Replace the placeholder with the real value |
| Adding extra spaces or a trailing character | No data | Paste the ID again, with no surrounding whitespace |
| Using the staging ID on production | Test data mixes in with real data | Use separate IDs or a hostname check |
A quick way to confirm that an ID is correct is to open your site, view the page source, and search for G-. Compare the value you find with the one shown in the stream details panel. The later chapter on verification shows how to confirm it with Realtime, Tag Assistant, and DebugView.
Summary of key points
- The Measurement ID (
G-followed by characters) identifies one web data stream. - You find it in Admin, then Data streams, then the stream details panel.
- The manual snippet contains it twice, and both copies must match.
- Platform integrations and Google Tag Manager take the same ID, but in differently named fields.
- It is public, so plan for junk traffic, and use separate IDs or checks for non-production sites.
- It never changes. A new ID means a new stream with no history.
Exercise
A teammate pastes the Google tag snippet into a site. They change the ID in the gtag('config', ...) line to the correct G- value, but the src URL still contains G-XXXXXXXXXX. Reports stay empty. Name the problem, and say how you would find the correct value and fix it.
Show answer
The two copies of the Measurement ID do not match, and the loader URL still holds the placeholder. Open Admin, then Data streams, and select the web stream. Copy the Measurement ID from the details panel (or copy the full snippet from View tag instructions). Replace the placeholder in the src URL with the same value used in the config call. Then check the page source for G- to confirm that both IDs are identical.
Exercise
You manage a production site and a staging site, and you want staging test visits kept out of production reports. Give two ways to do this, and state one trade-off of each.
Show answer
One way is to create a separate property and web stream for staging and use its own Measurement ID there. This gives the cleanest separation, but you must maintain a second property. Another way is to keep one stream and load the tag only when the hostname matches the production site. This is simple and needs no second property, but it runs in the browser, so it only keeps data clean and is not a security control. A third option, a data filter on the test hostname, also works, but the test hits are still collected and must be filtered or flagged.
Exercise
Is the Measurement ID a secret? Explain what someone can and cannot do with it.
Show answer
No. It is visible in the page source of any site that uses it. With it, someone can send fake hits to your stream. They cannot read your reports, change settings, or sign in to your account. The Measurement Protocol API secret is different and must stay private.