[Yandex Cloud documentation](../../../../index.md) > [Yandex Data Transfer](../../../index.md) > [Step-by-step guides](../../index.md) > [Configuring endpoints](../index.md) > Metrica > Source

# Transferring data from a Yandex Metrica source endpoint


Data Transfer enables you to transfer data from a [Yandex Metrica](https://metrika.yandex.com/) tag to a Yandex Cloud managed database.

1. [Explore possible data transfer scenarios](#scenarios).
1. [Set up a source endpoint](#endpoint-settings) in Yandex Data Transfer.
1. [Set up one of the supported data targets](#supported-targets).
1. [Create](../../transfer.md#create) a transfer and [start](../../transfer.md#activate) it.
1. Perform required operations with the database and [control the transfer](../../monitoring.md).
1. In case of any issues, [use ready-made solutions](../../../troubleshooting/index.md) to resolve them.

## Scenarios for transferring data from Yandex Metrica {#scenarios}

Data Transfer enables you to transfer metrics from [Yandex Metrica](https://metrika.yandex.com/) to a ClickHouse® cluster. This approach guarantees the completeness of the data transferred from Yandex Metrica and allows:

* Processing data with ClickHouse® tools.
* Streaming data from ClickHouse® to other locations.
* Visualizing data with [Yandex DataLens](https://datalens.ru/promo) or other services.

See [this tutorial](../../../tutorials/metrika-to-clickhouse.md) on how to transfer Yandex Metrica tag data to a ClickHouse® cluster.

For a detailed description of other possible Yandex Data Transfer scenarios, see [Tutorials](../../../tutorials/index.md).

## Configuring the Metrica source endpoint {#endpoint-settings}

{% note info %}

You can transfer data from a Yandex Metrica source if the [Metrica Pro](https://yandex.com/support/metrica/pro/intro.html) package is enabled or when using [Data Streaming from Yandex Metrica](https://yandex.cloud/en/marketplace/products/varioqub/metrica-data-streaming).

{% endnote %}

When [creating](../index.md#create) or [updating](../index.md#update) an endpoint, configure access to [Yandex Metrica](https://metrika.yandex.com/).

{% list tabs group=instructions %}

- Management console {#console}

    * **Tag numbers**: Specify the [numbers of the tags](https://yandex.ru/support/metrica/general/tag-id.html) the data will be coming from.
    * **Token**: Specify the token required to access the tags. To obtain it, follow [this link](https://oauth.yandex.ru/authorize?response_type=token&client_id=36b7fc9aa96c4fa09158bcacbbdc796a).
    * Optionally, specify a time interval to export data for. This option is supported for the **Snapshot and increment** transfer type. The end date must be at least 7 days later than the start date.
    * **Hits**: Select whether information about hits should be transferred.
        * **Fields**: Select the hit fields to export. In addition to the fields you select, there are certain mandatory fields that are always exported.
    * **Sessions**: Select whether information about sessions (visits) should be transferred.
        * **Fields**: Select the session fields to export. In addition to the fields you select, there are certain mandatory fields that are always exported.

- Terraform {#tf}

    * Endpoint type: `metrika_source`.

    * `counter_ids`: [Numbers of the tags](https://yandex.ru/support/metrica/general/tag-id.html) that will send data.

    * `token.raw`: Token required to access the tags. To obtain it, follow [this link](https://oauth.yandex.ru/authorize?response_type=token&client_id=36b7fc9aa96c4fa09158bcacbbdc796a).

    * `streams`: Parameters of transmitted data:
      
      * `type`: Data type. Specify one of these values:
      
         * `METRIKA_STREAM_TYPE_HITS`: Hits (obsolete, not updated)
         * `METRIKA_STREAM_TYPE_HITS_V2`: Hits
         * `METRIKA_STREAM_TYPE_VISITS`: Visits
      
      * `columns`: List of fields to export. You can view them in the management console. In addition to the fields you select, there are certain required fields that are always exported.

    Here is an example of the configuration file structure:

    ```hcl
    resource "yandex_datatransfer_endpoint" "<endpoint_name_in_Terraform>" {
      name = "<endpoint_name>"
      settings {
        metrika_source {
          counter_ids = [<tag_numbers>]
          token {
            raw = "<token>"
          }
          streams {
            type    = "<data_type>"
            columns = ["<field_list>"]
          }
        }
      }
    }
    ```

- API {#api}

    * `counterIds`: [Numbers of the tags](https://yandex.ru/support/metrica/general/tag-id.html) that will send data.

    * `token.raw`: Token required to access the tags. To obtain it, follow [this link](https://oauth.yandex.ru/authorize?response_type=token&client_id=36b7fc9aa96c4fa09158bcacbbdc796a).

    * `streams`: Parameters of transmitted data:
      
      * `type`: Data type. Specify one of these values:
      
         * `METRIKA_STREAM_TYPE_HITS`: Hits (obsolete, not updated)
         * `METRIKA_STREAM_TYPE_HITS_V2`: Hits
         * `METRIKA_STREAM_TYPE_VISITS`: Visits
      
      * `columns`: List of fields to export. You can view them in the management console. In addition to the fields you select, there are certain required fields that are always exported.

{% endlist %}

For more about the settings, see [this guide](https://yandex.com/support/metrica/index.html).

## Configuring the data target {#supported-targets}

Configure the supported data target:

* [ClickHouse®](../target/clickhouse.md).

For a full list of sources and targets supported in Yandex Data Transfer, see [Available transfers](../../../transfer-matrix.md).

After configuring the data source and target, [create and start the transfer](../../transfer.md#create).

_ClickHouse® is a registered trademark of [ClickHouse, Inc](https://clickhouse.com)._