Monitor video.js with the Mux Data SDK | Mux

Monitor video.js

Connect Mux Data to video.js to collect playback performance metrics. Use this guide when your web application plays video with video.js.

In this guide:

Mux Data collects playback performance metrics from video.js. Use this guide when your web application plays video with video.js and you want to monitor the playback experience of your viewers. You do not need Mux Video to use Mux Data.

Features

The following data can be collected by the Mux Data SDK when you use the Video.js SDK, as described below.

Supported Features:

Notes:

Request metrics and CDN identification are available using videojs-contrib-hls or Video.js v7+. Preroll Ads metrics & metadata available if using videojs-ima. Session Data is available with Video.js w/ HLS.js.

1 Install videojs-mux

Include the Mux JavaScript SDK on every page of your web app that includes video. You can use the Mux-hosted version of the script or install via npm. videojs-mux follows semantic versioning and the API will not change between major releases.

2 Initialize Mux Data

Get your ENV_KEY from the Mux environments dashboard.

Env Key is different than your API token

ENV_KEY is a client-side key used for Mux Data monitoring. These are not to be confused with API tokens which are created in the admin settings dashboard and meant to access the Mux API from a trusted server.

Call video.js like you normally would and include the Mux plugin options.

3 Make your data actionable

The only required field in the options that you pass into videojs-mux is env_key. But without some metadata the metrics in your dashboard will lack the necessary information to take meaningful actions. Metadata allows you to search and filter on important fields in order to diagnose issues and optimize the playback experience for your end users.

Pass in metadata under the data on initialization.

4 Set or update metadata after initialization

There are some cases where you may not have the full set of metadata until after the video playback has started. In this case, you should omit the values when you first initialize the Mux SDK. Then, once you have the metadata, you can update the metadata with the updateData method.

5 Changing the video

There are two cases where the underlying tracking of the video view needs to be reset:

  1. New source: When you load a new source URL into an existing player.
  2. New program: When the program within a singular stream changes (such as a program change within a continuous live stream).

Note: You do not need to change the video info when changing to a different source of the same video content (e.g. different resolution or video format).

New source

If your application plays multiple videos back-to-back in the same video player, you need to signal when a new video starts to the Mux SDK. Examples of when this is needed are:

In order to signal the Mux SDK that a new view is starting, you will need to emit a videochange event, along with metadata about the new video. You can include any metadata when changing the video but you should only need to update the values that start with video_.

New program

In some cases, you may have the program change within a stream, and you may want to track each program as a view on its own. An example of this is a live stream that streams multiple programs back to back, with no interruptions.

In this case, you emit a programchange event, including the updated metadata for the new program within the continuous stream.

Note: The programchange event is intended to be used only while the player is currently not paused. If you emit this event while the player is paused, the resulting view will not track video startup time correctly, and may also have incorrect watch time.

6 Advanced options

Disable cookies

By default, Mux plugins for HTML5-based players use a cookie to track playback across subsequent page views in order to understand viewing sessions. This cookie includes information about the tracking of the viewer, such as an anonymized viewer ID that Mux generates for each user. None of this information is personally-identifiable, but you can disable the use of this cookie if desired.

This is done by setting disableCookies: true in the options.

Over-ride 'do not track' behavior

By default, Mux plugins for HTML5-based players do not respect Do Not Track when set within browsers. This can be enabled by passing respectDoNotTrack: true in the options.

Customize error tracking behavior

Errors are fatal

Errors tracked by mux are considered fatal meaning that they are the result of playback failures.

By default, videojs-mux will track errors emitted from the video element as fatal errors. If a fatal error happens outside of the context of the player, you can emit a custom error to the mux monitor.

Error translator

If your player emits error events that are not fatal to playback or the errors are unclear and/or do not have helpful information in the default error message and codes you might find it helpful to use an error translator or disable automatic error tracking altogether.

Release notes

Current release

v4.21.29

Previous releases

v4.21.28

(Additional release notes are excluded for brevity.)


Track your video engagement and performanceDash.js Track your video engagement and performanceReact native video