Measurement Protocol
Measurement Protocol is a tool that allows you to send user interaction data directly from your server to Yandex Metrica servers via HTTP requests. It enhances data collection and analysis capabilities by supplementing the data collected by the standard web tag.
Alert
Measurement Protocol is best used in addition to automatic data collection by the Yandex Metrica tag, not as its replacement.
Usage
Linking online sessions with your data
-
Measurement Protocol allows you to combine data collected by the Yandex Metrica tag on your site with the data that the web tag cannot track.
For example:
- supplement a user’s session with information about those pages where the Yandex Metrica tag is not installed;
- send data about the quality of a lead who filled out a session form recorded by the web tag. Add a conversion event to this session for deeper analysis.
Tracking actions on both the client and server sides
- With Measurement Protocol, you can transmit data from both the client and server sides. This is especially useful when data collection on the client side is limited due to ad blockers or browser settings.
More accurate transmission of e-commerce event data
- Measurement Protocol allows you to transmit e-commerce event data directly from your server. This is useful when users do not return to the site after the acquiring page or when the web tag cannot capture data for other reasons, such as the presence of third-party script blockers on the user’s site.
Transmitted data
With Measurement Protocol, you can both create new sessions on the tag and supplement the existing ones.
The main identifier for sending data is the ClientID of Yandex Metrica. It allows you to link the transmitted data with the user’s history and sessions on the tag.
You can send:
- pageviews;
- JavaScript goal completions;
- e-commerce events (product views, purchases, additions to or removals from the cart);
- session parameters.
How to set up data transmission
-
Enable Measurement Protocol in the tag settings and obtain an authorization token.
To be able to send data, go to the Data security and usage section in Yandex Metrica interface or the API and enable the Measurement Protocol option in additional settings of the tag. You will receive a token that you will have to send in requests to mc.yandex.ru/collect. You can create up to 5 additional authorization tokens.
More about managing the option and generating tokens via the API
-
Remember the users’ ClientID identifier.
The main identifier for sending Measurement Protocol data is the ClientID of a Yandex Metrica user. Remember this ID on your server during the user’s session recorded by Yandex Metrica for further data transmission.
-
Send the data.
Send a POST or GET request listing the necessary parameters and the token obtained in step 1 to mc.yandex.ru/collect. Within 20 minutes, the data will be recorded in the tag.
Limitation on updating web sessions
With Measurement Protocol, you can transmit data about events that occurred over the past 12 hours. Because of this, you can update an existing session only if it ended less than 12 hours ago.
If you want to add more events to a user's history and their last sessions ended more than 12 hours, create a new session:
- Create a new session with the same user ID (ClientID) using the API Measurement Protocol.
- Send the event data. This data will update the user's history.
If you need to add data to older sessions without creating new ones, try sending offline data.
Useful links |
Online training |