Sub topic 2
Creating a Web Data Stream
This chapter assumes you have a GA4 account and property, can edit your site's HTML or use a tag manager or CMS plugin, and know basic HTML.
Creating a web data stream
A data stream connects one website or app to a GA4 property. Each website needs its own web data stream.
- In Admin, select your property, then open Data streams.
- Select Add stream, then Web.
- Enter the site URL, such as
https://www.example.com, and a stream name. - Select Create stream.
Use https:// and a full domain. A mismatched URL is a common source of confusion later.
Finding and understanding the measurement ID
After you create the stream, GA4 displays a measurement ID in the form G-XXXXXXXXXX. The ID tells Google which stream receives events from your pages. You can copy it from the stream details page at any time.
The measurement ID is not a secret. It appears in your page source, so anyone can read it. Treat it as an identifier, not a credential.
Enhanced measurement: automatic events
Enhanced measurement sends common events, such as page_view, scroll, outbound clicks, site search, video engagement, and file downloads, without extra code. Toggle these in the stream's settings. Review the list before launch, because each enabled event adds rows to your reports.
Installing the tag with gtag.js, Tag Manager, or a CMS
The tag is the script that sends data to your stream. Choose one method:
- gtag.js: Paste the snippet into the
<head>of every page. - Google Tag Manager: Add a GA4 Configuration tag with your measurement ID, then publish the container.
- CMS plugin: Enter the measurement ID in the plugin's settings.
The direct gtag.js snippet looks like this:
<!-- 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>Common errors:
| Symptom | Likely cause | Fix |
|---|---|---|
| No data in Realtime | Tag missing or wrong ID | Check page source for `gtag('config', ...)` with your ID |
| Data goes to another property | Copied ID from the wrong stream | Copy the ID from the stream you intend to use |
| Duplicate page views | Tag installed twice, such as gtag.js and a CMS plugin | Keep one installation method |
Exercise
Exercise
You installed the gtag.js snippet, but Realtime shows no visitors. Name two things to check first.
Show answer
Check that the snippet appears in the page's <head> on the live site, and that its measurement ID matches the web data stream's ID exactly.