The following instructions provide guidance for implementation across 2.x SDKs.
If you are implementing a 1.x version of the SDK, you can download 1.x Developers Guides here: Download SDKs
Initial tracking setup
Identify when the user triggers the intention of playback (the user clicks play and/or autoplay is on) and create a MediaObject
instance.
Variable Name | Description | Required |
---|---|---|
name |
Media name | Yes |
mediaid |
Media unique identifier | Yes |
length |
Media length | Yes |
streamType |
Stream type (see StreamType constants below) | Yes |
mediaType |
Media type (see MediaType constants below) | Yes |
StreamType
constants:
Constant Name | Description |
---|---|
VOD |
Stream type for Video on Demand. |
LIVE |
Stream type for LIVE content. |
LINEAR |
Stream type for LINEAR content. |
AOD |
Stream type for Audio on Demand. |
AUDIOBOOK |
Stream type for Audio Book. |
PODCAST |
Stream type for Podcast. |
MediaType
constants:
Constant Name | Description |
---|---|
Audio |
Media type for Audio streams. |
Video |
Media type for Video streams. |
var mediaObject =
MediaHeartbeat.createMediaObject(<MEDIA_NAME>,
<MEDIA_ID,
<MEDIA_LENGTH>,
MediaHeartbeat.StreamType.VOD,
<MEDIA_TYPE>);
Attach metadata
Optionally attach standard and/or custom metadata objects to the tracking session through context data variables.
Standard metadata
Implement standard metadata on JavaScript
Attaching the standard metadata object to the media object is optional.
Media metadata keys API Reference - Standard metadata keys - JavaScript
See the comprehensive set of available metadata here: Audio and video parameters
Custom metadata
Create a variable object for the custom variables and populate with the data for this media. For example:
/* Set custom context data */
var customVideoMetadata = {
isUserLoggedIn: "false",
tvStation: "Sample TV station",
programmer: "Sample programmer"
};
Track the intention to start playback
To begin tracking a media session, call trackSessionStart
on the Media Heartbeat instance:
mediaHeartbeat.trackSessionStart(mediaObject, customVideoMetadata);
The second value is the custom media metadata object name that you created in step 2.
trackSessionStart
tracks the user intention of playback, not the beginning of the playback. This API is used to load the data/metadata and to estimate the time-to-start QoS metric (the time duration between trackSessionStart
and trackPlay
).
If you are not using custom metadata, simply send an empty object for the data
argument in trackSessionStart
, as shown in the commented out line in the iOS example above.
Track the actual start of playback
Identify the event from the media player for the beginning of the playback, where the first frame of the media is rendered on the screen, and call trackPlay
:
mediaHeartbeat.trackPlay();
Track the completion of playback
Identify the event from the media player for the completion of the playback, where the user has watched the content until the end, and call trackComplete
:
mediaHeartbeat.trackComplete();
Track the end of the session
Identify the event from the media player for the unloading/closing of the playback, where the user closes the media and/or the media is completed and has been unloaded, and call trackSessionEnd
:
mediaHeartbeat.trackSessionEnd();
trackSessionEnd
marks the end of a tracking session. If the session was successfully watched to completion, where the user watched the content until the end, ensure that trackComplete
is called before trackSessionEnd
. Any other track*
API call is ignored after trackSessionEnd
, except for trackSessionStart
for a new tracking session.
Track all possible pause scenarios
Identify the event from the media player for pause and call trackPause
:
mediaHeartbeat.trackPause();
Pause Scenarios
Identify any scenario in which the media player will pause and make sure that trackPause
is properly called. The following scenarios all require that your app call trackPause()
:
Identify the event from the player for play and/or resume from pause and call trackPlay
:
mediaHeartbeat.trackPlay();
This may be the same event source that was used in Step 4. Ensure that each trackPause()
API call is paired with a following trackPlay()
API call when the playback resumes.