---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://appmetrica.yandex.com.tr/docs/en/mobile-api/stat/segmentation.md
  - https://appmetrica.yandex.com.tr/docs/ru/mobile-api/stat/segmentation.md
---
> **Documentation Index:** Fetch the complete configuration index at https://appmetrica.yandex.com.tr/docs/en/llms.txt

# 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](http://ru.wikipedia.org/wiki/URL#.D0.9A.D0.BE.D0.B4.D0.B8.D1.80.D0.BE.D0.B2.D0.B0.D0.BD.D0.B8.D0.B5_URL).

## Filter format {#format}

```xml translate=no
attribute operator 'value'
```

where

- `attribute`: The dimension or metric. For example, `ym:ge:mobileDeviceModel` or `ym:ge:users`.
- `operator`: [Filtering operator](https://appmetrica.yandex.com.tr/docs/en/mobile-api/stat/relations/relations.md). 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:

```xml translate=no
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:

```xml translate=no
&metrics=ym:ge:users&dimensions=ym:ge:age&filters=NOT(ym:ge:age!=18)
```

```xml translate=no
ym:ge:regionCity=='Москва' OR ym:ge:regionCity=='Санкт-Петербург'
```

You can also set priority using parentheses:

```xml translate=no
(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 info %}

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

{% endnote %}

## Example using segmentation {#example}

**Number of users based on the region**

`dimensions=ym:ge:mobileDeviceModel`
 
`metrics=ym:ge:users`
 
`filters=ym:ge:regionCityName=='Moscow'`
 
{% list tabs %}
 
- cURL
 
  ```bash translate=no
  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](https://appmetrica.yandex.com.tr/docs/en/mobile-api/intro/authorization.md#get-oauth-token).

- HTTP

  ```http translate=no
  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](https://appmetrica.yandex.com.tr/docs/en/mobile-api/intro/authorization.md#get-oauth-token).

{% endlist %}

<!-- source: en/_includes/feedback-button-2.md -->
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.

<a href="../../troubleshooting/feedback-new">
  <span class="button">Contact support</span>
</a>

<a href="../../troubleshooting/feedback-docs">
  <span class="button">Suggest an improvement for documentation</span>
</a>
<!-- endsource: en/_includes/feedback-button-2.md -->
