---
metadata:
  - name: generator
    content: Diplodoc Platform v5.48.2
alternate:
  - https://yandex.com/dev/metrika/en/stat/examples.md
  - https://yandex.com/dev/metrika/ru/stat/examples.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/metrika/en/llms.txt

# Examples

The examples provided below are helpful for solving common tasks.

These requests don't define the `date1` and `date2`parameters (the dates of the beginning and end of the reporting period). By default, the reporting period is 7 days (including the current day).

A demo tag is used as the `id` parameter.

The [/stat/v1/data](https://yandex.com/dev/metrika/en/stat/openapi/data.md) method is used for making requests.

{% note info %}

The request language (`lang` parameter) affects the filter values. Specify the `lang=ru` parameter for Russian names. For example, `ym:s:regionCityName=='Saint Petersburg'`.

{% endnote %}

## Presets {#preset}

### “Sources, summary” report {#ex1}

`preset=sources_summary`

```
https://api-metrika.yandex.net/stat/v1/data?preset=sources_summary&id=44147844
```

### "Sources, summary" report. Users from Saint Petersburg {#ex2}

`preset=sources_summary`

`filters=ym:s:regionCityName=='Saint Petersburg'`

The report data is a segmented using the parameter `filters=ym:s:regionCityName=='Saint Petersburg'`.

```
https://api-metrika.yandex.net/stat/v1/data?preset=sources_summary&filters=ym:s:regionCityName=='Санкт-Петербург'&id=44147844&lang=ru
```

### "Keywords" report {#ex3}

`preset=sources_search_phrases`

```
https://api-metrika.yandex.net/stat/v1/data?preset=sources_search_phrases&id=44147844
```

### "Browsers" report {#ex4}

`preset=tech_platforms`

`dimensions=ym:s:browser`

This preset helps create a report on user browsers, without accounting for the browser version.

```
https://api-metrika.yandex.net/stat/v1/data?preset=tech_platforms&dimensions=ym:s:browser&id=44147844
```

where the parameter `dimensions=ym:s:browser` sets a dimension in the preset for grouping resulting data.

### Content analytics {#ex5}

**Traffic sources**

:   This preset helps you create a report on sources from which users clicked through to the site content.

    `preset=publishers_sources`
    ```
    https://api-metrika.yandex.net/stat/v1/data?preset=publishers_sources&id=44147844&date1=today&date2=today
    ```

**Categories**

:   Use this preset to create a report with general statistics by category.

    `preset=publishers_rubrics`
    
    ```
    https://api-metrika.yandex.net/stat/v1/data?preset=publishers_rubrics&id=44147844&date1=today&date2=today
    ```

**Authors**

:   Use this preset to generate a standard report with statistics on the authors of your website's articles.

    `preset=publishers_authors`
    
    ```
    https://api-metrika.yandex.net/stat/v1/data?preset=publishers_authors&id=44147844&date1=today&date2=today
    ```

**Topics**

:   Use this preset to generate a standard report on the topics of the website's articles.

    `publishers_thematics`
    
    ```
    https://api-metrika.yandex.net/stat/v1/data?publishers_thematics&id=44147844&date1=today&date2=today
    ```

## Segmentation {#segment}

### Types of traffic sources {#ex0}

`dimensions=ym:s:lastTrafficSource`

`metrics=ym:s:visits,ym:s:users`

`filters=ym:s:lastTrafficSource=.('organic','direct','referral')`

```
https://api-metrika.yandex.net/stat/v1/data?dimensions=ym:s:lastTrafficSource&metrics=ym:s:visits,ym:s:users&filters=ym:s:lastTrafficSource=.('organic','direct','referral')&id=44147844&lang=ru
```

### Number of sessions and users from search engines {#visits}

`dimensions=ym:s:searchEngine`

`metrics=ym:s:visits,ym:s:users`

`filters=ym:s:trafficSource=='organic'`

```
https://api-metrika.yandex.net/stat/v1/data?dimensions=ym:s:searchEngine&metrics=ym:s:visits,ym:s:users&filters=ym:s:trafficSource=='organic'&id=44147844
```

### Number of sessions and users from search engines without robot sessions {#robots}

Yandex Metrica identifies robots based on behavioral patterns and other technical signals. Filtering robots in Yandex Metrica reports helps you get accurate data. For example, bounce rate, time on site, and page depth. To learn more, see [Help](https://yandex.com/support/metrica/general/robots.html).

`dimensions=ym:s:searchEngine`

`metrics=ym:s:visits,ym:s:users`

`filters=ym:s:trafficSource=='organic' AND ym:s:isRobot=='No'`

```
https://api-metrika.yandex.net/stat/v1/data?dimensions=ym:s:searchEngine&metrics=ym:s:visits,ym:s:users&filters=ym:s:trafficSource=='organic' AND ym:s:isRobot=='No'&id=44147844
```

### Number of sessions and new users from search engines {#search}

`dimensions=ym:s:searchEngine`

`metrics=ym:s:visits,ym:s:users`

`filters=ym:s:trafficSource=='organic' AND ym:s:isNewUser=='Yes'`

```
https://api-metrika.yandex.net/stat/v1/data?dimensions=ym:s:searchEngine&metrics=ym:s:visits,ym:s:users&filters=ym:s:trafficSource=='organic' AND ym:s:isNewUser=='Yes'&id=44147844
```

### Number of sessions and users, including the specified region {#segment}

`metrics=ym:s:visits,ym:s:users`

`filters=ym:s:regionCityName=.('Moscow','Saint Petersburg')`

```
https://api-metrika.yandex.net/stat/v1/data?metrics=ym:s:visits,ym:s:users&filters=ym:s:regionCityName=.('Москва','Санкт-Петербург')&id=44147844&lang=ru
```

```
https://api-metrika.yandex.net/stat/v1/data?metrics=ym:s:visits,ym:s:users&filters=ym:s:regionCityName=.('Moscow','Saint Petersburg')&id=44147844
```

### Number of sessions with depth greater than 5 pages {#page-view}

`metrics=ym:s:visits`

`filters=ym:s:pageViews>5`

```
https://api-metrika.yandex.net/stat/v1/data?metrics=ym:s:visits&filters=ym:s:pageViews>5&id=44147844
```

## Dimensions and metrics {#dim-metrics}

### Number of sessions {#dim-metrics}

`metrics=ym:s:visits`

```
https://api-metrika.yandex.net/stat/v1/data?metrics=ym:s:visits&id=44147844
```

### Number of users and conversion rate for a specified goal {#conv}

This example features parameterization of the metric `ym:s:goal<goal_id>conversionRate` with a goal ID:

`metrics=ym:s:users,ym:s:goal<goal_id>conversionRate`

`dimensions=ym:s:trafficSource`

`goal_id=<goal identifier>`

The report will include the number of users who reached the specified goal. Data is grouped by traffic source.

```
https://api-metrika.yandex.net/stat/v1/data?dimensions=ym:s:trafficSource&metrics=ym:s:users,ym:s:goal%3Cgoal_id%3EconversionRate&goal_id=30606879&id=44147844
```

### Conversion rate for multiple goals  {#conv-mult}

This example features parameterization of the metric `ym:s:goal<goal_id>conversionRate` with a goal ID in the expression body.

```
metrics=ym:s:users,ym:s:goal<first goal identifier>conversionRate,ym:s:goal<second goal identifier>conversionRate
```

```
https://api-metrika.yandex.net/stat/v1/data?metrics=ym:s:users,ym:s:goal30606879conversionRate,ym:s:goal30606884conversionRate&id=44147844
```

### Segment report for an experiment in Yandex Direct {#dim-metrics}

This example features parameterization of the dimension `ym:s:experimentAB<experiment_ab>`.

`metrics=ym:s:bounceRate`

`dimensions=ym:s:experimentAB123`, where 123 is the experiment ID.

```
https://api-metrika.yandex.net/stat/v1/data?id=44147844;&metrics=ym:s:bounceRate&dimensions=ym:s:experimentAB123
```

### Content analytics. Material report {#content}

Report on the number of views of site content. Data is grouped by article.

`dimensions=ym:s:publisherArticle`

`metrics=ym:s:publisherviews`

`filters=(ym:s:publisherArticle!n)`

`sort=-ym:s:publisherviews`

```
https://api-metrika.yandex.net/stat/v1/data?ids=44147844&date1=2019-10-01&date2=2019-10-01&dimensions=ym:s:publisherArticle&metrics=ym:s:publisherviews&filters=(ym:s:publisherArticle!n)&sort=-ym:s:publisherviews
```

## Displaying data by time {#query}

The [/stat/v1/data/bytime](https://yandex.com/dev/metrika/en/stat/openapi/bytime.md) method is used for getting data.

The examples below show how to get data for a specific period of time. This data can be grouped together. To define the type or number of groups (`dimensions`), use the `row_ids` or `top_keys` parameter. If the `row_ids` parameter is omitted, the `top_keys`parameter is used automatically. By default, it is set to 7 (the maximum is 30).

{% cut "More information about parameters" %}

- `row_ids` — Array of arrays in JSON format. Each sub-array may contain [dimension values](https://yandex.com/dev/metrika/en/stat/localize.md) (`name` or `id`) corresponding to the set of values defined in the request for the `dimensions` parameter. The size of a sub-array indicates the dimensions that data will be grouped by.

    For example, if data is grouped by a single dimension, the size of this sub-array is 1.

    ```
    ...?row_ids=[["Russia"]]&...&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&...
    ```

    {% note info %}

    If a sub-array contains dimension values for a single group (for example, [Geography](https://yandex.com/dev/metrika/en/stat/attributes/visitsaudience_/geo.md)), data is grouped by the last specified dimension.

    ```
    ...?row_ids=[["Russia","Saratov region","Saratov"]]&...&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&...
    ```

    {% endnote %}

    To use multiple sub-arrays, separate them with commas:

    ```
    ...?row_ids=[["Russia"],["Russia","Saratov region"],["Russia","Saratov region","Saratov"]]&...&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&...
    ```

- The `top_keys` parameter selects the top values from the first dimension specified in the request. You can set the quantity of these values (30 maximum). Data is sorted in the API response by decreasing order of the first value of the `metrics` parameter.

    ```
    ...?top_keys=3&...&dimensions=ym:s:regionCountry,ym:s:regionArea,ym:s:regionCity&group=day&ids=44147844&metrics=ym:s:visits
    ```

{% endcut %}

### “Sources, summary” report {#query}

In the example, the response will contain data grouped by the type of traffic source.

Example without the `row_ids` parameter. The `top_keys` parameter is used by default:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:<attribution>TrafficSource&attribution=last&ids=44147844&metrics=ym:s:visits
```

Example with a value set for the `top_keys` parameter:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?top_keys=3&date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:<attribution>TrafficSource&attribution=last&ids=44147844&metrics=ym:s:visits
```

The examples below show reports that specify dimension values for the [Sources](https://yandex.com/dev/metrika/en/stat/attributes/visits/source.md) group.

Traffic sources for the day:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["direct"],["organic","organic.yandex"],["social","social.ya"],["ad"]]&date1=2018-01-13&date2=2018-01-13&group=day&dimensions=ym:s:<attribution>TrafficSource,ym:s:<attribution>SourceEngine&attribution=last&ids=44147844&metrics=ym:s:visits
```

Traffic sources for two weeks, grouped by days:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["direct"],["organic","organic.yandex"],["social","social.ya"],["ad"]]&date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:<attribution>TrafficSource,ym:s:<attribution>SourceEngine&attribution=last&ids=44147844&metrics=ym:s:visits
```

Traffic sources for two weeks, grouped by weeks. Data is grouped by calendar weeks:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["direct"],["organic","organic.yandex"],["social","social.ya"],["ad"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:<attribution>TrafficSource,ym:s:<attribution>SourceEngine&attribution=last&ids=44147844&metrics=ym:s:visits
```

### “Users — Geography” report {#query}

In this example, the report will contain data on the number of users, grouped by geographical location.

Example without the `row_ids` parameter. The `top_keys` parameter is used by default:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:regionCountry,ym:s:regionArea,ym:s:regionCity&ids=44147844&metrics=ym%3As%3Avisits
```

Example with a value set for the `top_keys` parameter:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?top_keys=3&date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:regionCountry,ym:s:regionArea,ym:s:regionCity&ids=44147844&metrics=ym%3As%3Avisits
```

The examples below show reports that specify dimension values for the [Geography](https://yandex.com/dev/metrika/en/stat/attributes/visitsaudience_/geo.md) group.

The number of sessions from Russia, the Saratovskaya region, and Saratov over two weeks. Data is grouped by calendar weeks:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Russia"],["Russia","Saratov%20region"],["Russia","Saratov%20region","Saratov"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&ids=44147844&metrics=ym%3As%3Avisits&lang=ru
```

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Russia"],["Russia","Saratov%20region"],["Russia","Saratov%20region","Saratov"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&ids=44147844&metrics=ym%3As%3Avisits
```

The number of sessions from Russia, Moscow and the Moscow region, Saint Petersburg, and the Leningradskaya region over two weeks:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Russia"],["Russia","Moscow%20and%20Moscow%20region"],["Russia","Saint%20Petersburg%20and%20Leningrad%20region"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&ids=44147844&metrics=ym%3As%3Avisits&lang=ru
```

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Russia"],["Russia","Moscow%20and%20Moscow%20region"],["Russia","Saint%20Petersburg%20and%20Leningrad%20region"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:regionCountryName,ym:s:regionAreaName,ym:s:regionCityName&ids=44147844&metrics=ym%3As%3Avisits
```

### Report on operating systems and browsers {#query}

In this example, the report will contain data on the number of users, grouped by the type of operating system they are using.

Example without the `row_ids` parameter. The `top_keys` parameter is used by default:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:operatingSystemRootName,ym:s:browserName&ids=44147844&accuracy=medium&metrics=ym:s:visits
```

Example with a value set for the `top_keys` parameter:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?top_keys=10&date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:operatingSystemRootName,ym:s:browserName&ids=44147844&accuracy=medium&metrics=ym:s:visits
```

The examples below show reports that specify dimension values for the [Operating systems](https://yandex.com/dev/metrika/en/stat/attributes/visitstechnology_/os.md) and [Browsers](https://yandex.com/dev/metrika/en/stat/attributes/visitstechnology_/browser.md) groups.

The number of sessions for users of Windows, Yandex Browser, and Internet Explorer. Data is grouped by days:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Windows"],["Windows","Yandex Browser"],["Windows","MSIE"]]&date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:operatingSystemRootName,ym:s:browserName&ids=44147844&accuracy=medium&metrics=ym:s:visits&lang=ru
```

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Windows"],["Windows","Yandex Browser"],["Windows","MSIE"]]&date1=2018-01-01&date2=2018-01-14&group=day&dimensions=ym:s:operatingSystemRootName,ym:s:browserName&ids=44147844&accuracy=medium&metrics=ym:s:visits
```

Data is grouped by calendar weeks:

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Windows"],["Windows","Yandex Browser"],["Windows","MSIE"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:operatingSystemRootName,ym:s:browserName&ids=44147844&accuracy=medium&metrics=ym:s:visits&lang=ru
```

```
https://api-metrika.yandex.net/stat/v1/data/bytime?row_ids=[["Windows"],["Windows","Yandex Browser"],["Windows","MSIE"]]&date1=2018-01-01&date2=2018-01-14&group=week&dimensions=ym:s:operatingSystemRootName,ym:s:browserName&ids=44147844&accuracy=medium&metrics=ym:s:visits
```

### The number of views per day for the last 30 days (chart) {#query}

In the example, data will be given for making a chart. The `/stat/v1/data/bytime` method is used for getting data.

`metrics=ym:s:hits`

`date1=30daysAgo`

`date2=today`

`group=day`

```
https://api-metrika.yandex.net/stat/v1/data/bytime?metrics=ym:s:hits&date1=30daysAgo&date2=today&group=day&id=44147844
```

## Comparing segments {#comparison}

The [/stat/v1/data/comparison](https://yandex.com/dev/metrika/en/stat/openapi/comparison.md) method is used for comparing data.

### Comparison of two days {#comparison}

In this example, the number of users is compared. Data is grouped by traffic source.

`metrics=ym:s:users`

`dimensions=ym:s:trafficSource`

`date1_a=today`

`date1_b=yesterday`

```
https://api-metrika.yandex.net/stat/v1/data/comparison?metrics=ym:s:users&dimensions=ym:s:trafficSource&date1_a=today&date1_b=yesterday&id=44147844
```

### Comparing sessions from mobile and non-mobile devices {#comparison}

In this example, the number of users and bounce rate are compared. Data is grouped by traffic source.

`metrics=ym:s:users,ym:s:bounceRate`

`dimensions=ym:s:trafficSource`

`filters_a=ym:s:isMobile=='Yes'`

`filters_b=ym:s:isMobile=='No'`

```
https://api-metrika.yandex.net/stat/v1/data/comparison?metrics=ym:s:users,ym:s:bounceRate&dimensions=ym:s:trafficSource&filters_a=ym:s:isMobile=='Yes'&filters_b=ym:s:isMobile=='No'
```

## Drilldown {#drilldown}

The [/stat/v1/data/drilldown](https://yandex.com/dev/metrika/en/stat/openapi/drilldown.md) method is used for getting data.

### “Operating systems” report in tree view {#drilldown}

To generate the “Operating systems” report in tree view:

1. Send a request for getting top-level data, using the [tech_platforms](https://yandex.com/dev/metrika/en/stat/presets/preset_tech.md) preset (the**Operating systems** report).

    ```
    https://api-metrika.yandex.net/stat/v1/data/drilldown?preset=tech_platforms&id=44147844
    ```

2. In the response, the `expand` parameter has the value `true`. This means that the node can be expanded to the next level. In our case, we can get information about the operating system version.

    ```xml translate=no
    ...
    {
        "dimension": {
            "id": "100",
            "name": "Windows"
        },
        "metrics": [
            21779,
            52056,
            17.7786,
            2.39019,
            182.664
        ],
        "expand": true
    }
    ...
    ```

    To do this, we define the path to this level from the root in the `parent_id` parameter. Since the `id` element of the `dimension` parameter has the value `"100"`, the request will look like this:

    ```
    https://api-metrika.yandex.net/stat/v1/data/drilldown?preset=tech_platforms&id=44147844&parent_id=["100"]
    ```

    In the response, the `expand` parameter has the value `false`. In other words, this node can't be expanded further.
    
    ```xml translate=no
    ...
    {
        "dimension": {
            "id": "33",
            "name": "Windows 7 or 2008 Server"
        },
        "metrics": [
            14948,
            36300,
            7214,
            42842,
            048
        ],
        "expand": false
    }
    ...
    ```

## Access filters

You can use access filters to restrict the data shared from a specific tag for certain users. For more information, see [this article](https://yandex.com/support/metrica/general/access-filters).

To use access filters in a request, first get their IDs for the tag:

```
https://api-metrika.yandex.net/management/v1/counter/44147844/access_filters
```

Next, add the ID to the request using the `access_filter_id` parameter. For example:

```
https://api-metrika.yandex.net/stat/v1/data?ids=44147844&metrics=ym:s:visits&dimensions=ym:s:date&access_filter_id=12345
```
