Choose the platform you want to see in this guide:
Format the request
The Google Analytics Measurement Protocol only supports HTTP POST requests.
To send an event, use the following format:
POST /mp/collect HTTP/1.1
HOST: www.google-analytics.com
Content-Type: application/json
<payload_data>
You must provide the following in the request URL:
api_secret: The API SECRET generated in the Google Analytics UI.
To create a new secret, navigate to Admin > Data Streams > choose
your stream > Measurement Protocol > Create.
measurement_id: The measurement ID associated with a stream, found in the
Google Analytics UI under Admin > Data Streams > choose your
stream > Measurement ID.
You must provide the following in the request body:
client_id: A unique identifier for a client. This is different than a
Firebase app_instance_id. Use gtag.js('get').
user_id: Optional. A unique identifier for a user. Can only contain UTF-8
characters. See User-ID for cross-platform analysis for more information
about this identifier.
timestamp_micros: Optional. The Unix epoch time, in microseconds, for the
events and user properties in the request. If not specified, defaults to the
time of the request.
events: An array of event items. You can include multiple events in one
request.
In order for user activity to display in reports like
Realtime,
engagement_time_msec and session_id must be supplied as part of the
params for an event. The engagement_time_msec parameter should reflect
the event's engagement time in milliseconds.