Transmitting user parameters
Warning
Working with the JavaScript API requires knowledge of HTML and JavaScript. If you don’t know these languages, contact your website developer or webmaster.
Most of the session data is collected automatically by the Yandex Metrica tag. You can supplement it with your own data by transmitting session parameters. However, you may find that information about the users themselves is more useful than session statistics.
Yandex Metrica lets you send any custom data, referred to as user parameters. For user parameters, we recommend transmitting user traits that don’t change from session to session and that don’t contain personal data such as the user’s name. For more information about the difference between session parameters and user parameters, see Processing and storing data.
If you want the parameters you passed to be reflected in reports, Yandex Metrica should link them to site users. To do this, the following special IDs are used: ClientID and UserID. Parameters are linked to sessions for users who visited the website within 90 days before the data was sent to Yandex Metrica.
Note
When transmitting user parameters specifying the ClientID and UserID, the total number of users in Yandex Metrica reports may differ from the number of IDs passed due to the way the UserID is bound to the ClientID.
The reports will be updated with the new information within a few hours. To view statistics, use 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).
Note
Parameters sent to Yandex Metrica are stored for two years from the last upload. When the storage period ends, the report will no longer display the data.
When to transmit the ClientID
We recommend using the ClientID in transmitted data if you don’t need to get your own IDs in a report.
When to transmit the UserID
We recommend using the UserID if, for instance, your site already has a user ID system and you need to get a report that shows these IDs.
You can send user parameters to Yandex Metrica in several ways:
Passing data 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. Information sent using this method cannot be deleted from Yandex Metrica.
To transmit the parameters at any other time, use the userParams method. To transmit parameters during tag initialization, specify data in the userParams parameter. The information is transmitted as a JavaScript object and processed as follows.
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 — Counts the number of times each different value of the string occurs.
-
number — Calculates the total and average value of all numbers.
-
true, false or null — Calculates the number of times each value occurs.
Data will be bound to ClientID only if the userParams
method was called during the user's session. To get more complete statistics, wait until a larger volume of data has been transmitted to Yandex Metrica.
Example
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. After 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: Jane / VIP. Along with the status, you can also transmit the user ID that is stored in your database.
To send data to Yandex.Metrica, 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:
At any timeWhen initializing a tag
ym(XXXXXX, 'userParams', { vip_status: true, child: 1, child_age: 13, UserID: 12345 });
ym(XXXXXX, 'init', { clickmap: true, webvisor: true, userParams: { vip_status: true, child: 1, child_age: 13, UserID: 12345 } });
If information is being transmitted about a “normal” user, the code will look like this:
At any timeWhen initializing a tag
ym(XXXXXX, 'userParams', { vip_status: false, child: 1, child_age: 13, UserID: 12345 });
ym(XXXXXX, 'init', { clickmap: true, webvisor: true, userParams: { vip_status: false, child: 1, child_age: 13, UserID: 12345 } });
where
XXXXXX
is your counter number.If a regular customer gets VIP status, the
userParams
method will send the new data to Yandex Metrica the next time they log in to your website. 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
With this method, Yandex Metrica receives the data collected both during the site session and after the user left the site.
Specification for the CSV format
Field name |
Description |
Example |
|
Site user ID |
P12345 |
|
User ID. Maximum of 1,000 per user |
age | client.age |
|
User ID value |
40 |
To send a hierarchical structure of parameters, use the “.” symbol (dot). For example, to transmit multiple values of the key
field, specify client.demography.age
.
The maximum number of characters in fields shown in Yandex Metrica reports:
key
— 255;value
— 50.
To pass information with a parameter:
- Get the ClientID using the getClientID method.
- Generate a CSV file specifying ClientID and submit it in the Yandex Metrica interface.
- Send your UserID using the setUserID method.
- Generate a CSV file specifying UserID and submit it in the Yandex Metrica interface.
Working with a file
The Yandex Metrica interface lets you upload data and delete it. You can manage the file in Settings (find the Upload data tab and choose User parameters).
To send a generated CSV file to Yandex Metrica:
- Click Upload data.
- In the window that appears, select the file type depending on the type of the ID you want to upload (UserID or ClientID).
- Select the file on your computer and add comments to the upload, if necessary.
- Click Upload 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:
-
Click Delete data.
-
In the window that appears, select the file type to which you want to apply changes, depending on the ID (UserID or ClientID).
-
Select the file on your computer and add comments to the upload, if necessary.
-
Click Upload data.
It takes some time for the service to process the file. Once processing is complete, the information you submitted becomes 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).
Useful links |
Online training |
Unique website session ID created automatically by Yandex Metrica.
User ID set by the site owner (for example, when the site user logs into their personal account).
User ID set by the site owner (for example, when the site user logs into their personal account).
Unique website session ID created automatically by Yandex Metrica.