Real-time reporting shows what's happening on your site right now—which pages are getting traffic, what events are firing, who's completing conversions. But these insights only surface if you're tracking the right events. We'll walk through sending events that appear in real-time, viewing them in GA4, and querying them programmatically so you can monitor what matters.
Send Events That Appear in Real-Time
Events tracked via gtag.js or the Measurement Protocol appear in GA4's real-time report within 1–2 seconds. No special setup needed—every event you send gets included automatically.
Track events with gtag.js on the client side
Add gtag('event', 'name') calls to your site for button clicks, form submissions, and page views. Each event appears in Real-time > Summary immediately after firing.
// Track a button click event
document.getElementById('subscribe-btn').addEventListener('click', () => {
gtag('event', 'subscribe_click', {
'button_name': 'Subscribe',
'button_location': 'hero_section'
});
});
// Track a form submission
document.getElementById('contact-form').addEventListener('submit', (e) => {
gtag('event', 'form_submit', {
'form_name': 'contact',
'form_destination': '[email protected]'
});
e.preventDefault();
});
// Track an ecommerce purchase
gtag('event', 'purchase', {
'transaction_id': 'T_12345',
'value': 99.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU_123',
'item_name': 'Premium Plan',
'quantity': 1,
'price': 99.99
}]
});Send events from your server with the Measurement Protocol
Track backend events (signups, API calls, database updates) by posting to Google's Measurement Protocol endpoint. These events show in real-time just like client-side events.
// Send a server-side event via Measurement Protocol
const sendGAEvent = async (clientId, eventName, eventParams) => {
const payload = {
client_id: clientId,
events: [{
name: eventName,
params: eventParams
}]
};
try {
await fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${process.env.GA_MEASUREMENT_ID}&api_secret=${process.env.GA_API_SECRET}`, {
method: 'POST',
body: JSON.stringify(payload)
});
console.log(`Event "${eventName}" sent to GA4`);
} catch (error) {
console.error('Failed to send GA4 event:', error);
}
};
// Track a database signup
await sendGAEvent('user-123', 'sign_up', {
'sign_up_method': 'email',
'user_role': 'analyst'
});View and Filter Real-Time Data in GA4
Once events are flowing, the Real-time report shows them as they happen. You can filter by event type, add dimensions, and segment by user properties.
Open the Real-time report
In your GA4 property, navigate to Reports > Real-time on the left sidebar. You'll see Active users and event counts updating every few seconds.
Add custom dimensions to segment real-time data
Click Add dimension to slice by custom properties. For example, add page_title to see which pages are trending, or add user_role if you track it as a custom dimension.
// Set custom dimensions in gtag config
gtag('config', 'G-XXXXXX', {
'user_id': 'user-456',
'custom_map': {
'dimension1': 'user_role',
'dimension2': 'subscription_tier'
}
});
// Track events with these dimensions
gtag('event', 'purchase', {
'user_role': 'premium_member',
'subscription_tier': 'enterprise',
'value': 499.99,
'currency': 'USD'
});Filter real-time events by name
Click the Event name dropdown to focus on specific events like purchase, form_submit, or subscribe_click. This narrows the view to only the events you're monitoring.
Query Real-Time Data Programmatically
For dashboards or alerts, query the real-time report via the Google Analytics Data API. You can poll every 5–10 seconds to build custom monitoring systems.
Create a service account and authenticate
Create a service account in Google Cloud, grant it Viewer access to your GA4 property, and download the JSON key. Use this to authenticate Data API requests.
Query the real-time report with the Data API
Use the runRealtimeReport method to fetch active users, event counts, and custom dimensions. Real-time queries only support a subset of metrics and dimensions—no date ranges or filters.
const {BetaAnalyticsDataClient} = require('@google-analytics/data');
const client = new BetaAnalyticsDataClient();
const runRealtimeReport = async (propertyId) => {
const response = await client.runRealtimeReport({
property: `properties/${propertyId}`,
metrics: [
{name: 'activeUsers'},
{name: 'newUsers'},
{name: 'eventCount'}
],
dimensions: [
{name: 'pageTitle'},
{name: 'city'},
{name: 'eventName'}
],
limit: 10
});
console.log('Active users:', response[0].totals[0].values[0]);
console.log('Real-time rows:', response[0].rows);
return response[0];
};
await runRealtimeReport('123456789');Common Pitfalls
- Assuming all events show in real-time—only events from the last 30 minutes appear, and older ones disappear from the real-time report entirely.
- Forgetting to send custom dimensions upfront; real-time filtering is limited, so track the user properties and event attributes you'll need right away.
- Polling the real-time API too frequently and hitting rate limits; GA4 allows 1 request per second per property, so throttle to every 5–10 seconds.
- Relying on real-time data for revenue accuracy—real-time can be 2–5 seconds behind, so same-hour totals may drift from final reports.
Wrapping Up
Real-time tracking in GA4 comes down to sending events via gtag.js or Measurement Protocol and viewing them in the Real-time report or Data API. Expect 1–2 second latency, not zero. Real-time works best for spotting traffic spikes and debugging conversion issues, not millisecond-precision analysis. If you want to track this automatically across tools, Product Analyst can help.