Set up and configure your MediaHeartbeat instance

Add the library to your project by completing the tasks in Implement the JavaScript library.

  1. For easy access to the APIs, create local references to the MediaHeartbeat classes.
    var MediaHeartbeat = ADB.va.MediaHeartbeat;
    var MediaHeartbeatConfig = ADB.va.MediaHeartbeatConfig;
    var MediaHeartbeatDelegate = ADB.va.MediaHeartbeatDelegate;
    
  2. Create a MediaHeartbeatConfig instance.

    This section helps you to understand MediaHeartbeat config parameters and how to set correct config values on your MediaHeartbeat instance, for accurate tracking.

    Here is the MediaHeartbeatConfig reference:
    Variable Name Description Required Default Value
    trackingServer Defines the server for tracking media heartbeats. This is different from your analytics tracking server. Yes Empty String
    channel Channel name property Yes Empty String
    ovp Name of the online video platform through which content gets distributed. Yes unknown
    appVersion Version of the video player app/SDK. Yes unknown
    playerName

    Name of the video player in use. E.g.: "AVPlayer", "HTML5 Player", "My Custom VideoPlayer".

    Yes Empty String
    ssl Property that indicates whether the heartbeat calls should be made over HTTPS. Yes false
    debugLogging Gets the preference for debug log output. Yes false

    Here is a sample MediaHeartbeatConfig initialization:

    //Media Heartbeat initialization
    var mediaConfig = new MediaHeartbeatConfig();
    mediaConfig.trackingServer = Configuration.HEARTBEAT.TRACKING_SERVER;
    mediaConfig.playerName = Configuration.PLAYER.NAME;
    mediaConfig.channel = Configuration.HEARTBEAT.CHANNEL;
    mediaConfig.debugLogging = true;
    mediaConfig.appVersion = Configuration.HEARTBEAT.SDK;
    mediaConfig.ssl = false;
    mediaConfig.ovp = Configuration.HEARTBEAT.OVP;
    
  3. Implement the MediaHeartbeatDelegate protocol.
    Here is the MediaHeartbeatDelegate reference:
    Method name Description Required
    getQoSObject() Returns the MediaObject instance that contains the current QoS information. This method will be called multiple times during a playback session. Player implementation must always return the most recently available QoS data. Yes
    getCurrentPlaybackTime()

    Returns the current position of the playhead.

    For VOD tracking, the value is specified in seconds from the beginning of the media item.

    For LIVE/LIVE tracking, the value is specified in seconds from the beginning of the program.

    Yes
    Here is the MediaObject (QoS Object) reference:
    Variable name Description Required
    bitrate The bitrate of media in bits per second Yes
    startupTime The start up time of media in seconds Yes
    fps The start up time of media in seconds Yes
    droppedFrames The number of dropped frames so far Yes
    var mediaDelegate = new MediaHeartbeatDelegate();
    
    // Replace <currentPlaybackTime> with the video player current playback time
    mediaDelegate.getCurrentPlaybackTime = function() {
        return <currentPlaybackTime>;
    };
    
    // Replace <bitrate>, <startuptime>, <fps> and <droppeFrames> with the current playback QoS values. 
    mediaDelegate.getQoSObject = function() {
        return MediaHeartbeat.createQoSObject(<bitrate>, <startuptime>, <fps>, <droppedFrames>);
    };
  4. Create the MediaHeartbeat instance.

    Use the MediaHeartbeatConfig and MediaHeartbeatDelegate to create the MediaHeartbeat instance.

    this.mediaHeartbeat = new MediaHeartbeat(mediaDelegate, mediaConfig, appMeasurement);
    Important: Make sure that your MediaHeartbeat instance is accessible and does not get deallocated until the end of the video session. This instance will be used for all of the following video tracking events.
    Tip: MediaHeartbeat requires an instance of AppMeasurement to send calls to Adobe Analytics.

    Here is an example of an AppMeasurement instance:

    // AppMeasurement instance example
    var appMeasurement = new AppMeasurement();
    appMeasurement.visitor = visitor;
    appMeasurement.trackingServer = "<visitor_namespace>.sc.omtrdc.net";
    appMeasurement.account = <rsid>;
    appMeasurement.pageName = <page_name>;
    appMeasurement.charSet = "UTF­8";