Session parameters

Tip. Working with the JavaScript API requires knowledge of HTML and JavaScript. If you don't have these skills, contact your website developer or webmaster.

Most of the session data is collected automatically by the Yandex.Metrica counter. However, the collected data often needs to be supplemented with your own data. For example, you may be interested in statistics on specific item purchases or information about the actions of users who are logged in.

Yandex.Metrica lets you connect a custom set of data to a session. This is called session parameters. This data can be shown in reports, or used in conditions for dimensions and segmentation.

Session parameters are transmitted to the counter storage using the JavaScript API. Data can be sent either during counter initialization, or at any time.

During counter initialization, session parameters are specified in the params parameter.

To send session parameters at any other time, use the params method, or the optional argument for the extLink, file, hit, or reachGoal methods.

Session parameters are transmitted as JavaScript objects.

The request can have a maximum of 128 parameters, and the maximum size of the request itself (including the header) is 256 KB.

var yaParams = {
    x: 10,
    y: "unauthorized user"

var yaCounterXXXXXX = new Ya.Metrika({id: XXXXXX, params: window.yaParams||{}});

Processing transmitted data

Data that is transmitted to Yandex.Metrica as JavaScript objects are processed as follows.

The field name and nesting level are interpreted as the parameter name and level, respectively. The field value is processed as follows, depending on its type:

  • object — Creates a new tree branch for each object key, and invokes the algorithm recursively for each value.
  • string — Calculates the number of cases when each different string value occurs.
  • number — Calculates the total and average value of all numbers.
  • array — Creates a [Parameters] tree branch, calculates the number of times the value is an array, and invokes the algorithm recursively for each item in the array.
  • true, false or null — Calculates the number of times each value occurs.
Parameters are transmitted to Yandex.Metrica as dimensions

Attribute for user actions that are registered by the counter (for example, session, pageview, referral, file download, and so on). Data put in the report is grouped by this attribute.

. The numbers that are calculated by processing the data are the metrics.
Attention! Some of the field names are reserved for transmitting ecommerce data.

Example. АВ testing

Let’s say we need to conduct an experiment to determine how the color of the Buy button affects the conversion rate for a “View basket” goal.

If the user is shown a red button, we use the following parameter:

var yaParams = {ab_test: "red button"};

If the user is shown a green button, we use the following parameter:

var yaParams = {ab_test: "green button"};

This parameter is transmitted in any convenient way. For example, it can be passed when initializing the counter on product pages or using the reachGoal method called when the Buy button is clicked.

After this, we will be able to use the ab_test parameter value in the Yandex.Metrica interface for selecting the corresponding data.

Example. Transmitting a hierarchical data structure

For instance, we need to transmit data and show it in a report in a tree view.

var yaParams = {