The Reports API allows you to get site traffic statistics and other data without using the Yandex.Metrica interface.
Dimensions and metrics are used for making API requests.
|Operating system||Page depth|
If you are familiar with SQL, you can think of dimensions as columns used for grouping, and metrics as the results returned by aggregate functions.
For example, the report shown above can be imagined as a query to a hypothetical table of sessions:
SELECT operatingSystem, avg(depth) from visits GROUP BY operatingSystem
|Operating system||OS version||Page depth|
For example, to get a report on page depth with data grouped by OS type and version, use this request:
The API supports two types of dimensions and metrics:
You cannot use different prefixes in the same request, or specify more than one category (see the section Categories and relationships).
You can specify a different prefix from the one set in the request and different categories when using the filters parameter for filtering resulting data by dimensions.
For example, this request generates a report on the number of sessions and unique users from search engines for the page specified in the request:
Resulting data can be provided in the following formats:
All report levels and metrics are shown as a table.
To display data as a table, use the /stat/v1/data method.
Generating a single branch of a tree view report.
To create branches, use the /stat/v1/data/drilldown method.
Data is divided over units of time (such as days, weeks, and months). This format is convenient for building charts and tracking trends.
Use the /stat/v1/data/bytime method.
Comparison of segments specified in the same request. Data is shown as a table.
Use the /stat/v1/data/comparison method.
Comparison of segments specified in the same request. Data is shown in a tree-view report.
Use the /stat/v1/data/comparison/drilldown method.
The API returns responses in UTF-8 encoding. Responses are in JSON or CSV format.
The format is specified in the request after the URL:
Since JSON is the default format, it can be omitted:
Yandex.Metrica protects users' privacy and ensures that all collected information is depersonalized. For this reason, certain information such as social-demographic data (gender, age, and so on) has limited disclosure. Such data is provided only if there were more than 10 users in the sample.
For example, you want to know the percentage of males out of the total users for the day. At the time of the request, the site has been visited by 5 people (less than 10). In this case, the response will contain information about the total number of users for the day, but data will not be available for the number of males.