Browser Plugin to be used with @snowplow/browser-tracker.
Adds Video and Audio tracking events to your Snowplow tracking.
Part of the Snowplow JavaScript Tracker monorepo.
Build with Node.js (12 LTS or 14 LTS) and Rush.
npm install -g @microsoft/rush
git clone https://github.com/snowplow/snowplow-javascript-tracker.git
rush updateWith npm:
npm install @snowplow/browser-plugin-media-trackingInitialize your tracker with the MediaTrackingPlugin:
import { newTracker } from '@snowplow/browser-tracker';
import { MediaTrackingPlugin } from 'snowplow-browser-media-tracker';
newTracker('sp2', '{{collector}}', { plugins: [ MediaTrackingPlugin() ] }); // Also stores reference at module levelThen, use the TrackMedia function described below to produce events from your Video/Audio element(s).
TrackMedia( mediaId, [ config ])| Argument | Type | Default | Required | Description |
|---|---|---|---|---|
mediaId |
string | - | Yes | The HTML id attribute of the media element |
config |
object | See below | No | The config options for tracking |
| Parameter | Type | Default | Description |
|---|---|---|---|
label |
string |
- | An identifiable custom label sent with the event |
listenEvents |
string[] |
ControlEvents |
The name(s) of the events you want to listen for |
percentageBoundries |
number[] |
[10, 25, 50, 75] |
The progress percentages to fire an event at (if enabled) |
| Event | Description |
|---|---|
| pause | --- |
| play | --- |
| seeked | --- |
| ratechange | --- |
| volumechange | --- |
| change | --- |
| fullscreenchange | --- |
| enterpictureinpicture | --- |
| leavepictureinpicture | --- |
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
<video id="my-video" src="my-video.mp4">
</body>
</html>import { TrackMedia } from '@snowplow/browser-plugin-media-tracking'
TrackMedia(
"my-video",
{
label: "My Custom Video Label",
listenEvents: ["pause", "volumechange", "percentprogress"],
percentageBoundries: [10, 25, 50, 75],
}
)Licensed and distributed under the BSD 3-Clause License (An OSI Approved License).
Copyright (c) 2021 Snowplow Analytics Ltd.
All rights reserved.