Segmentation

All methods in the Reporting API can return results for each separate data segment, as well as for the entire site. To set the segment, use the filters parameter.

You can segment a request by dimensions and metrics. The dimension or metric does not have to be specified in the request.

Dimension filters are applied to source (ungrouped) data, and metric filters are applied to grouped rows in the result.

To set a filter in the request URL, use URL encoding.

Filter format

attribute operator 'value'

where

  • attribute: The dimension or metric. For example, ym:ge:mobileDeviceModel or ym:ge:users.
  • operator: Filtering operator. and specifies which type of filtration to apply. For example, ==.
  • value: Comparison value. In the string with the value, the characters ' and \ must be escaped with a \.

In addition, the following limits are imposed: a maximum of 10 unique dimensions and metrics, 20 separate filters, and 2000 characters in the filter string.

For example, to get data only for sessions from Moscow, use this filter:

filters=ym:ge:regionCity=='Москва'

Different dimensions have different filtration operators available.

To combine filters in a request, use the binary AND, OR operators and the unary NOT operator:

&metrics=ym:ge:users&dimensions=ym:ge:age&filters=NOT(ym:ge:age!=18)
ym:ge:regionCity=='Москва' OR ym:ge:regionCity=='Санкт-Петербург'

You can also set priority using parentheses:

(ym:ge:regionCity=='Москва' OR ym:ge:regionCity=='Санкт-Петербург') AND ym:ge:gender=='мужской'

You can combine dimension filters and metric filters, but only at the top level (outside of parentheses) and only using the AND operator.

Note

The request language (lang parameter) affects the filter values. We recommend always specifying this parameter.

Example using segmentation

Number of users based on the region

dimensions=ym:ge:mobileDeviceModel

metrics=ym:ge:users

filters=ym:ge:regionCityName=='Moscow'

curl -X GET \
  'https://api.appmetrica.yandex.com/stat/v1/data?id=1111&metrics=ym:ge:users&dimensions=ym:ge:mobileDeviceModel&filters=ym:ge:regionCityName==%27Москва%27' \
  -H 'Authorization: OAuth <your_token>'

where <your_token> is an OAuth token that you can obtain by following this guide.

GET /stat/v1/data?id=1111&metrics=ym:ge:users&dimensions=ym:ge:mobileDeviceModel&filters=ym:ge:regionCityName=='Москва' HTTP/1.1
Host: api.appmetrica.yandex.com
Authorization: OAuth <your_token>

where <your_token> is an OAuth token that you can obtain by following this guide.

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.

Contact support Suggest an improvement for documentation