Overview
This guide explains how to format and send requests to the Google Analytics Measurement Protocol.
Sending events
To send an event, make an HTTP
POST
request to the following endpoint:
POST /mp/collect HTTP/1.1
HOST: www.google-analytics.com
Content-Type: application/json
<payload_data>
Required parameters
A valid request requires two sets of parameters that vary if you're using Firebase or gtag.js:
URL parameters
api_secret
- Required. AnAPI SECRET
generated in the Google Analytics UI. To create a new secret, navigate to: Admin > Data Streams > choose your stream > Measurement Protocol > Create
See query parameters for the full reference.
JSON body
user_id
- Optional. A unique identifier for a user. See User-ID for cross-platform analysis for more information on this identifier.events
- Required. An array of event items.
See JSON POST BODY for the full reference.
Send an event
To send a tutorial_begin
event, make the following request:
Limitations
- Requests can have a maximum of 25 events.
- Events can have a maximum of 25 parameters.
- Events can have a maximum of 25 user properties.
- User property names must be 24 characters or fewer.
- User property values must be 36 characters or fewer.
- Event names must be 40 characters or fewer, may only contain alpha-numeric characters and underscores, and must start with an alphabetic character.
- Parameter names (including item parameters) must be 40 characters or fewer, may only contain alpha-numeric characters and underscores, and must start with an alphabetic character.
- Parameter values (including item parameter values) must be 100 character or fewer.
- Item parameters can have a maximum of 10 custom parameters.
- The post body must be smaller than 130kB.