Event count is GA4's core metric—it tells you how many times a specific event fired across all your users and sessions. Unlike pageviews (which track page loads), events capture custom user actions: button clicks, purchases, form submissions, video plays, or any action you instrument. If you're reporting on user behavior beyond page navigation, event count is the metric you need. This guide covers three methods to calculate and query event count: the GA4 interface, the Google Analytics Data API, and custom reports.
View Event Count in the GA4 Interface
The quickest way to understand event volume is through GA4's built-in reports. This method requires no code and updates with a ~4 hour delay.
Open the Events Report
Log into your GA4 property and navigate to Reports in the left sidebar. Click Engagement > Events. GA4 displays a table showing every event fired in your property, sorted by Event Count in descending order. This column shows the total number of times each event fired during your selected date range. For example, if you track a purchase event every time someone completes a checkout, the table shows the total number of purchases.
// GA4 tracks events via gtag.js
// Place this tracking code in your website <head> or via Google Tag Manager
// After installation, track events like this:
gtag('event', 'purchase', {
'currency': 'USD',
'value': 99.99,
'items': [
{
'item_id': 'SKU123',
'item_name': 'Widget Pro',
'price': 99.99,
'quantity': 1
}
]
});Apply Date Range and Segments
Use the date picker at the top right to select your reporting window (e.g., last 30 days, last quarter). Apply Segments from the left panel to isolate specific user groups: new users, returning users, iOS users, etc. The event count table updates to show only events matching your filters. This is useful when you need to compare event counts across user cohorts—for instance, do new users click buttons less frequently than returning users?
Drill Down into Event Details
Click any event name in the table to expand it. GA4 shows a breakdown by event dimensions (if applicable). You can add secondary dimensions using the + button—for example, break down purchase events by country or device category to see where most purchases come from. This multi-dimensional view helps identify which segments drive the most events.
Query Event Count Programmatically with the Data API
For automation, real-time data, and deeper analysis, query event counts using the Google Analytics Data API. This method requires a service account and a few lines of JavaScript.
Create a Service Account and Download Credentials
Open Google Cloud Console and create a new service account in your GA4 project. Grant it the Viewer role. Generate a JSON key file and download it—this file authenticates your API requests. Store it securely; never commit it to git. Then, grant this service account access to your GA4 property in Admin > Property Access Management.
// Install the Google Analytics Data API client
// npm install @google-analytics/data
const {BetaAnalyticsDataClient} = require('@google-analytics/data');
const path = require('path');
// Initialize the client with your service account key
const analyticsDataClient = new BetaAnalyticsDataClient({
keyFilename: path.join(__dirname, 'ga4-service-account-key.json')
});
// Your GA4 property ID (find it in Admin > Property Settings)
const propertyId = '123456789';Build a Report Request with eventCount Metric
Call the runReport() method to query event counts. Specify your GA4 property ID, date range, the eventCount metric, and dimensions to break down the data (e.g., eventName to count events by type). The API returns a structured response with rows of data.
const response = await analyticsDataClient.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: '2024-01-01',
endDate: '2024-01-31'
}
],
metrics: [
{
name: 'eventCount' // Total number of events fired
}
],
dimensions: [
{
name: 'eventName' // Break down by event type
}
]
});
console.log('Event count by name:', response[0].rows);Parse Results and Extract Counts
The API response contains an array of rows. Each row has dimensionValues (e.g., the event name) and metricValues (e.g., the event count as a number). Loop through rows to extract counts for specific events or sum them for a total. You can then export to a database, email, or dashboard.
const rows = response[0].rows;
let totalEventCount = 0;
const eventCounts = {};
rows.forEach(row => {
const eventName = row.dimensionValues[0].value; // e.g., 'purchase'
const eventCount = parseInt(row.metricValues[0].value); // e.g., 1250
eventCounts[eventName] = eventCount;
totalEventCount += eventCount;
console.log(`${eventName}: ${eventCount} events`);
});
console.log(`Total events in period: ${totalEventCount}`);Filter for a Specific Event
If you only care about one event (e.g., purchase), add a dimensionFilter to the API request. This reduces query time and network overhead. Filters use GA4's dimension syntax: match the exact eventName value.
const response = await analyticsDataClient.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: '2024-01-01',
endDate: '2024-01-31'
}
],
metrics: [
{
name: 'eventCount'
}
],
dimensionFilter: {
filter: {
fieldName: 'eventName',
stringFilter: {
matchType: 'EXACT',
value: 'purchase'
}
}
}
});
const purchaseCount = parseInt(response[0].rows[0].metricValues[0].value);
console.log(`Total purchases: ${purchaseCount}`);Create Custom Reports for Event Count Analysis
If you prefer a visual, no-code approach, build custom reports directly in GA4. These reports can be saved and shared with your team.
Build and Save a Custom Report
Go to Reports > Library (bottom left sidebar). Click Create custom report. Name it something clear like "Event Counts by Device." Drag eventCount from the Metrics panel into the metric area. Add dimensions like eventName, deviceCategory, or userType to break down counts by these attributes. Click Save to persist the report.
// Custom reports in GA4 are built visually, but you can replicate them via the Data API
const response = await analyticsDataClient.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: '2024-01-01',
endDate: '2024-01-31'
}
],
metrics: [
{
name: 'eventCount'
}
],
dimensions: [
{
name: 'eventName'
},
{
name: 'deviceCategory' // mobile, tablet, or desktop
}
]
});
// Now you have a custom report-like dataset with event counts by name and deviceCommon Pitfalls
- Event count includes all event fires, even duplicates from the same user in the same session. If you need unique occurrences, query
eventCountPerUseror combine withactiveUsersto understand per-user behavior. - Auto-tracked events (e.g., page_view, scroll) are counted alongside your custom events. If you only want custom events, filter by
eventNamein your API query or use a segment in the UI. - GA4's UI shows event counts with ~4 hour latency; the Data API may be slightly faster, but expect a 1-2 hour lag in production. For time-critical analysis, plan accordingly.
- The Data API allows 1,200 queries per day for standard GA4 accounts. If you're building heavy automation, cache results or batch multiple queries into a single API call to stay under the limit.
Wrapping Up
Event count is GA4's fundamental metric for tracking custom user actions—purchases, form submissions, video plays, and beyond. You now know three ways to calculate it: the GA4 interface for quick analysis, the Data API for automation and real-time integration, and custom reports for team dashboards. Each method has trade-offs between speed, accuracy, and ease of use; choose based on your workflow. If you want to track and calculate event counts automatically across GA4 and your other analytics tools in one place, Product Analyst can help.