Knowing how many users are actively on your site right now matters—especially when you're debugging a launch or running a campaign. GA4 gives you active user metrics in multiple places, but finding the right view depends on what you're trying to answer: are you checking real-time traffic, or do you need historical trends?
Viewing Active Users in the GA4 Dashboard
The fastest way to see active users is through GA4's built-in dashboards and real-time reporting.
Step 1: Open the Real-time Report
In your GA4 property, go to Reports > Real-time. You'll see a card labeled Active users right now at the top—this updates every few seconds and shows concurrent users currently on your site. This is your single-number pulse check.
Step 2: Add Active Users to Custom Reports
For historical trends, navigate to Reports > Engagement > Overview or create a custom report by clicking Explore > Blank. Drag Active users from the Metrics panel into your report canvas. Pair it with dimensions like Date, Device, or Country to see patterns over time.
Step 3: Query Real-time Active Users Programmatically
If you want to check active users in code (for dashboards or alerts), use the Google Analytics Data API's Realtime endpoint. Authenticate with a service account and call runRealtimeReport to get concurrent user counts.
const {google} = require('googleapis');
const analyticsdata = google.analyticsdata('v1beta');
async function getRealtimeActiveUsers(propertyId) {
const response = await analyticsdata.properties.runRealtimeReport({
property: `properties/${propertyId}`,
requestBody: {
metrics: [{name: 'activeUsers'}]
}
}, {
auth: new google.auth.GoogleAuth({
keyFile: './service-account-key.json',
scopes: ['https://www.googleapis.com/auth/analytics.readonly']
})
});
const activeUsers = response.data.totals[0].values[0];
console.log(`Active users right now: ${activeUsers}`);
return activeUsers;
}
getRealtimeActiveUsers('123456789');Visualizing Active Users Trends with the Data API
For deeper analysis—like comparing active users across time periods or by device type—pull historical data via the Data API and chart it.
Step 1: Set Up Authentication
Create a service account in your Google Cloud project and download the JSON key. Install the Google Analytics Data API client: npm install @google-analytics/data. This gives you programmatic access to your GA4 property without manual exports.
const {BetaAnalyticsDataClient} = require('@google-analytics/data');
const client = new BetaAnalyticsDataClient({
keyFilename: './service-account-key.json'
});Step 2: Query Active Users by Date
Use runReport to fetch active users grouped by date. Specify your date range (e.g., last 30 days) and slice by dimensions like Device category or User default channel group to see where traffic comes from.
async function getActiveUsersTrend(propertyId) {
const [response] = await client.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: '30daysAgo',
endDate: 'today'
}
],
metrics: [
{name: 'activeUsers'}
],
dimensions: [
{name: 'date'},
{name: 'deviceCategory'}
],
orderBys: [
{
dimension: {name: 'date'},
desc: false
}
]
});
response.rows.forEach(row => {
const date = row.dimensions[0];
const device = row.dimensions[1];
const activeUsers = row.metrics[0].value;
console.log(`${date} (${device}): ${activeUsers}`);
});
}
getActiveUsersTrend('123456789');Step 3: Visualize with a Charting Library
Pipe the API response into Chart.js or D3.js. Plot date on the x-axis and active users on the y-axis. This gives you a quick visual of traffic patterns and helps spot dips or spikes during campaigns.
// Transform GA4 API response into Chart.js format
const chartData = {
labels: response.rows.map(row => row.dimensions[0]),
datasets: [
{
label: 'Active Users',
data: response.rows.map(row => row.metrics[0].value),
borderColor: '#171717',
backgroundColor: 'rgba(23, 23, 23, 0.05)',
fill: true,
tension: 0.3
}
]
};
const ctx = document.getElementById('activeUsersChart').getContext('2d');
new Chart(ctx, {
type: 'line',
data: chartData,
options: {
responsive: true,
plugins: {
title: {text: 'Active Users (Last 30 Days)'}
},
scales: {
y: {beginAtZero: true}
}
}
});runRealtimeReport for live numbers and the standard runReport for finalized, historical data.Filtering Active Users by Segment
Sometimes you only care about active users in a specific segment—logged-in users, premium customers, or a specific region.
Step 1: Define Custom User Properties
Set custom user properties via gtag to tag users as they arrive (e.g., user tier, account status). This makes segmenting active users cleaner than event-based filters.
// Set a custom user property when user signs in
gtag('set', {'user_properties': {
'subscription_tier': 'premium',
'account_age_days': 120
}});Step 2: Query Active Users with Segment Filters
Use runReport with a dimensionFilter to drill down by your custom properties. This tells you how many of your target users are currently active.
async function getActiveUsersBySegment(propertyId) {
const [response] = await client.runReport({
property: `properties/${propertyId}`,
dateRanges: [{startDate: 'today', endDate: 'today'}],
metrics: [{name: 'activeUsers'}],
dimensions: [{name: 'date'}],
dimensionFilter: {
filter: {
fieldName: 'customUser:subscription_tier',
stringFilter: {
matchType: 'EXACT',
value: 'premium'
}
}
}
});
const activeUsers = response.rows[0].metrics[0].value;
console.log(`Active premium users today: ${activeUsers}`);
}
getActiveUsersBySegment('123456789');Common Pitfalls
- Confusing active users (distinct users with at least one session in the last 24 hours) with concurrent users (users online right now). The real-time report shows concurrent; the reporting API shows active. Both are useful—just know which you're reading.
- Pulling today's active user data via
runReportand wondering why it's incomplete. GA4 finalizes data with a ~24-hour lag. For up-to-the-minute counts, always userunRealtimeReport. - Creating a new segment or audience in GA4 and expecting it to apply to historical data. Segments only count sessions *after* they're created. You'll see zero active users in new segments even though the setup is correct.
- Forgetting to include at least one metric (like active users) in your API call. GA4's
runReportrequires both dimensions and metrics. Without metrics, the query will fail.
Wrapping Up
Active user visualization in GA4 is straightforward once you pick the right tool for the job: use the Real-time report for a quick pulse check, build custom reports for trends, and reach for the Data API when you need automation or custom dashboards. Combine this with filtered segments to zoom in on your highest-value user cohorts. If you want to unify active user tracking across all your analytics tools and get a true north dashboard, Product Analyst can help.