# Yandex Metrica


> **Информация:**

This integration has `@beta` status. Follow the [player changelog](https://docs.kinescope.com/player-docs/changelog/).



The player can send viewing events to Yandex Metrica. Create a goal in your counter and enable the integration in the player or through the API.

## Configure a goal in Metrica {#ym-setup}

Add a goal in the counter settings:

| Field | Value |
| :--- | :--- |
| **Name** | Any clear name |
| **Condition type** | JavaScript event |
| **Goal ID** | Exactly `kinescope.video_event` |

## Enable the integration in the player {#player-setup}

**In the dashboard:** enable the Yandex Metrica integration in the player settings and enter the counter ID.

**Through the IFrame API:** pass the counter ID in `settings.yandexMetrics` when you call [`create()`](https://docs.kinescope.com/player-docs/embedding/iframe-api-create-player/#create):

```js
playerFactory.create('player', {
  url: 'https://kinescope.io/VIDEO_ID',
  settings: { yandexMetrics: '000000000' },
})
```

## Integration script for iframe {#PlayerSetupIframe}

If the player runs in an `<iframe>` through [simple embedding](https://docs.kinescope.com/player-docs/embedding/simple-iframe-embed/) or the [IFrame API](https://docs.kinescope.com/player-docs/embedding/iframe-api/), add:

`https://player.kinescope.io/latest/iframe.ym.js`

Place the script **after** the Yandex Metrica code. Without it, iframe events do not reach Metrica.

### Simple embedding example

```html
<head>
  <!-- 1. Yandex Metrica -->
  <script>
    // Counter initialization code from the Metrica interface
  </script>

  <!-- 2. Integration script after Metrica -->
  <script src="https://player.kinescope.io/latest/iframe.ym.js"></script>
</head>
<body>
  <iframe
    src="https://kinescope.io/embed/VIDEO_ID"
    allow="autoplay; fullscreen; picture-in-picture; encrypted-media; gyroscope; accelerometer; clipboard-write; screen-wake-lock;"
    style="border: none;"
  ></iframe>
</body>
```

In this setup, enter the Metrica counter ID in the [player settings](#player-setup) in the dashboard.

### IFrame API example

```html
<html>
  <head>
    <!-- 1. Yandex Metrica -->
    <script>
      // Yandex Metrica initialization code
    </script>

    <!-- 2. Integration script after Metrica -->
    <script src="https://player.kinescope.io/latest/iframe.ym.js"></script>

    <!-- 3. IFrame API -->
    <script>
      function onKinescopeIframeAPIReady(playerFactory) {
        playerFactory.create('player', {
          url: 'https://kinescope.io/VIDEO_ID',
          settings: { yandexMetrics: '000000000' },
        })
      }
    </script>
    <script async src="https://player.kinescope.io/latest/iframe.player.js"></script>
  </head>
  <body>
    <div id="player"></div>
  </body>
</html>
```

## Next steps

- [Google Analytics](https://docs.kinescope.com/player-docs/google-analytics/) — send player events to GA4 and GTM
- [Simple iframe embedding](https://docs.kinescope.com/player-docs/embedding/simple-iframe-embed/)
- [Create a player](https://docs.kinescope.com/player-docs/embedding/iframe-api-create-player/) — configure the `settings` parameter

