# Vimeo media tracking on web
> Automatically track Vimeo video players embedded via iframe or Vimeo Player SDK with comprehensive playback and interaction events.
> Source: https://docs.snowplow.io/docs/sources/web-trackers/tracking-events/media/vimeo/
> Documentation index: https://docs.snowplow.io/llms.txt

This plugin enables the automatic tracking of a Vimeo video. It uses the [Snowplow Media plugin](/docs/sources/web-trackers/tracking-events/media/snowplow/) under the hood.

Vimeo media events and entities are **automatically tracked** once configured.

## Install plugin

**JavaScript (tag):**

| Tracker Distribution | Included |
| -------------------- | -------- |
| `sp.js`              | ❌        |
| `sp.lite.js`         | ❌        |

**Download:**

|                                             |                                                                                                               |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Download from GitHub Releases (Recommended) | [Github Releases (plugins.umd.zip)](https://github.com/snowplow/snowplow-javascript-tracker/releases)         |
| Available on jsDelivr                       | [jsDelivr](https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-vimeo-tracking@4.10.2/dist/index.umd.min.js) |
| Available on unpkg                          | [unpkg](https://unpkg.com/@snowplow/browser-plugin-vimeo-tracking@4.10.2/dist/index.umd.min.js)               |

```javascript
window.snowplow(
    'addPlugin',
    'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-vimeo-tracking@4.10.2/dist/index.umd.min.js',
    ['snowplowVimeoTracking', 'VimeoTrackingPlugin']
);
```

**Browser (npm):**

- `npm install @snowplow/browser-plugin-vimeo-tracking`
- `yarn add @snowplow/browser-plugin-vimeo-tracking`
- `pnpm add @snowplow/browser-plugin-vimeo-tracking`

```javascript
import { VimeoTrackingPlugin } from '@snowplow/browser-plugin-vimeo-tracking';

newTracker('sp1', '{{collector_url}}', {
   appId: 'my-app-id',
   plugins: [ VimeoTrackingPlugin() ],
});
```

***

## Quick Start

The snippets below show how to get started with the plugin, after [setting up your tracker](/docs/sources/web-trackers/tracker-setup/).

Using an `iFrame`:

**JavaScript (tag):**

```html
<iframe
  id='vimeo-iframe'
  src='https://player.vimeo.com/video/535907279?h=db7ea8b89c'
></iframe>
```

```javascript
const id = 'XXXXX'; // randomly generated ID
const video = document.getElementById('vimeo-iframe')

window.snowplow('startVimeoTracking', { id, video });

// Vimeo events are tracked...

window.snowplow('endVimeoTracking', id);
```

**Browser (npm):**

```html
<iframe
  id='vimeo-iframe'
  src='https://player.vimeo.com/video/535907279?h=db7ea8b89c'
></iframe>
```

```javascript
import { startVimeoTracking, endVimeoTracking } from '@snowplow/browser-plugin-vimeo-tracking'

const id = 'XXXXX'; // randomly generated ID
const video = document.getElementById('vimeo-iframe')

startVimeoTracking({ id, video })

// Vimeo events are tracked...

endVimeoTracking(id)
```

***

Using `Vimeo.Player`:

**JavaScript (tag):**

```html
<div id='vimeo-player'></div>
```

```javascript
const id = 'XXXXX'; // randomly generated ID
const video = new Vimeo.Player('vimeo-player', {
  videoId: 'zSM4ZyVe8xs'
});

window.snowplow('startVimeoTracking', { id, video });

// Vimeo events are tracked...

window.snowplow('endVimeoTracking', id);
```

**Browser (npm):**

```html
<div id='vimeo-player'></div>
```

```javascript
import { Player } from '@vimeo/player'
import { startVimeoTracking, endVimeoTracking } from '@snowplow/browser-plugin-vimeo-tracking'

const id = 'XXXXX'; // randomly generated ID
const video = new Player('vimeo-player', {
  videoId: 'zSM4ZyVe8xs'
});

startVimeoTracking({ id, video })

// Vimeo events are tracked...

endVimeoTracking(id)
```

***

## Start tracking

Use the `startVimeoTracking` function to begin tracking Vimeo media events. You must provide a unique `id` for the media session, along with the `video` element or `Vimeo.Player` instance.

| Parameter                                       | Type                                                                                                                 | Description                                                                                                                        | Default / Required            |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| `id`                                            | `string`                                                                                                             | A unique session UUID for each media element, used to identify and end tracking.                                                   | Required                      |
| `video`                                         | `HTMLIFrameElement` or `Player`                                                                                      | An `iframe` element, or an instance of `Vimeo.Player` created with the [Vimeo Player SDK](https://developer.vimeo.com/player/sdk). | Required                      |
| `label`                                         | `string`                                                                                                             | A custom human-readable label for the media element.                                                                               | `undefined`                   |
| `captureEvents`                                 | `VimeoEvent[]`                                                                                                       | A list of media events to track.                                                                                                   | All events tracked by default |
| `boundaries`                                    | `number[]`                                                                                                           | Percentage thresholds (0-100) to trigger progress events.                                                                          | `[10, 25, 50, 75]`            |
| `context`                                       | [`DynamicContext`](/docs/sources/web-trackers/custom-tracking-using-schemas/global-context/#global-contexts-methods) | Dynamic contexts attached to each tracking event.                                                                                  | `undefined`                   |
| `updatePageActivityWhilePlaying`                | `boolean`                                                                                                            | Whether to update page activity while media is playing.                                                                            | `true`                        |
| `filterOutRepeatedEvents`                       | `FilterOutRepeatedEvents`                                                                                            | Whether to suppress consecutive identical events.                                                                                  | Enabled by default            |
| `filterOutRepeatedEvents` `.seekEvents`         | `boolean`                                                                                                            | Whether to filter out seek start and end events tracked after each other.                                                          | `true`                        |
| `filterOutRepeatedEvents` `.volumeChangeEvents` | `boolean`                                                                                                            | Whether to filter out volume change events tracked after each other.                                                               | `true`                        |
| `filterOutRepeatedEvents` `.flushTimeoutMs`     | `number`                                                                                                             | Timeout in milliseconds after which to send the events that are queued for filtering.                                              | `5000` (milliseconds)         |
| `pings.pingInterval`                            | `number`                                                                                                             | Interval (in seconds) for sending ping events.                                                                                     | `30` (seconds)                |
| `pings.maxPausedPings`                          | `number`                                                                                                             | Maximum number of ping events sent while playback is paused.                                                                       | `1`                           |
| `session`                                       | `boolean` or `object`                                                                                                | Whether to track the media session entity for playback statistics, or set a custom start time.                                     | `true`                        |

## Stop tracking

It's important to call `endVimeoTracking` when you finish tracking. This will end any recurring ping events, clear all listeners set by the Vimeo plugin, along with resetting statistics counters used by the Snowplow Media plugin.

## Events

The plugin provides automatic tracking of the following events. Note that some events are specific to this plugin, and not part of the standard Snowplow Media events.

| Vimeo Event Name                 | Description                                                                                        | Vimeo only |
| -------------------------------- | -------------------------------------------------------------------------------------------------- | ---------- |
| `Ready`                          | Sent when the media tracking is successfully attached to the player and can track events.          |            |
| `Play`                           | Sent when the player changes state to playing from previously being paused.                        |            |
| `Pause`                          | Sent when the user pauses the playback.                                                            |            |
| `End`                            | Sent when playback stops when end of the media is reached or because no further data is available. |            |
| `SeekStart`                      | Sent when a seek operation begins.                                                                 |            |
| `SeekEnd`                        | Sent when a seek operation completes.                                                              |            |
| `PlaybackRateChange`             | Sent when the playback rate has changed.                                                           |            |
| `VolumeChange`                   | Sent when the volume has changed.                                                                  |            |
| `FullscreenChange`               | Sent immediately after the browser switches into or out of full-screen mode.                       |            |
| `PictureInPictureChange`         | Sent immediately after the browser switches into or out of picture-in-picture mode.                |            |
| `BufferStart`                    | Sent when the player goes into the buffering state and begins to buffer content.                   |            |
| `BufferEnd`                      | Sent when the player finishes buffering content and resumes playback.                              |            |
| `QualityChange`                  | Sent when the video playback quality changes automatically.                                        |            |
| `Error`                          | Sent when the Vimeo player encounters an error                                                     |            |
| `Ping`                           | Fires periodically during playback                                                                 |            |
| `PercentProgress`                | Fires at progress milestones defined by `boundaries` option                                        |            |
| `CuePoint`                       | Sent when a cue point is reached.                                                                  | ✅          |
| `ChapterChange`                  | Sent when the chapter changes.                                                                     | ✅          |
| `TextTrackChange`                | Sent when the text track changes.                                                                  | ✅          |
| `InteractiveHotspotClicked`      | Sent when an interactive hotspot is clicked.                                                       | ✅          |
| `InteractiveOverlayPanelClicked` | Sent when an interactive overlay panel is clicked.                                                 | ✅          |

If you wish to track only a subset of these events, pass an array of `VimeoEvent`s to the `startVimeoTracking` function:

**JavaScript (tag):**

```javascript
window.snowplow('startVimeoTracking',  {
  id,
  video,
  captureEvents: ['play', 'pause'],
})
```

**Browser (npm):**

```javascript
import { VimeoEvent } from '@snowplow/browser-plugin-vimeo-tracking'

startVimeoTracking({
  id,
  video,
  captureEvents: [VimeoEvent.Play, VimeoEvent.Pause],
})
```

***

### Track events manually

For event types provided by the [Snowplow Media plugin](/docs/sources/web-trackers/tracking-events/media/snowplow/) but not automatically tracked by the Vimeo plugin, such as advertising events, you can use the corresponding `track*Event` functions from the Snowplow Media plugin.

**JavaScript (tag):**

```javascript
const id = 'XXXXX'; // randomly generated ID

const video = new Player('vimeo-player', {
  videoId: 'zSM4ZyVe8xs'
});

window.snowplow('startVimeoTracking', { id, video });

...

// When your ad break starts
window.snowplow('trackMediaAdBreakStart', { id });

// When your ad break ends
window.snowplow('trackMediaAdBreakEnd', { id });

...

window.snowplow('endVimeoTracking', id);;
```

**Browser (npm):**

```javascript
import { trackMediaAdBreakStart, trackMediaAdBreakEnd } from '@snowplow/browser-plugin-media';

const id = 'XXXXX'; // randomly generated ID

const video = new Player('vimeo-player', {
  videoId: 'zSM4ZyVe8xs'
});

startVimeoTracking({ id, video });

...

// When your ad break starts
trackMediaAdBreakStart({ id });

// When your ad break ends
trackMediaAdBreakEnd({ id });

...

endVimeoTracking(id);
```

***

## Vimeo-specific event schemas

The `CuePoint`, `ChapterChange`, `TextTrackChange`, `InteractiveHotspotClicked`, and `InteractiveOverlayPanelClicked` events are specific to the Vimeo plugin, and not provided by the Snowplow Media plugin.

They're not used by the [Media Player](/docs/modeling-your-data/modeling-your-data-with-dbt/dbt-models/dbt-media-player-data-model/) dbt package, but you can use them for your own analysis.

### Cue point

Fired when a cue point added via `addCuePoint()` is reached during playback.

### `cue_point_event`

**Type:** Event

Schema for a Vimeo cue point event, fired when a cue point is reached in a video.

**Properties:**

| Property                | Description                                                                  |
| ----------------------- | ---------------------------------------------------------------------------- |
| `id` _string_           | _Required._ The ID of the cue point.                                         |
| `cuePointTime` _number_ | _Required._ The location of the cue point in seconds.                        |
| `data` _object_         | _Optional._ The custom data from the addCuePoint() call, or an empty object. |

**Example warehouse query (Snowflake):**

```sql
select
unstruct_event_com_vimeo_cue_point_event_1 cue_point_event_1
from
atomic.events
where
events.collector_tstamp > getdate() - interval '1 hour'
and events.event = 'unstruct'
and events.event_name = 'cue_point_event'
and events.event_vendor = 'com.vimeo'
```

### Chapter change

Fired when the current chapter changes during playback.

### `chapter_change_event`

**Type:** Event

Schema for a Vimeo chapter change event fired when the current chapter changes.

**Properties:**

| Property              | Description                                              |
| --------------------- | -------------------------------------------------------- |
| `index` _integer_     | _Optional._ The chapter number.                          |
| `startTime` _integer_ | _Optional._ The time in seconds when the chapter begins. |
| `title` _string_      | _Optional._ The chapter title.                           |

**Example warehouse query (Snowflake):**

```sql
select
unstruct_event_com_vimeo_chapter_change_event_1 chapter_change_event_1
from
atomic.events
where
events.collector_tstamp > getdate() - interval '1 hour'
and events.event = 'unstruct'
and events.event_name = 'chapter_change_event'
and events.event_vendor = 'com.vimeo'
```

### Text track change

Fired when the active text track (captions or subtitles) changes.

### `text_track_change_event`

**Type:** Event

Schema for a Vimeo text track event, fired when the active text track of the captions or subtitle kind changes.

**Properties:**

| Property            | Description                                                                         |
| ------------------- | ----------------------------------------------------------------------------------- |
| `kind` _string_     | _Optional._ The kind of the text track: 'captions' or 'subtitles'.                  |
| `language` _string_ | _Optional._ The ISO code of the text track's language.                              |
| `label` _string_    | _Optional._ The human-readable label of the text track for identification purposes. |
| `mode` _string_     | _Optional._ The mode of the text track                                              |

**Example warehouse query (Snowflake):**

```sql
select
unstruct_event_com_vimeo_text_track_change_event_1 text_track_change_event_1
from
atomic.events
where
events.collector_tstamp > getdate() - interval '1 hour'
and events.event = 'unstruct'
and events.event_name = 'text_track_change_event'
and events.event_vendor = 'com.vimeo'
```

### Interactive hotspot clicked

Fired when a user clicks an interactive hotspot in a Vimeo interactive video. The interaction details are provided in the `interaction` entity.

### `interactive_hotspot_click_event`

**Type:** Event

Schema for a Vimeo interactive video hotspot click

**Properties:**

**Example warehouse query (Snowflake):**

```sql
select
unstruct_event_com_vimeo_interactive_hotspot_click_event_1 interactive_hotspot_click_event_1
from
atomic.events
where
events.collector_tstamp > getdate() - interval '1 hour'
and events.event = 'unstruct'
and events.event_name = 'interactive_hotspot_click_event'
and events.event_vendor = 'com.vimeo'
```

### Interactive overlay panel clicked

Fired when a user clicks an interactive overlay panel in a Vimeo interactive video. The interaction details are provided in the `interaction` entity.

### `interactive_overlay_panel_click_event`

**Type:** Event

Schema for a Vimeo interactive overlay panel click

**Properties:**

**Example warehouse query (Snowflake):**

```sql
select
unstruct_event_com_vimeo_interactive_overlay_panel_click_event_1 interactive_overlay_panel_click_event_1
from
atomic.events
where
events.collector_tstamp > getdate() - interval '1 hour'
and events.event = 'unstruct'
and events.event_name = 'interactive_overlay_panel_click_event'
and events.event_vendor = 'com.vimeo'
```

## Vimeo entities

The event and entity schemas are [the same as](/docs/events/ootb-data/media-events/) for the [Snowplow Media plugin](/docs/sources/web-trackers/tracking-events/media/snowplow/), plus the Vimeo-specific events detailed above.

Along with the standard Snowplow media entities, the Vimeo media plugin also tracks two Vimeo media-specific entities, `meta` and `interaction`. They're not used by the [Media Player](/docs/modeling-your-data/modeling-your-data-with-dbt/dbt-models/dbt-media-player-data-model/) dbt package, but you can use them for your own analysis.

### Video metadata

The `meta` entity provides additional metadata about the video. It's added to the `Ready` event only.

### `meta`

**Type:** Schema

Schema for a Vimeo video metadata.

**Properties:**

| Property               | Description                                                                                           |
| ---------------------- | ----------------------------------------------------------------------------------------------------- |
| `videoId` _number_     | _Required._ The Vimeo ID of the video.                                                                |
| `videoTitle` _string_  | _Required._ The title of the video.                                                                   |
| `videoUrl` _string_    | _Optional._ The URL of the video on vimeo.com.                                                        |
| `videoWidth` _number_  | _Required._ The native width of the video as the width of the video's highest available resolution.   |
| `videoHeight` _number_ | _Required._ The native height of the video as the height of the video's highest available resolution. |

### Interaction

The `interaction` entity provides details of user interactions for `InteractiveHotspotClicked` and `InteractiveOverlayPanelClicked` events.

### `interaction`

**Type:** Schema

Context Schema attached to interactive\_hotspot\_click\_event and interactive\_overlay\_panel\_click\_event.

**Properties:**

| Property                     | Description                                                                                              |
| ---------------------------- | -------------------------------------------------------------------------------------------------------- |
| `action` _string_            | _Required._ The action type of the hotspot.                                                              |
| `actionPreference` _object_  | _Required._ The user's preferred action type for the hotspot.                                            |
| `customPayloadData` _object_ | _Optional._ The custom payload data of the interactive hotspot                                           |
| `currentTime` _number_       | _Optional._ The current time of the video when the interaction occurs is clicked.                        |
| `hotspotId` _string_         | _Optional._ The unique ID for the hotspot.                                                               |
| `panelId` _string_           | _Optional._ The unique ID for a panel within the overlay.                                                |
| `overlayId` _string_         | _Optional._ When action is overlay, the displayed unique ID for the overlay when the hotspot is clicked. |

## Advanced usage

As the Vimeo plugin uses Snowplow Media internally, for more granular control over events, you can utilise any of the functions provided by the [Snowplow Media plugin](/docs/sources/web-trackers/tracking-events/media/).

For example, if you wish to include additional behavior when a video is paused, you can create callback on the `pause` event of an instance of a Vimeo player.

> **Note:** In the following example, ensure you aren't passing the `pause` event to the `startVimeoTracking` function, as this will result in the event being tracked twice.

**JavaScript (tag):**

```javascript
const id = 'XXXXX'; // randomly generated ID

const video = new Vimeo.Player('vimeo-player', {
  videoId: 'zSM4ZyVe8xs'
});

window.snowplow('startVimeoTracking', { id, video, captureEvents: ['play']});

video.on('pause', () => {
  // Do something when the video is paused
  window.snowplow('trackPauseEvent', { id });
});
```

**Browser (npm):**

```javascript
import { Player } from '@vimeo/player'
import { trackPauseEvent } from '@snowplow/browser-plugin-media'

const id = 'XXXXX'; // randomly generated ID

const video = new Player('vimeo-player', {
  videoId: 'zSM4ZyVe8xs'
});

startVimeoTracking({ id, video, captureEvents: [VimeoEvent.Play]});

video.on('pause', () => {
  // Do something when the video is paused
  trackPauseEvent({ id })
});
```

***

You can also provide `player` configuration when calling `startVimeoTracking`, to set options on the underlying Vimeo player instance.
