Metrica

Transmitting and processing data

Yandex.Metrica assigns each site user a ClientID. At the same time, site owners may use their own systems for identifying users.

You can use the setUserID method to transmit a site user ID to Yandex.Metrica, which allows you to link the UserID to the ClientID.

This method must be called during the session in order for the site user ID to be associated with the ClientID
[no-highlight[

The site user‘s ID assigned by Yandex.Metrica.

]no-highlight]
for a site visitor. To get more complete statistics, we recommend waiting some time until a larger volume of data is transmitted to Yandex.Metrica.

There are two ways to transmit user parameters:

During a site session

This method is useful when you are generating a report based on data received while the user is viewing the site.

User parameters are transmitted to Yandex.Metrica through the JavaScript API. To transmit the parameters at any other time, use the userParams method.

When initializing the counter, you can specify user parameters in UserParams.

Data is sent as JavaScript objects and 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.
  • true, false or null — Calculates the number of times each value occurs.
Note. Data that is sent via the JavaScript API is not deleted from the service.

Let's look at an online store that has two types of customers: “normal” and “VIP”. The client status data is stored in the site's own database. Once users sign in on the site, they see their usernames in place of the Sign in link on every page. If a user has a special status, it is shown next to the name: Alice / VIP. To send Yandex.Metrica the client status, you need to add code to all the site's pages that will call the userParams method.

For sending data about users with a special status, the code will look like this:

yaCounterXXXXXX.userParams({
    vip_status: true,
    child: 1,
    child_age: 13
});

If information is being transmitted about a “normal” user, the code will look like this:

yaCounterXXXXXX.userParams({
    vip_status: false,
    child: 1,
    child_age: 13
});

where XXXXXX is your counter number.

If a “normal” customer gets VIP status, the userParams method sends the new data to Yandex.Metrica the next time this user signs in on the site. This new status will apply to the entire history of this user's sessions, as if the customer was always VIP.

Transmitting data in a CSV file at any time

This method allows you to send Yandex.Metrica not only the data collected during the site session, but also any data collected after the user left the site.

Specification for the CSV format

Overview of the CSV format

Table 1. Required fields for transmitting data

The fields support a hierarchical data structure.
Field nameDescriptionExample
clientID | userIDSite user IDP12345
key User ID. Maximum of 1,000 per username | client.name
value User ID value John

For a hierarchical structure of parameters, use the dot (“.”). For example, to transmit multiple values of the key field, specify client.demography.age.

When to transmit the ClientID
We recommend using the ClientID
[no-highlight[

The site user‘s ID assigned by Yandex.Metrica.

]no-highlight]
in transmitted data if you don't need to get your own IDs in a report. In this case, to transmit the data:
  1. Use the getClientID method to get the ClientID.
  2. Prepare a CSV file specifying the ClientID and send it through the Yandex.Metrica interface.

When to transmit the UserID
We recommend using the UserID
[no-highlight[

The site user‘s ID assigned by the site owner.

]no-highlight]
if, for instance, your site already has a user ID system and you need to get a report that shows these IDs. In this case, you need to create a CSV file specifying the UserIDs and send it through the Yandex.Metrica interface.

Working with a file

The Yandex.Metrica interface lets you upload data and delete it. You can work with a file in the Settings section (go to the Upload data tab).

Note. If session parameters were transmitted in the file, you won't be able to remove them from the service later. You can only delete user parameters.
Uploading data

To send a prepared CSV file to Yandex.Metrica:

  1. Click Upload data.
  2. In the window that opens, choose the file type according to the type of ID you want to upload (UserID
    [no-highlight[

    The site user‘s ID assigned by the site owner.

    ]no-highlight]
    or ClientID
    [no-highlight[

    The site user‘s ID assigned by Yandex.Metrica.

    ]no-highlight]
    ).
  3. Select the file on your computer and add comments to the upload, if necessary.
  4. Click Upload data.

Sample CSV file for uploading data

Deleting data

To remove previously uploaded data or parts of it from the service, prepare a CSV file. The file should only contain the key field for the data you want to remove. Then follow these steps:

  1. Click Delete data.
  2. In the window that opens, choose the type of file to apply the changes to, according to the type of ID (UserID
    [no-highlight[

    The site user‘s ID assigned by the site owner.

    ]no-highlight]
    or ClientID
    [no-highlight[

    The site user‘s ID assigned by Yandex.Metrica.

    ]no-highlight]
    ).
  3. Select the file on your computer and add comments to the upload, if necessary.
  4. Click Upload data.

Sample CSV file for deleting data

It takes some time for the system to process the file. When processing is complete, the data you sent will be available in the User parameters report. You can also use this data to create segments for retargeting lists in Yandex.Direct or Yandex.Audience (see the example).