Comparing segments

Used to compare two data segments. Segments are identified as segment A and segment B. You can set different date ranges and segmentation filters for each segment. Data will be presented in a table. Each row in the report has two sets of metrics: metrics for segment A, and metrics for segment B. See an example with this request.

Request

GET

https://api-metrika.yandex.net/stat/v1/data/comparison

Query parameters

Name

Description

ids

Type: integer[]

Comma-separated list of tag IDs.

Example: 44147844,2215573

metrics

Type: string

List of metrics separated by comma. Limit: 20 metrics per request.

Example: ym:s:pageviews

accuracy

Type: string

Sample size for the report. Use it to control the sampling rate (the number of sessions used for calculating results).

Example: ``

callback

Type: string

Callback function that processes the API response.

Example: ``

date1_a

Type: string

Start date of the sample period for segment A in YYYY-MM-DD format. You can also use the values today, yesterday, and ndaysAgo.

Default: 6daysAgo

Example: ``

date1_b

Type: string

Start date of the sample period for segment B in YYYY-MM-DD format. You can also use the values today, yesterday, and ndaysAgo.

Default: 6daysAgo

Example: ``

date2_a

Type: string

End date of the sample period for segment A in YYYY-MM-DD format. You can also use the values today, yesterday, and ndaysAgo.

Default: today

Example: ``

date2_b

Type: string

End date of the sample period for segment B in YYYY-MM-DD format. You can also use the values today, yesterday, and ndaysAgo.

Default: today

Example: ``

dimensions

Type: string

Comma-separated list of dimensions. Limit: 10 dimensions per request.

Example: ym:s:trafficSource

direct_client_logins

Type: string[]

Comma-separated usernames of Yandex Direct clients. Can be used for generating the Yandex Direct — costs report.

Example: login1,login2

filters

Type: string

Segmentation filter. Limits: up to 10 unique dimensions and metrics; up to 20 separate filters; up to 10,000 characters per filter row; and up to 100 values per filtering criteria.

Example: ``

filters_a

Type: string

Segmentation filter for segment A.

Example: ``

filters_b

Type: string

Segmentation filter for segment A.

Example: ``

include_undefined

Type: boolean

The response will include rows that don't have defined dimension values. This only affects the first dimension. Disabled by default.

lang

Type: string

Language.

Example: ``

limit

Type: string

Number of items on the results page. Limit: 100,000.

Default: 100

Example: ``

offset

Type: string

Index of the first row of requested data, starting from 1.

Default: 1

Example: ``

preset

Type: string

Report presets.

Example: sources_summary

pretty

Type: string

Specifies the formatting for results. To use formatting, set the value to true.

Default: false

Example: ``

proposed_accuracy

Type: boolean

If the parameter is set to true, the API may automatically increase the accuracy to the recommended level. This can help you get meaningful results when querying small tables containing a very small sample of data.

sort

Type: string

Comma-separated list of dimensions and metrics to use for sorting. By default, data is sorted in descending order (indicated by the - symbol in front of the dimension or metric). To sort data in ascending order, remove the - symbol.

Example: ``

timezone

Type: string

Time zone in ±hh:mm format within the range of [-23:59; +23:59] (the plus sign should be denoted as %2B). This time zone is used to calculate the request sample period as well as the date- and time-specific dimensions. By default, the tag's time zone is used.

Example: +03:00

Responses

200 OK

OK

Body

application/json
{
  "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
}

Name

Description

contains_sensitive_data

Type: boolean

Indicates whether sensitive data can be omitted from the response. Such data includes data calculated by Yandex algorithms: demographic data (gender, age, and other), login page addresses, search phrases, and robot information. If the value is true, the response will not display such data if the sample is less than 10 users. Possible values: true, false.

data

Type: ComparisonRowStaticAB[]

Example
[
  {
    "dimensions": [
      {}
    ],
    "metrics": {
      "a": [
        0.5
      ],
      "b": [
        0.5
      ]
    }
  }
]

data_lag

Type: integer

Delay in updating data, in seconds.

query

Type: ComparisonQueryAB

Original request. Contains the request parameters, including detailed parameters from the template and parameters for attribute parametrization.

Example
{
  "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
}

sample_share

Type: number

Share of data used for the calculation. Available value ranges from 0 to 1.

sample_size

Type: integer

Number of rows in the data sample.

sample_space

Type: integer

Number of data rows.

sampled

Type: boolean

Sampling flag. Indicates whether sampling was applied. Possible values: true, false.

total_rows

Type: integer

The total number of rows in the response for the entire dataset (after filtering).

total_rows_rounded

Type: boolean

Indicates that the total number of rows was rounded.

totals

Type: ComparisonDataAB

Total results for metrics across the entire dataset (after filtering).

Example
{
  "a": [
    0.5
  ],
  "b": [
    0.5
  ]
}

ComparisonQueryAB

Original request. Contains the request parameters, including detailed parameters from the template and parameters for attribute parametrization.

Name

Description

date1_a

Type: string

Start date of the sample period for segment A in YYYY-MM-DD format.

Example: example

date1_b

Type: string

Start date of the sample period for segment B in YYYY-MM-DD format.

Example: example

date2_a

Type: string

End date of the sample period for segment A in YYYY-MM-DD format.

Example: example

date2_b

Type: string

End date of the sample period for segment B in YYYY-MM-DD format.

Example: example

dimensions

Type: string[]

Example
[
  "example"
]

filters_a

Type: string

Segmentation filter for segment A.

Example: example

filters_b

Type: string

Segmentation filter for segment B.

Example: example

limit

Type: integer

Number of items on the results page.

metrics

Type: string[]

Example
[
  "example"
]

offset

Type: integer

Index of the first row of requested data, starting from 1.

preset

Type: string

Report preset.

Example: example

sort

Type: string[]

Example
[
  "example"
]

timezone

Type: string

Time zone of the sample period in ±hh:mm format.

Example: example

Example
{
  "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
}

ComparisonDataAB

Total results for metrics across the entire dataset (after filtering).

Name

Description

a

Type: number[]

Example
[
  0.5
]

b

Type: number[]

Example
[
  0.5
]
Example
{
  "a": [
    0.5
  ],
  "b": [
    0.5
  ]
}

ComparisonRowStaticAB

Response rows. An array in which each item is a single row of the result.

Name

Description

dimensions

Type: object[]

[additional]

Type: string

Example: example

Array of dimension values for this row. Each dimension value is an object. It must have the name field, which is a text value. But it can also have additional fields, such as id.

Example
[
  {}
]

metrics

Type: ComparisonDataAB

Total results for metrics across the entire dataset (after filtering).

Example
{
  "a": [
    0.5
  ],
  "b": [
    0.5
  ]
}
Example
{
  "dimensions": [
    {}
  ],
  "metrics": {
    "a": [
      0.5
    ],
    "b": [
      0.5
    ]
  }
}