Monitor HLS.js with the Mux Data SDK | Mux

Monitor HLS.js

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

In this guide:

  1. Install mux-embed
  2. Initialize Mux Data
  3. Make your data actionable
  4. Set or update metadata after initialization
  5. Changing the video
  6. Advanced options
  7. Release notes

Features

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

Supported Features:

Notes:

1 Install mux-embed

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. mux-embed 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 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 mux.monitor and pass in a valid CSS selector or the video element itself. Followed by the SDK options and metadata. If you use a CSS selector that matches multiple elements, the first matching element in the document will be used.

If you aren't seeing data, check to see if you have an ad blocker, tracking blocker or some kind of network firewall that prevents your player from sending requests to Mux Data servers.

3 Make your data actionable

The only required field in the options that you pass into mux-embed 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.

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 call monitor. 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).

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.

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.

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.

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

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.

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 in the options passed to Mux, via a setting named respectDoNotTrack. The default for this is false. If you would like to change this behavior, pass respectDoNotTrack: true.

Release notes

Current release

v5.18.2

Previous releases

v5.18.1

v5.18.0

v5.17.10

v5.17.9

v5.17.8

v5.17.7

v5.17.6

...additional release notes omitted for brevity.