The Google Analytics 4 API is not one monolithic endpoint. It is a set of three programmatic interfaces, Data API, Admin API, and Measurement Protocol, each designed for a distinct job. The Data API pulls the same report data you see in the GA4 interface. The Admin API lets you automate account and property configuration. The Measurement Protocol sends server-to-server and offline events directly to GA4.
This article covers the differences between these tools, the exact steps to get access, and how to execute your first report. If you later want to query GA4 with natural language, the GA4 MCP server connects AI tools to your property through the Data API.
Which GA4 API Do You Need?
Google Analytics 4 offers three programmatic paths. The first, the Google Analytics Data API v1, returns aggregated report data, exactly what you see in the GA4 web interface. It respects the property’s chosen reporting identity space: Blended, Observed, or Device-based. The second, the Admin API v1, manages configuration objects like accounts, properties, data streams, custom dimensions, and link relationships to Google Ads, Firebase, or BigQuery. The third, the Measurement Protocol, sends HTTP events directly to GA4 servers for server-to-server and offline scenarios.
The Data API and Admin API work only with Google Analytics 4 properties, not legacy Universal Analytics properties. The Measurement Protocol supplements, but never replaces, standard tagging with gtag, Tag Manager, or Firebase. The table below shows the main characteristics of each interface.
| API / Protocol | Primary Use | Key Methods (Data/Admin) or Endpoint |
|---|---|---|
| Data API | Read aggregated reports, pivot tables, realtime data, and (in early preview) funnel reports. | runReport, runRealtimeReport, runPivotReport, runFunnelReport (early preview), batchRunReports, getMetadata |
| Admin API | Create and modify GA4 accounts, properties, data streams, audience definitions (Alpha), and service links. | properties.create, properties.dataStreams.create, properties.googleAdsLinks.create, properties.audiences.create |
| Measurement Protocol | Send offline conversions, kiosk events, or server-side transactions directly into GA4 properties. | Measurement Protocol validation server and production endpoint |
The Data API accesses the same report data as the Google Analytics interface. The Admin API supports features like data retention settings, SKAdNetwork conversion value schemas (Alpha), event create and edit rules (Alpha), and Display & Video 360 advertiser links (Alpha). Realtime reports are available through the Data API’s runRealtimeReport method and cover the last 30 minutes for standard properties, or 60 minutes for Analytics 360 properties.
Getting Access: Cloud Project, Service Account, Property Permission
Before any API call, you need a Google Cloud project with the Analytics Data API (or Admin API) enabled, a service account, and the service account added to your GA4 property. The quickstart process works like this.
- Create or select a Google Cloud project. Then enable the Analytics Data API v1 from the APIs & Services > Library page in the Cloud console. You can search for "Google Analytics Data API" and click Enable.
- Create a service account in that project and download its JSON key. Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto point to that file. The client libraries (Python, Node.js, PHP, Java, .NET, Go) will pick it up automatically. - Copy the service account’s email address, then open your GA4 property. In Admin > Property access management, click the plus icon, choose Add users, paste the email, and assign at least the Viewer role. Without this step, the API returns permission errors.
- Install the client library. For Python, it’s
pip install google-analytics-data. For Node.js,npm install @google-analytics/data. The full list of installation guides is in the Data API quickstart documentation.
You can also authenticate with a user account using OAuth 2.0, but service accounts are preferred for automated scripts. Google's quickstart uses the scopes https://www.googleapis.com/auth/analytics.readonly and cloud-platform when setting up application default credentials with gcloud. Once the API is enabled and the service account has property access, you can confirm the setup with a simple runReport call.
The Data API quotas are tied to the Google Cloud project and the GA4 property, and requests authenticated only with an API key are also subject to them.
Short on time? Analytics Art can check this in your property for you.
Your First Data API Report (RunReport Example)
The runReport method is the main way to pull non-realtime GA4 data. You send a POST request to https://analyticsdata.googleapis.com/v1beta/properties/GA_PROPERTY_ID:runReport with a JSON body that contains dateRanges, dimensions, and metrics.
To find your property ID, open GA4, go to Admin > Property settings, and copy the numeric string under Property ID. It is not the Measurement ID (which starts with G-). The property ID is used in the URL path as properties/123456789.
Here is a minimal request that counts active users by country for the last 7 days (yesterday’s data is recommended to avoid today’s partial data):
POST https://analyticsdata.googleapis.com/v1beta/properties/123456789:runReport
{
"dateRanges": [{ "startDate": "7daysAgo", "endDate": "yesterday" }],
"dimensions": [{ "name": "country" }],
"metrics": [{ "name": "activeUsers" }]
}
The response contains dimensionHeaders, metricHeaders, and rows. Each row has a list of dimensionValues and metricValues. The ordering matches the dimensions and metrics in the request. For example:
{
"dimensionHeaders": [{ "name": "country" }],
"metricHeaders": [{ "name": "activeUsers", "type": "TYPE_INTEGER" }],
"rows": [
{ "dimensionValues": [{ "value": "United States" }], "metricValues": [{ "value": "4820" }] },
{ "dimensionValues": [{ "value": "Japan" }], "metricValues": [{ "value": "2541" }] }
]
}You can test queries interactively in the GA4 Query Explorer before writing code. If your property has very little data, widen the date range to avoid data thresholds. Data thresholds can also apply to API calls, so rows may be withheld when they include demographic data or the counts are too low.
For batching, use batchRunReports to send up to 5 reports in a single HTTP call. Each sub-request consumes quota independently, but it reduces round-trip time.
Realtime, Dimensions, Metrics And Filters
Realtime reports use the runRealtimeReport method. Events appear seconds after they are sent, covering the present moment back to 30 minutes (60 minutes for Analytics 360). The request shape is similar: a RunRealtimeReportRequest with at least one dimension and one metric.
Unlike core reports, realtime supports a more limited set of dimensions and metrics. Check the Realtime API schema for the exact list. Features like pagination, dimension filters, and user properties behave the same in realtime and core reports.
Multiple dimensions can be combined. For example, to get active users by country and city:
POST https://analyticsdata.googleapis.com/v1beta/properties/GA_PROPERTY_ID:runRealtimeReport
{
"dimensions": [{ "name": "country" }, { "name": "city" }],
"metrics": [{ "name": "activeUsers" }]
}
The response groups rows by the unique combination of dimension values. You can add minute ranges to zoom into specific segments of the realtime window. Minute ranges are specified as an array of minuteRange objects, each with a startMinutesAgo and endMinutesAgo. Without minute ranges, the report covers the standard realtime window.
For core reports, the full list of dimensions and metrics is in the API schema documentation. That includes ecommerce parameters, event names, page paths, and all the fields available in the GA4 interface. Filters can be added using the dimensionFilter and metricFilter objects. See the API reference for the supported filter expressions. Complex filter expressions increase token consumption.
Quotas, Tokens And Thresholding
Every Data API request consumes tokens from a set of property-level and project-level quotas. The Core category (runReport, runPivotReport, the batch methods, runAccessReport, getMetadata, checkCompatibility, createAudienceExports) has the following standard limits per property:
| Quota Name | Standard | Analytics 360 |
|---|---|---|
| Core tokens per day | 200,000 | 2,000,000 |
| Core tokens per hour | 40,000 | 400,000 |
| Core tokens per project per property per hour | 14,000 | 140,000 |
| Core concurrent requests | 10 | 50 |
| Core server errors per project per property per hour | 10 | 50 |
Realtime and Funnel have their own buckets with the same limits. Chat has its own bucket: 3,750,000 tokens per day and 500,000 per hour for both standard and 360 properties.
Token cost depends on the number of rows, dimensions, metrics, filter complexity, date range length, and the cardinality of the data. High-cardinality dimensions like pagePath can drive up cost. To see exactly how many tokens a request used, add "returnPropertyQuota": true to the JSON body. The response includes a propertyQuota object with consumed and remaining values for each quota. If any quota bucket reaches zero, subsequent requests to that property fail with 429 RESOURCE_EXHAUSTED.
Google Analytics also applies data thresholds to prevent the inference of individual user demographics or interests. This can hide rows when you include demographic data or search query information and the user count is too low. Properties are allowed 120 potentially thresholded requests per hour. Thresholds are system-defined and cannot be adjusted. To reduce their impact, widen the date range. Note that Analytics does not export Google signals data to BigQuery, so counts there can differ.
Is The GA4 API Free?
Google's documentation describes Data API usage in terms of quotas, measured in tokens, concurrent requests, and server errors, and it does not list a per-request price. Check the current Google Cloud and Google Analytics terms for any charges that apply to your account.
If you exceed a quota, requests fail with a 429 RESOURCE_EXHAUSTED error. To stay within limits, monitor propertyQuota and throttle background jobs when remaining tokens fall low. Batching up to 5 reports in a single batchRunReports call helps reduce HTTP overhead, though each sub-report still counts toward token quotas separately.
For the Measurement Protocol and the Admin API, consult Google's documentation for current limits and any pricing details. For the Data API, Google recommends exponential backoff with retry limits when a request fails with 429, 500, or 503.
Frequently Asked Questions
Does Google Analytics Have An API?
Yes, GA4 offers three APIs: the Data API to read reports, the Admin API to manage account and property settings, and the Measurement Protocol to send events directly from servers or offline devices. The Data API works only with GA4 properties and is not compatible with Universal Analytics.
How Do I Connect To Google Analytics 4 Programmatically?
Enable the Analytics Data API in a Google Cloud project, create a service account, download its JSON key, and add that service account as a user on the GA4 property with at least Viewer role. Then use a client library or REST calls to the runReport endpoint with your numeric property ID.
What Is Replacing Google Analytics?
Google Analytics 4 is the current version of Google Analytics. The Data API and Admin API described here work only with GA4 properties, not legacy Universal Analytics properties.
What Data Can I Get From The GA4 API?
You can pull all standard aggregated metrics like active users, sessions, event counts, conversions, and ecommerce data, broken down by any dimensions available in the GA4 UI, including custom dimensions and user properties. Realtime data is also available for the last 30 minutes (up to 60 minutes for Analytics 360 properties).
Is Google Analytics 100% Accurate?
No. Data thresholds may suppress rows when you include demographic or interest dimensions and user counts are low, to protect privacy. Also, data from different identity spaces (Blended, Observed, Device-based) can differ. The Data API accesses the same report data as the GA4 interface, so thresholding and identity-space differences apply to API results too.
Does Google Analytics Have An App?
Google offers a Google Analytics mobile app, but the APIs discussed here are the programmatic interfaces for developers, not the app itself.
What Are GA4 API Quotas?
Quotas limit the number of tokens you can consume per day and per hour, as well as concurrent requests. Standard properties have 200,000 core tokens per day; Analytics 360 has 2,000,000. You can monitor remaining quotas by setting 'returnPropertyQuota: true' in your API call.
Related GA4 Guides
More in APIs & Integrations or browse all GA4 guides.
Official Documentation Used