# Monitor playback with Mux Data

Measure startup time, rebuffering, failures, and watch time by adding the Mux Data extension to a player

[Mux Data](https://www.mux.com/data?utm_source=videojs&utm_campaign=vjs10&utm_content=docs-content) measures playback quality: startup time, rebuffering, playback failures, and watch time. Add the Mux Data [extension](./architecture.md) to a player and it monitors whichever media that player is playing:

Install the extension alongside the framework façade. The `<mux-video>` example also installs the Mux playback adapter:

```bash
pnpm add @videojs/html @videojs/mux-video @videojs/mux-data
```

**index.html**

```html
<video-player>
  <media-container>
    <mux-video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM.m3u8" playsinline></mux-video>
    <mux-data></mux-data>
  </media-container>
</video-player>
<script type="module">
  import '@videojs/html/video/player';
  import '@videojs/html/ui/container';
  import '@videojs/html/media/mux-video';
  import '@videojs/html/extensions/mux-data';
</script>
```

That’s the whole setup for Mux-hosted playback — no environment key required. The extension renders nothing; place it anywhere inside the player.

> **Note**
>
> Mux Data is opt-in. No media component monitors playback on its own, Mux ones included, so nothing is measured and no beacons are sent until you add the extension.

## Set the environment key

Mux Data needs to know which environment a view belongs to. For Mux-hosted playback, you do not need to set an environment key. The extension reports the Mux playback ID as the view’s `video_id`, and Mux attributes the view to the environment that owns that playback ID.

Set `envKey` when you monitor a source Mux doesn’t host, like a self-hosted HLS or DASH stream. Find the key in the [Mux dashboard](https://dashboard.mux.com/settings/data?utm_source=videojs&utm_campaign=vjs10&utm_content=docs-content):

For the hls.js example, also install `@videojs/hlsjs-video`. Replace `<mux-video>` in the primary example with `<hlsjs-video>` and keep `<hlsjs-video>` and `<mux-data>` inside the container:

```bash
pnpm add @videojs/hlsjs-video
```

```html
<hlsjs-video src="https://example.com/stream.m3u8"></hlsjs-video>
<mux-data env-key="YOUR_ENV_KEY"></mux-data>
<script type="module">
  import '@videojs/html/media/hlsjs-video';
  import '@videojs/html/extensions/mux-data';
</script>
```

An explicit `envKey` overrides the environment Mux infers from the playback ID. Set one to send Mux-hosted views to a specific environment.

## How it works

The extension attaches to the media the player is using, not to a specific element type, so it monitors [`<mux-video>`](../reference/components/mux-video.md), [`<hlsjs-video>`](../reference/components/hlsjs-video.md), [`<dash-video>`](../reference/components/dash-video.md), and the rest alike.

How much the extension reports depends on the engine playing the stream. All media report the playback metrics available from the media element. The extension also recognizes [hls.js](https://github.com/video-dev/hls.js/) and [dash.js](https://github.com/Dash-Industry-Forum/dash.js) engines and hands them to the Mux Data SDK, which adds stream-level detail: rendition switches, segment request timing and throughput, and engine errors. Media without a JavaScript engine, like native HLS or a plain `<video>`, report only the element-level metrics.

The `video_id` it reports is the Mux playback ID for streams served from `stream.mux.com`, and the source URL otherwise. Each view also gets a generated `view_session_id`. Override either through `metadata`.

## Name the player

Each view reports a player software name of `videojs-html-<engine>`, with the Video.js version as the player software version, so you can compare views by engine in Mux Data. For example, a stream played by hls.js reports `videojs-html-hlsjs`.

| Engine | Played by |
| --- | --- |
| `hlsjs` | [hls.js](https://github.com/video-dev/hls.js/) |
| `spf-hls-video` | The Video.js SPF engine for video, used by HLS video |
| `spf-hls-video-mpeg-ts` | The SPF video engine with MPEG-TS support, used by the SPF flavor of Mux video |
| `spf-hls-audio` | The audio-only SPF engine, used by HLS audio |
| `spf-hls-audio-mpeg-ts` | The audio-only SPF engine with MPEG-TS support, used by the SPF flavor of Mux audio |
| `spf-hls-background-video` | The SPF engine for background video, used by HLS background video |
| `spf-hls-background-video-mpeg-ts` | The SPF background video engine with MPEG-TS support, used by Mux background video |
| `shaka` | [Shaka Player](https://github.com/shaka-project/shaka-player) |
| `dashjs` | [dash.js](https://github.com/Dash-Industry-Forum/dash.js) |
| `browser` | The browser itself, like native HLS in Safari or an MP4 file |

The name follows the engine that’s playing, so a source change that switches engines updates the name for the current view.

To report your own name instead, set the player software name. It takes precedence over the default:

```html
<mux-data player-software-name="my-player" player-software-version="2.4.0"></mux-data>
```

## Describe the view

Pass Mux Data [metadata](https://www.mux.com/docs/guides/make-your-data-actionable-with-metadata?utm_source=videojs&utm_campaign=vjs10&utm_content=docs-content) to label views with your own titles, viewer IDs, and custom dimensions.

Set `metadata-*` attributes in markup, or assign the `metadata` property when you need an object or want to override attribute values. The property wins when both set the same key.

```html
<mux-data
  metadata-video-title="Big Buck Bunny"
  metadata-viewer-user-id="u_789"
></mux-data>
```

```ts
const muxData = document.querySelector('mux-data');
muxData.metadata = { video_title: 'Big Buck Bunny', viewer_user_id: 'u_789' };
```

## Configuration

The [`<mux-data>` reference](../reference/components/mux-data.md) lists every option: the metadata and software fields above, plus the beacon domain, cookie, debug, and SDK settings. Most options update the current view in place; changing `MuxDataSdk`, `beaconCollectionDomain`, `debug`, or `disableCookies` restarts monitoring, ending the current view and starting a new one.

## Related pages

### Components

- [mux-data](../reference/components/mux-data.md): Options for the Mux Data extension that monitors playback quality
- [mux-video](../reference/components/mux-video.md): Video element for Mux-hosted HLS streams
- [mux-audio](../reference/components/mux-audio.md): Audio element for Mux-hosted HLS streams

### Guides

- [Cast to AirPlay and Chromecast](./casting.md): Send playback to AirPlay and Google Cast devices, with availability detection and connection state.