AI-generated Key Takeaways
-
Data for the Measurement Protocol must be sent securely using HTTPS
POSTrequests to a specified endpoint. -
The payload for a Measurement Protocol request consists of query parameters, including a required
api_secret, and a JSONPOSTbody with various optional and required fields likeuser_id,timestamp_micros, andevents. -
The
eventsarray within the JSON body is required and can contain up to 25 event items, each needing anameand optionally includingparams. -
Common event parameters like
session_idandengagement_time_msecare important for user activity to display in reports like Realtime. -
The Measurement Protocol uses
RELAXEDvalidation by default, butENFORCE_RECOMMENDATIONScan be used for stricter validation, particularly when validating events.
This page describes the transport mechanism and data parameters for the Measurement Protocol.
Transport
All data must be sent securely using HTTPS POST requests.
Send requests to the following endpoint:
https://www.google-analytics.com/mp/collect
If you want your data to be collected in the EU, use the following endpoint instead:
https://region1.google-analytics.com/mp/collect
Here's a sample POST request:
POST /mp/collect HTTP/1.1
HOST: www.google-analytics.com
Content-Type: application/json
PAYLOAD_DATA
Replace PAYLOAD_DATA with Payload of the request.
The Measurement Protocol returns a 2xx status code if the HTTP
request is received. The Measurement Protocol doesn't return an error code if
the payload is malformed, or if the data is incorrect or not processed by
Google Analytics.
Payload
The payload has two parts:
- Query parameters.
- A JSON
POSTbody.
Query parameters
| Parameter Name | Description |
|---|---|
|
Required. The API Secret from the Google Analytics UI.
Found under Admin > Data Streams > Choose your stream > Measurement Protocol > Create. Private to your organization. Should be regularly updated to avoid excessive SPAM. |
JSON POST body
| Key | Type | Description |
|---|---|---|
|
string |
Optional. A unique identifier for a user. See User-ID for cross-platform analysis for more information on this identifier. Can include only utf-8 characters. |
|
number |
Optional. A Unix timestamp, microseconds, not milliseconds. Represents the time of the event. Should be set only to record events that happened
in the past. Can be overridden by
|
|
object |
Optional. The user properties for the measurement. |
|
object |
Optional. User-provided data. |
|
object |
Optional. Consent settings for the request. See the consent section for more information. |
|
boolean |
Optional. Set to true to indicate the user's data shouldn't
be used for personalized ads.
|
|
object |
Optional. Sets the geographic information for the request in a structured format. |
|
string |
Optional. IP address Google Analytics uses to derive geographic information for the request. |
|
object |
Optional. Sets the device information for the request in a structured format. |
|
string |
Optional. Sets the validation behavior for the request. Either |
|
array |
Required. An array of event items. Up to 25 events can be sent per
request. See the events
reference for all valid events.
|
|
string |
Required. Name of the event. See Events for all options. |
|
object |
Optional. Parameters for the event. See Events for the suggested parameters for each event, and Common event parameters. |
Common event parameters
The Measurement Protocol has the following common event parameters:
| Key | Type | Description |
|---|---|---|
|
number |
A positive number that identifies the user session. Required for several
common use cases.
Must match the regular expression ^\d+$.
|
|
number |
The duration of user engagement, in milliseconds, for the event. Use a value that reflects the amount of user engagement time since the preceding event. |
|
number |
The Unix epoch time, in microseconds, for the event. Use this parameter to override the timestamp of the event. |
Consent
The consent attribute configures consent types and states.
If you don't specify consent, Google Analytics uses the consent
settings from corresponding online interactions for the client or app instance.
| Key | Type | Description |
|---|---|---|
|
string |
Optional. Consent for sending user data from the request's events and user properties to Google for advertising purposes. Either |
|
string |
Optional. Consent for personalized advertising for the user. Either |
Geographic information
The user_location and ip_override attributes provide geographic information.
user_location takes precedence over ip_override.
Here's the structure of the
user_location field. Provide as many of the attributes as possible. We
recommend country_id and region_id at a minimum.
| Key | Type | Description |
|---|---|---|
|
string |
Optional. The city's
name. If the city is in the US, also set country_id and
region_id so Google Analytics can properly map the city name
to a city
ID.
|
|
string |
Optional. The ISO 3166 country and
subdivision. For example, US-CA, US-AR,
CA-BC, GB-LND, CN-HK.
|
|
string |
Optional. The country in ISO 3166-1 alpha-2
format. For example, US, AU,
ES, FR.
|
|
string |
Optional. The subcontinent in UN M49 format. For
example, 011, 021, 030,
039.
|
|
string |
Optional. The continent in UN M49 format. For
example, 002, 019, 142,
150.
|
Here's a sample user_location:
"user_location": {
"city": "Mountain View",
"region_id": "US-CA",
"country_id": "US",
"subcontinent_id": "021",
"continent_id": "019"
}
ip_override is an alternative to user_location. If you send ip_override
instead, Google Analytics derives geographic information from the IP address.
If you send user_location, Google Analytics ignores ip_override.
If you don't send user_location or ip_override, Google
Analytics derives geographic information from tagging events using
client_id.
Google Analytics applies the property's granular location data settings to the request, regardless of the geographic information sent.
Device information
To send device information, use the
device field. Here's the structure of the device field. Provide as many of
the attributes as possible. We recommend category at a minimum.
| Key | Type | Description |
|---|---|---|
|
string |
Optional. The category of the device. For example,
desktop,
tablet,
mobile,
smart TV.
|
|
string |
Optional. The language in ISO 639-1 format. For
example, en, en-US.
|
|
string |
Optional. The resolution of the device, formatted as
WIDTHxHEIGHT. For example, 1280x2856,
1080x2340.
|
|
string |
Optional. The operating system or platform. For example,
MacOS.
|
|
string |
Optional. The version of the operating system or platform. For
example, 13.5.
|
|
string |
Optional. The model of the device. For example,
Pixel 9 Pro, Samsung Galaxy S24.
|
|
string |
Optional. The brand of the device. For example,
Google, Samsung.
|
|
string |
Optional. The brand or type of browser. For example,
Chrome, Firefox.
|
|
string |
Optional. The version of the browser. For example,
136.0.7103.60, 5.0.
|
The following snippet shows an example of device settings:
"device": {
"category": "mobile",
"language": "en",
"screen_resolution": "1280x2856",
"operating_system": "Android",
"operating_system_version": "14",
"model": "Pixel 9 Pro",
"brand": "Google",
"browser": "Chrome",
"browser_version": "136.0.7103.60"
}
Regardless of whether you specify Google Analytics applies the property's granular device data settings to the request.
Validation behavior
The validation_behavior attribute controls how the Measurement Protocol
validates the contents of the request.
RELAXEDvalidation only rejects requests that are malformed. It might still accept events and parameters with invalid field names or with data that isn't the correct type, but it ignores parameters that exceed limits. The Measurement Protocol usesRELAXEDvalidation by default.ENFORCE_RECOMMENDATIONSvalidation rejects event and item parameters that aren't the correct type or that contain parameters that exceed limits. In addition,ENFORCE_RECOMMENDATIONSrejects any event or user property with a timestamp more than 3 business days in the past in the property's time zone.
We recommend the following approach:
Use
ENFORCE_RECOMMENDATIONSwhen you validate events to get as much feedback as possible about potential problems with your requests.You can also validate requests using the Event Builder since it specifies
ENFORCE_RECOMMENDATIONSwhen validating requests.Don't specify
validation_behaviorwhen you send events to minimize the data rejected by the Measurement Protocol.If you want to prioritize strict validation over data collection when sending a particular request, add the
validation_behaviorfield and set it toENFORCE_RECOMMENDATIONS.
Custom parameters
You can include custom user-scoped, event-scoped and item-scoped parameters in a Measurement Protocol payload.
- User-scoped custom parameters can be included in
user_properties. - Event-scoped custom parameters can be included in
events[].params. - Item-scoped custom parameters can be included in
items.
Recommended values for certain events
Some events have recommended parameters. See events for the recommended parameters for all supported events.
Reserved names
Some event, parameter, and user property names are reserved and can't be used:
Reserved event names
The following event names are reserved and can't be used:
ad_activeviewad_clickad_exposuread_queryad_rewardadunit_exposureapp_clear_dataapp_exceptionapp_installapp_removeapp_store_refundapp_updateapp_upgradedynamic_link_app_opendynamic_link_app_updatedynamic_link_first_openerrorfirebase_campaignfirebase_in_app_message_actionfirebase_in_app_message_dismissfirebase_in_app_message_impressionfirst_openfirst_visitin_app_purchasenotification_dismissnotification_foregroundnotification_opennotification_receivenotification_sendos_updatesession_startuser_engagement
Reserved parameter names
The following parameter names are reserved and can't be used:
firebase_conversion
Parameter names can't begin with the following:
_ (underscore)firebase_ga_google_gtag.
Reserved user property names
The following user property names are reserved and can't be used:
first_open_timefirst_visit_timelast_deep_link_referreruser_idfirst_open_after_install
Additionally, user property names can't begin with:
_ (underscore)firebase_ga_google_