Transmitting events
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. However, you’ll likely find that it would benefit you to supplement this data with your own data. For example, you may be interested in statistics on what specific items were purchased or what actions users who were logged in performed.
Yandex Metrica lets you connect a custom data set to a session. These sets are called event 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 tag initialization, or at any time before the session timeout expires.
During tag initialization, session parameters are specified in the params parameter.
To transfer event parameters during a user’s session on your site, use the params method or an optional argument of extLink, file, hit, reachGoal methods.
Event parameters are transmitted as objects or object arrays.
Transferring and processing data
Data is transferred to Yandex Metrica as JavaScript objects.
The data request sent to Yandex Metrica can contain no more than 8 KB (8,192 characters). When you send hierarchically structured data, the Yandex Metrica reports display up to 10 nesting levels. If, within a single session, one parameter was transmitted with different values, then Yandex Metrica will display all values. It should be noted that up to 512 parameters can be sent in one session. For more information, see Restrictions.
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.
- 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.
Example of transferred data:
// Example of object transfer. Maximum nesting depth: 10 levels.
ym(XXXXXX, "params", {
level1_1: {
level2_1: {
level3_1: "example1" ,
level3_2: "example2",
},
...
level2_2: "example3"
}
})
Where:
- XXXXXX is the tag number.
- level1_1, level1_2, level2_1 — structure of event parameters.
- example1, example2, example3 — values for parameters.
For more examples, see the Examples of sending session parameters section.
Reports by parameters
Events are transferred to Yandex Metrica as dimensions or goals. The numbers that are calculated by processing the data are the metrics.
To view statistics on transmitted events, use the “Event parameters” report or the “Session parameters” report. You can also use parameters as conditions for creating segments in other Yandex Metrica reports.
Note
If you pass parameters using the reachGoal method, but you haven't created a JavaScript goal for the tag or only created it as part of a multi-step goal, the data won’t appear in the “Event parameters” report.
Create a separate JavaScript goal in the tag interface or use other methods to transfer parameters: params, extLink, file, or hit.
Useful links |
Online training |
Attribute that represents user actions registered by the tag (for example, session, pageview, referral, file download, etc.). Data sent in a report is grouped by attribute.
A numerical value that is based on an attribute of a session or pageview. This amount can be the total or average. For example, pageviews are calculated as the sum of values, while session depth is the average value.