Introduction

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.

A dimension is an attribute of a session or hit that can be used for grouping data.

In API requests, dimensions are set in the dimensions parameter. If you need to list multiple dimensions, separate them with commas.

It is also possible to make a report without dimensions; in this case, the total result is calculated.

A metric is a numerical value that is based on an attribute of a hit or session.

In API requests, metrics are set in the metrics parameter. If you need to list multiple metrics, separate them with commas.

You can create the desired report structure by specifying metrics and dimensions in the API request.

For example, to get a report on page depth with data grouped by OS type and version, use this request:

https://api-metrica.yandex.com/stat/v1/data.csv?id=2138128&metrics=ym:s:avgPageViews&dimensions=ym:s:operatingSystem&limit=5&oauth_token=05dd3dd84ff948fdae2bc4fb91f13e22bb1f289ceef0037

Compatibility of dimensions and metrics

The API supports two types of dimensions and metrics:

  • Sessions, with the prefix ym:s:.
  • Pageviews (hits), with the prefix ym:pv:.

You cannot use different prefixes in the same request, or specify more than one category (see the section Categories and relationships).

Attention.

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:

where

  • dimensions=ym:s:searchEngineName — Data grouped by the dimension ym:s:searchEngine (type of search engine).
  • metrics=ym:s:visits,ym:s:users — Number of sessions and users.
  • filters=ym:s:trafficSourceName=='Traffic from search engines' AND ym:pv:URL=@'help' — Data segmentation by the dimensions ym:s:trafficSourceName and ym:pv:URL.

Types of reports

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.

Format of reports

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:

GET https://api-metrica.yandex.com/stat/v1/data.csv?<counter_id>&<metrics>&<dimensions>

Since JSON is the default format, it can be omitted:

GET https://api-metrica.yandex.com/stat/v1/data?<counter_id>&<metrics>&<dimensions>

Data disclosure

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.