The GA4 Measurement Protocol sends events straight to Google Analytics servers via HTTPS POST requests. Use it to capture server-to-server transactions, offline conversions, or interactions from devices that can't run gtag or the Firebase SDK.
The protocol supplements your existing data streams; you still need gtag, Tag Manager, or Firebase running on your front end to get full reporting. This guide walks through creating an API secret, building a properly formatted request, validating payloads with the debug endpoint, and understanding the limits you'll hit in production.
What The Measurement Protocol Is For
The Measurement Protocol exists to handle interactions your standard tagging can't reach. While gtag.js, Google Tag Manager, and the Firebase SDK automatically collect page views, clicks, and sessions, they don't cover server-side events like back-end checkouts, CRM status changes, or in-store purchases. The Measurement Protocol fills that gap with a plain HTTP API.
Four clear use cases from the official documentation:
- Tie online to offline behavior. A user browses products on your site, then buys in a physical store. Send the store purchase as a Measurement Protocol event, linked by
client_idoruser_id, and you see the full journey. - Measure client-side and server-side interactions together. Add server-side events to a session that started in the browser by including the same
session_idandclient_id. - Send events that happen outside standard user-interaction, like offline conversions.
- Send events from devices and apps where automatic collection isn't available, such as kiosks and watches.
Google Analytics joins Measurement Protocol events with online data using client_id (for web streams) or app_instance_id (for app streams). This automatically applies the user's privacy settings, like non-personalized ads and ad tracking limits, and pulls in the most recent geographic and device information from the tag-based hits. If you need the event to reflect a specific session's geo or device data, include a session_id and send the event within 24 hours of that session's start.
You must have gtag, Google Tag Manager, or Firebase installed on your property. The Measurement Protocol is not a standalone replacement. When used alone, many reports show partial data, and some automatic features, like remarketing with Google signals, require online tagging as well. Also, rules you set in the GA4 interface to generate or rename events do not fire for Measurement Protocol events; your server code must handle any event modifications itself. For cross-device remarketing, you'll need a user_id in your payload.
Create An API Secret
Before you send a single event, you need an API secret. This string authenticates your Measurement Protocol requests so that GA4 knows they belong to your property. Without it, the endpoint won't process your payload.
Create the secret inside your data stream settings:
- Sign in to Google Analytics and select the account and property that contain your target data stream.
- Click Admin (the gear icon at the bottom left).
- Under Data collection and modification, choose Data streams.
- Select the web or app stream you want to use. For a web stream, you'll see a measurement ID like
G-XXXXXXXX; for an app stream, a Firebase app ID. - Click Measurement Protocol API secrets.
- Click Create. Give the secret a descriptive nickname (for example, "production-server"), then click Create again.
- Copy the Secret value that appears.
The API secret is private to your organisation. Treat it like a password: store it in environment variables or a secure vault, never hard-coded in client-side code. Google recommends rotating secrets periodically to reduce spam risk.
For app streams, you'll also need a firebase_app_id, which identifies the Firebase app itself (separate from the app_instance_id that identifies a specific installation). Find it in the Firebase console under Project settings > General > Your apps. Select your iOS or Android app; the App ID is the value you'll use in the Measurement Protocol URL. For web streams, you use the measurement_id instead.
Short on time? Analytics Art can check this in your property for you.
Build A Request: Client ID, Events And Parameters
To send an event, make an HTTPS POST to the Measurement Protocol endpoint. The URL includes two query parameters: your api_secret and either measurement_id (for web streams) or firebase_app_id (for app streams). If you don't know your measurement ID, see Where To Find Your GA4 Measurement ID.
For a web stream, the request structure looks like this:POST https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXX&api_secret=YOUR_SECRET
The request body must be JSON. Three fields sit at the top level:
client_id(for web) orapp_instance_id(for app). Use the exactclient_idthat gtag.js or GTM assigns to the user's browser, so it matches the ID the Google Analytics tag generated on your website. For app streams, retrieveapp_instance_idthrough the Firebase SDK (methods likegetAppInstanceId()on Android orappInstanceID()on Swift).events: an array of event objects. Each object requires aname(up to 40 characters, alphanumeric plus underscores, starting with a letter) and an optionalparamsobject with up to 25 key-value pairs. Parameter names also have a 40-character limit, and values are capped at 100 characters (500 for Google Analytics 360 properties).- Optionally, you can add
user_idfor cross-device tracking,user_properties(up to 25),timestamp_microsfor backdating, and location or device overrides. We'll focus on the essential.
A minimal event payload looks like this:
{
"client_id": "CLIENT_ID",
"events": [
{
"name": "login",
"params": {
"method": "Google",
"session_id": "SESSION_ID",
"engagement_time_msec": 100
}
}
]
}The session_id and engagement_time_msec parameters deserve special attention. session_id identifies the session this event belongs to. It must be a positive number matching ^\d+$ and should be the session ID your tag is using for that visit. In Google Tag Manager, the Analytics Session ID built-in variable provides it. Providing a new session_id starts a new session without needing the reserved session_start event. engagement_time_msec tells GA4 how many milliseconds of user engagement happened since the preceding event. Together with session_id, it is needed for user activity to display in reports like Realtime.
Timestamp handling follows a clear hierarchy: if an event has timestamp_micros, it uses that; otherwise it uses the request-level timestamp_micros; otherwise the server's receive time. You can backdate events up to 72 hours. For most use cases, leave timestamps alone and let the server time them.
You can send up to 25 events in a single request. That means you can batch several server-side events together, as long as the total JSON body stays under 130kB.
If you're working with User-ID to unify cross-device behaviour, include "user_id" in the JSON root. More on that in How To Set Up User-ID In GA4.
Now, before going live, validate your payloads.
Validate With The Debug Endpoint
The normal Measurement Protocol endpoint won't return error codes, even for malformed payloads. A 2xx status means only that the HTTP request was received, not that the data was processed or is valid. To catch mistakes early, send your first requests to the debug validation server.
The debug URL is identical, except it includes /debug before /mp/collect:https://www.google-analytics.com/debug/mp/collect?measurement_id=G-XXXXXXXX&api_secret=YOUR_SECRET
All other request fields stay the same. When you post to this endpoint, the server validates the payload but does not record any events; they never appear in your reports. It returns a JSON object with a validationMessages array. An empty array means everything passed. Any issues appear as objects with fieldPath, description, and validationCode, like NAME_INVALID, VALUE_REQUIRED, or EXCEEDED_MAX_ENTITIES.
For instance, sending an event with a name that starts with an underscore (reserved) yields:
{
"validationMessages": [
{
"fieldPath": "events",
"description": "Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.",
"validationCode": "NAME_INVALID"
}
]
}For development, set the validation_behavior parameter to "ENFORCE_RECOMMENDATIONS". This applies strict rules: it rejects events with timestamps older than 72 hours, invalid parameter types, and anything that exceeds documented limits. The default RELAXED mode still accepts many borderline payloads, which can hide problems. In production, don't set validation_behavior, because you want to minimise rejected data; but during testing, strict mode shows you every fix you'll need.
The easiest way to build and validate payloads without writing code first is the Google Analytics Event Builder. It provides a visual interface, constructs the JSON, and calls the validation server automatically with ENFORCE_RECOMMENDATIONS. You can paste the resulting JSON directly into your server code.
One note: the validation server does not check whether your api_secret or Measurement ID is correct, so always double-check those values manually before tagging live. Use GA4 DebugView once you start sending real events to confirm they appear in the property.
Limits And What It Cannot Do
The Measurement Protocol enforces hard limits on field sizes and request structure. Exceed them and your data may be silently discarded.
| Limit | Value |
|---|---|
| Events per request | 25 |
| Parameters per event | 25 |
| User properties per request | 25 |
| Maximum JSON body size | 130 kB |
| Event name length | 40 characters, alphanumeric and underscores only, must start with a letter |
| Parameter name length | 40 characters, same rules as event names |
| Parameter value length (standard) | 100 characters |
| Parameter value length (360) | 500 characters |
| User property name length | 24 characters |
| User property value length | 36 characters |
| Custom item parameters per item | 10 |
| Backdating window | up to 72 hours (events beyond 72h are capped or rejected depending on validation) |
On top of field limits, there's a volume cap: each property can receive up to 100 million non-conversion requests per hour. If you exceed that, the Measurement Protocol silently discards all non-conversion requests for the rest of that hour. Your server gets a 200 OK, so you won't know data was lost unless you monitor your hourly submission counts.
App streams have an additional restriction: Measurement Protocol events sent to app streams do not populate Search audiences in Google Ads for app users. The reserved names list also matters, event names like ad_impression, in_app_purchase, screen_view are only allowed for app streams (on web, use page_view and purchase instead). Other reserved event names such as first_open, session_start, and user_engagement cannot be used at all. Parameter names cannot start with an underscore, firebase_, ga_, google_, or gtag.. Similarly, user property names like first_open_time and user_id are reserved.
The Measurement Protocol is a supplementary tool. If you rely on it as your sole data source, expect incomplete reporting: some dimensions (e.g., device category) default to "desktop" for web or "mobile" for app, and automatic event modifications like event renaming or generation rules won't apply. Always keep your gtag, GTM, or Firebase tagging in place so that MP events can be joined with the rich context those tags collect.
Frequently Asked Questions
What Is The Google Measurement Protocol?
The Google Measurement Protocol allows you to send events directly to Google Analytics servers via HTTP POST requests. It supplements automatic data collection methods like gtag, Tag Manager, and Firebase by capturing server-to-server interactions, offline conversions, and events from devices that can't run client-side code. You need an active GA4 property and an API secret to use it.
How Do I Get An API Secret For The Measurement Protocol?
In Google Analytics, go to Admin > Data collection and modification > Data streams > choose your stream > Measurement Protocol API secrets. Click Create, enter a nickname, and copy the Secret value. Keep it confidential; it authenticates your requests. App streams also need a firebase_app_id, found in the Firebase console under Project settings.
What Parameters Are Required In A Measurement Protocol Request?
For web streams, you need api_secret and measurement_id in the URL and client_id in the JSON body, plus an events array with at least one event object containing a name. For app streams, replace measurement_id with firebase_app_id and client_id with app_instance_id. Parameters like session_id and engagement_time_msec are strongly recommended for proper session reporting.
Why Should I Validate Events With The Debug Endpoint?
The production endpoint returns a 2xx status whenever it receives the request, even for malformed payloads. The debug endpoint (/debug/mp/collect) validates your JSON without recording events and returns a validationMessages array that details every error, missing fields, invalid names, exceeding limits. It helps catch mistakes before they silently fail.
What Are The Limits Of The Measurement Protocol?
Up to 25 events per request, 25 parameters per event, 25 user properties per call, and a 130kB body size. Event and parameter names have 40-character limits; values top out at 100 characters (500 on 360). You can't backdate events beyond 72 hours, and each property has a 100 million non-conversion request per hour ceiling, after which data is silently dropped.
How Do I Include Geographic Information In Measurement Protocol Events?
You can send a user_location object with city, region_id (ISO 3166-2), country_id (ISO alpha-2), subcontinent_id, and continent_id (UN M49). Provide at least country_id and region_id. Alternatively, use ip_override to let GA derive location; user_location takes precedence. GA applies the property's granular location settings regardless.
Related GA4 Guides
- The GA4 API Explained: Data, Admin And Measurement ProtocolThe GA4 API includes Data API, Admin API, and Measurement Protocol to pull reports, manage settings, and send server-side events. Learn how to get started.
- The Google Analytics MCP Server: Query GA4 From Claude And Other AI ToolsUse the official Google Analytics MCP server to ask GA4 questions in Claude, Gemini, or Cursor. Setup steps, read-only access, and quota limits explained.
- How To Connect GA4 To Looker StudioConnect GA4 to Looker Studio and build a custom dashboard for Google Analytics. Step-by-step guide to data sources, reports, templates, and quota limits.
- How To Export GA4 Data To BigQueryExport raw GA4 events to BigQuery for SQL analysis. Learn to link properties, choose daily or streaming export, understand the schema, and run your first queries.
- How To Add GA4 To A React AppUse the react-ga4 package to track page views and custom events in your single-page React app. Step-by-step setup, manual tracking with React Router, and testing.
More in APIs & Integrations or browse all GA4 guides.
Official Documentation Used