Data streams are where Google Analytics 4 collects your data. No stream, no data—it's that simple. We'll walk you through creating one, installing the measurement code, and verifying that events are flowing.
Creating Your Data Stream
A data stream is your connection point between GA4 and your website or app. Creating one gives you a Measurement ID that you'll install on every page.
Step 1: Navigate to Data Streams in Admin
Open GA4 and go to Admin (bottom left). Click Data Streams. You'll see any existing streams listed. Click Add stream to create a new one.
Step 2: Choose Your Platform and Configure
Select Web (iOS and Android have their own flows). Enter your website URL and give the stream a descriptive name—something like 'Production' or 'Main Site' that you'll recognize later.
Step 3: Copy Your Measurement ID
GA4 generates your Measurement ID immediately (format: G-XXXXXXXXXX). This is what you'll reference in your code. Store it safely—you need it every time you instrument a new page or app.
// Your Measurement ID from the data stream
const MEASUREMENT_ID = 'G-XXXXXXXXXX';
// This gets passed to gtag.js in the next sectionInstalling the Global Measurement Tag
Install gtag.js on your site to start sending data to your stream. This JavaScript library loads on every page and watches for events.
Step 1: Add the gtag.js Snippet to Your Head Tag
Paste this into the <head> section of your site (or your shared header template). Replace G-XXXXXXXXXX with your actual Measurement ID. Load this as high as possible in your <head> so GA4 catches events early.
<!-- Add to <head> tag on all pages -->
<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>Step 2: Check Real-Time Data
Visit your website in a browser. Open GA4 and navigate to Real-time. Within 5–10 seconds, you should see your session appear. If it shows up, data is being collected.
Step 3: Enable Enhanced Measurement (Optional)
Go to Admin > Data Streams > [Your Stream] > Enhanced measurement. Enable any events you want automatically tracked—File downloads, Video engagement, Outbound clicks, Site search. GA4 captures these without any additional code.
// Enhanced measurement events are sent automatically by GA4
// For example, outbound clicks are tracked without code like this:
// gtag('event', 'click', {
// 'link_url': 'https://external.com',
// 'link_domain': 'external.com'
// });
// This happens automatically when enhanced measurement is enabled.Tracking Custom Events and User Properties
Page views are a start, but you'll want to track actions specific to your business—purchases, signups, form completions. Send these as custom events tied to user properties.
Step 1: Send a Custom Event
Use gtag('event', 'name', {...}) to track any action. Include event parameters that describe what happened. Common examples: a signup with the signup method, a purchase with amount and item details.
// Track a signup
gtag('event', 'sign_up', {
'method': 'email',
'signup_type': 'free_trial'
});
// Track a purchase
gtag('event', 'purchase', {
'currency': 'USD',
'value': 99.99,
'items': [{
'item_id': 'SKU_123',
'item_name': 'Product Name',
'quantity': 1,
'price': 99.99
}]
});
// Track any custom action
gtag('event', 'form_submit', {
'form_name': 'contact',
'form_id': 'contact_123'
});Step 2: Set User Properties for Segmentation
User properties let you segment by who someone is—plan tier, company size, role, cohort. Set them once and GA4 adds them to all subsequent events from that user. This is powerful for retention and revenue analysis.
// Set user properties
gtag('set', {
'user_id': 'user_12345',
'plan_type': 'enterprise',
'company_size': 'large'
});
// Or set a single property
gtag('set', {'plan_tier': 'pro'});
// These properties persist across all future events from this usersign_up not sign up). Invalid names are silently dropped—use Real-time to verify your events are arriving.Common Pitfalls
- Forgetting to replace the placeholder
G-XXXXXXXXXXwith your real Measurement ID. Your site loads fine but no data reaches GA4. - Installing gtag.js on only some pages. Every page you want to track needs the snippet. Missing a critical page means missing all its events.
- Not using Real-time to debug during setup. Wait 24+ hours for reports to populate, but Real-time shows data within seconds. Use it to verify immediately after deploying.
- Creating event names longer than 40 characters or with invalid characters (spaces, special chars). GA4 silently drops these, and you won't know until you check Real-time and they're missing.
Wrapping Up
You now have a data stream collecting events from your website. Start simple with page views and essential user properties, then add custom events as you identify what matters to your business. If you want to track this automatically across tools, Product Analyst can help.