---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.1
alternate:
  - https://yandex.com/dev/metrika/en/stat/openapi/comparison.md
  - https://yandex.com/dev/metrika/ru/stat/openapi/comparison.md
  - href: ru/stat/openapi/comparison.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/metrika/ru/llms.txt

<div class="openapi">

# Сравнение сегментов

<!-- markdownlint-disable-file -->

Позволяет сравнить два сегмента данных, указанные в запросе. Сегменты идентифицируются как сегмент А и сегмент B. Для каждого сегмента можно задать разные диапазоны дат и фильтры сегментации. Данные будут представлены в виде таблицы.
Для каждой строки отчета возвращается два набора метрик: метрики сегмента А и метрики сегмента B.
Посмотрите как используется данный запрос в [примере](https://yandex.com/dev/metrika/ru/stat/examples.md#comparison).

## Request

<div class="openapi__requests">

<div class="openapi__request__wrapper" style="--method: var(--dc-openapi-methods-get);margin-bottom: 12px">

<div class="openapi__request">

GET {.openapi__method}
```text translate=no
https://api-metrika.yandex.net/stat/v1/data/comparison
```

</div>

</div>

</div>

### Query parameters

#|
|| **Name** | **Description** ||
||

_ids_{.json-schema-reset .json-schema-property .json-schema-required}
{.table-cell}|
**Type**: integer[]

Идентификаторы счетчиков, через запятую.

_Example:_{.json-schema-reset .json-schema-example} `44147844,2215573`
{.table-cell}
||
||

_metrics_{.json-schema-reset .json-schema-property .json-schema-required}
{.table-cell}|
**Type**: string

Список метрик, разделенных запятой.
Лимит: 20 метрик в запросе.

_Example:_{.json-schema-reset .json-schema-example} `ym:s:pageviews`
{.table-cell}
||
||

_accuracy_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Размер выборки, используемой для отчета. Позволяет управлять [семплированием](https://yandex.com/dev/metrika/ru/stat/sampling.md) (количеством визитов, использованных при расчете итогового значения).

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_callback_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Функция обратного вызова, которая обрабатывает ответ API.

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_date1_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата начала периода выборки для сегмента A в формате YYYY-MM-DD. Также поддерживаются значения: `today`, `yesterday`, `ndaysAgo`.

_Default:_{.json-schema-reset .json-schema-value} `6daysAgo`

_Min length:_{.json-schema-reset .json-schema-assertion} `1`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_date1_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата начала периода выборки для сегмента B в формате YYYY-MM-DD. Также поддерживаются значения: `today`, `yesterday`, `ndaysAgo`.

_Default:_{.json-schema-reset .json-schema-value} `6daysAgo`

_Min length:_{.json-schema-reset .json-schema-assertion} `1`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_date2_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата окончания периода выборки для сегмента A в формате YYYY-MM-DD. Также поддерживаются значения: `today`, `yesterday`, `ndaysAgo`.

_Default:_{.json-schema-reset .json-schema-value} `today`

_Min length:_{.json-schema-reset .json-schema-assertion} `1`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_date2_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата окончания периода выборки для сегмента B в формате YYYY-MM-DD. Также поддерживаются значения: `today`, `yesterday`, `ndaysAgo`.

_Default:_{.json-schema-reset .json-schema-value} `today`

_Min length:_{.json-schema-reset .json-schema-assertion} `1`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_dimensions_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Список группировок, разделенных запятой.
Лимит: 10 группировок в запросе.

_Example:_{.json-schema-reset .json-schema-example} `ym:s:trafficSource`
{.table-cell}
||
||

_direct_client_logins_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string[]

Логины клиентов Яндекс Директа, через запятую. Могут использоваться для формирования отчета [Директ-расходы](https://yandex.com/dev/metrika/ru/stat/direct-clicks.md).

_Example:_{.json-schema-reset .json-schema-example} `login1,login2`
{.table-cell}
||
||

_filters_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Фильтр [сегментации](https://yandex.com/dev/metrika/ru/stat/segmentation.md).
Лимит: количество уникальных группировок и метрик — до 10, количество отдельных фильтров — до 20, длина строки в фильтре — до 10 000 символов; количество значений в одном условии фильтрации — 100.

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_filters_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Фильтр сегментации для сегмента A.

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_filters_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Фильтр сегментации для сегмента A.

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_include_undefined_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: boolean

Включает в ответ строки, для которых значения группировок не определены. Влияет только на первую группировку. По умолчанию выключено.
{.table-cell}
||
||

_lang_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Язык.

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_limit_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Количество элементов на странице выдачи.
Лимит: 100 000.

_Default:_{.json-schema-reset .json-schema-value} `100`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_offset_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Индекс первой строки выборки, начиная с 1.

_Default:_{.json-schema-reset .json-schema-value} `1`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_preset_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

[Шаблон отчета](https://yandex.com/dev/metrika/ru/stat/presets.md).

_Example:_{.json-schema-reset .json-schema-example} `sources_summary`
{.table-cell}
||
||

_pretty_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Задает форматирование результата. Чтобы использовать форматирование, укажите значение `true`.

_Default:_{.json-schema-reset .json-schema-value} `false`

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_proposed_accuracy_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: boolean

Если параметр выставлен в `true`, API имеет право автоматически увеличивать accuracy до рекомендованного значения.Когда идет запрос в маленькую таблицу с очень маленьким семплингом, параметр поможет получить осмысленные результаты.
{.table-cell}
||
||

_sort_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Список группировок и метрик, разделенных запятой, по которым осуществляется сортировка. По умолчанию сортировка производится по убыванию (указан знак `-` перед группировкой или метрикой). Чтобы отсортировать данные по возрастанию, удалите знак `-`.

_Example:_{.json-schema-reset .json-schema-example} ``
{.table-cell}
||
||

_timezone_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Часовой пояс в формате ±hh:mm в диапазоне [-23:59; +23:59] (знак плюса нужно передавать как `%2B`),
в котором будут рассчитан период выборки запроса, а также связанные с датой и временем группировки.
По умолчанию используется часовой пояс счетчика.

_Example:_{.json-schema-reset .json-schema-example} `+03:00`
{.table-cell}
||
|#{.json-schema-properties}

## Responses

<div class="openapi__response__code__200">

## 200 OK

OK

<div class="openapi-entity">

### Body

{% cut "application/json" %}

```json translate=no
{
  "query": {
    "timezone": "example",
    "preset": "example",
    "dimensions": [
      "example"
    ],
    "metrics": [
      "example"
    ],
    "sort": [
      "example"
    ],
    "date1_a": "example",
    "date2_a": "example",
    "filters_a": "example",
    "date1_b": "example",
    "date2_b": "example",
    "filters_b": "example",
    "limit": 0,
    "offset": 0
  },
  "data": [
    {
      "dimensions": [
        {}
      ],
      "metrics": {
        "a": [
          0.5
        ],
        "b": [
          0.5
        ]
      }
    }
  ],
  "total_rows": 0,
  "total_rows_rounded": true,
  "sampled": true,
  "contains_sensitive_data": true,
  "sample_share": 0.5,
  "sample_size": 0,
  "sample_space": 0,
  "data_lag": 0,
  "totals": null
}
```

{% endcut %}

#|
|| **Name** | **Description** ||
||

_contains_sensitive_data_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: boolean

Признак возможного отсутствия [конфиденциальных данных](https://yandex.ru/support/metrica/reports/report-general.html#privacy) в ответе. К ним относятся данные, которые рассчитываются алгоритмами Яндекса, например, социально-демографические (пол, возраст и др.), адреса страниц входа, поисковые фразы, информация о роботах. При значении `true` в ответе не отобразятся такие данные, если выборка составляет меньше 10 посетителей.
Возможные значения: `true`, `false`.
{.table-cell}
||
||

_data_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [ComparisonRowStaticAB](#entity-ComparisonRowStaticAB)[]

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  {
    "dimensions": [
      {}
    ],
    "metrics": {
      "a": [
        0.5
      ],
      "b": [
        0.5
      ]
    }
  }
]
```

{% endcut %}
{.table-cell}
||
||

_data_lag_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: integer

Задержка в обновлении данных, в секундах.
{.table-cell}
||
||

_query_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [ComparisonQueryAB](#entity-ComparisonQueryAB)

Исходный запрос. Содержит параметры запроса, включая развернутые параметры из шаблона и параметры для схемы параметризации атрибутов.

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "timezone": "example",
  "preset": "example",
  "dimensions": [
    "example"
  ],
  "metrics": [
    "example"
  ],
  "sort": [
    "example"
  ],
  "date1_a": "example",
  "date2_a": "example",
  "filters_a": "example",
  "date1_b": "example",
  "date2_b": "example",
  "filters_b": "example",
  "limit": 0,
  "offset": 0
}
```

{% endcut %}
{.table-cell}
||
||

_sample_share_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: number

Доля данных, по которым осуществлялся расчет. Доступно значение в пределах от 0 до 1.
{.table-cell}
||
||

_sample_size_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: integer

Количество строк в выборке данных.
{.table-cell}
||
||

_sample_space_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: integer

Количество строк данных.
{.table-cell}
||
||

_sampled_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: boolean

Признак семплирования. Показывает, был ли применен семплинг. Возможные значения: `true`, `false`.
{.table-cell}
||
||

_total_rows_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: integer

Общее количество строк в ответе по всему множеству данных (с учетом фильтра).
{.table-cell}
||
||

_total_rows_rounded_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: boolean

Признак того, что общее количество строк было округлено.
{.table-cell}
||
||

_totals_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [ComparisonDataAB](#entity-ComparisonDataAB)

Общие результаты для метрик по всему множеству данных (с учетом фильтра).

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "a": [
    0.5
  ],
  "b": [
    0.5
  ]
}
```

{% endcut %}
{.table-cell}
||
|#{.json-schema-properties}

</div>

<div class="openapi-entity">

### ComparisonQueryAB {#entity-ComparisonQueryAB}

Исходный запрос. Содержит параметры запроса, включая развернутые параметры из шаблона и параметры для схемы параметризации атрибутов.

#|
|| **Name** | **Description** ||
||

_date1_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата начала периода выборки для сегмента A в формате YYYY-MM-DD.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_date1_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата начала периода выборки для сегмента B в формате YYYY-MM-DD.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_date2_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата окончания периода выборки для сегмента A в формате YYYY-MM-DD.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_date2_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Дата окончания периода выборки для сегмента B в формате YYYY-MM-DD.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_dimensions_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string[]

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  "example"
]
```

{% endcut %}
{.table-cell}
||
||

_filters_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Фильтр сегментации для сегмента A.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_filters_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Фильтр сегментации для сегмента B.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_limit_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: integer

Количество элементов на странице выдачи.
{.table-cell}
||
||

_metrics_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string[]

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  "example"
]
```

{% endcut %}
{.table-cell}
||
||

_offset_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: integer

Индекс первой строки выборки, начиная с 1.
{.table-cell}
||
||

_preset_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Пресет отчета.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_sort_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string[]

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  "example"
]
```

{% endcut %}
{.table-cell}
||
||

_timezone_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Часовой пояс периода выборки в формате ±hh:mm.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
|#{.json-schema-properties}

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "timezone": "example",
  "preset": "example",
  "dimensions": [
    "example"
  ],
  "metrics": [
    "example"
  ],
  "sort": [
    "example"
  ],
  "date1_a": "example",
  "date2_a": "example",
  "filters_a": "example",
  "date1_b": "example",
  "date2_b": "example",
  "filters_b": "example",
  "limit": 0,
  "offset": 0
}
```

{% endcut %}

</div>

<div class="openapi-entity">

### ComparisonDataAB {#entity-ComparisonDataAB}

Общие результаты для метрик по всему множеству данных (с учетом фильтра).

#|
|| **Name** | **Description** ||
||

_a_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: number[]

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  0.5
]
```

{% endcut %}
{.table-cell}
||
||

_b_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: number[]

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  0.5
]
```

{% endcut %}
{.table-cell}
||
|#{.json-schema-properties}

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "a": [
    0.5
  ],
  "b": [
    0.5
  ]
}
```

{% endcut %}

</div>

<div class="openapi-entity">

### ComparisonRowStaticAB {#entity-ComparisonRowStaticAB}

Строки ответа. Представляет собой массив, каждый элемент которого — одна строка результата.

#|
|| **Name** | **Description** ||
||

_dimensions_{.json-schema-reset .json-schema-property}
{.table-cell}|
{% cut "**Type**: object[]" %}

#|
||

_[additional]_{.json-schema-reset .json-schema-additional-property}
{.table-cell}|
**Type**: string

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
|#{.json-schema-properties}

{% endcut %}

Массив значений группировок для данной строки. Каждое из значений группировки представляет собой объект. В нем обязательно присутствует поле `name` — текстовое значение, но могут присутствовать дополнительные поля, например идентификатор — `id`.

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  {}
]
```

{% endcut %}
{.table-cell}
||
||

_metrics_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [ComparisonDataAB](#entity-ComparisonDataAB)

Общие результаты для метрик по всему множеству данных (с учетом фильтра).

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "a": [
    0.5
  ],
  "b": [
    0.5
  ]
}
```

{% endcut %}
{.table-cell}
||
|#{.json-schema-properties}

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "dimensions": [
    {}
  ],
  "metrics": {
    "a": [
      0.5
    ],
    "b": [
      0.5
    ]
  }
}
```

{% endcut %}

</div>

</div>

</div>

[*Deprecated]: No longer supported, please use an alternative and newer version.