Set up JavaScript

  • Obtain valid configuration parameters - These parameters can be obtained from an Adobe representative after you set up your analytics account.
  • Implement AppMeasurement for JavaScript in your media application - See Implementing Analytics Using JavaScript.
  • Provide the following capabilities in your media player:
    • An API to subscribe to player events - The Media SDK requires that you call a set of simple APIs when events occur in your player.
    • An API that provides player information - This information includes details such as the media name and the play head position.
  1. Add your downloaded library to your project. Create local references to the classes for convenience.
    1. Expand the MediaSDK-js-v2.*.zip file that you downloaded.
    2. Verify that the MediaSDK.min.js file exists in the libs directory:
    3. Host the MediaSDK.min.js file.

      This core JavaScript file must be hosted on a web server that is accessible to all pages on your site. You need the path to these files for the next step.

    4. Reference MediaSDK.min.js on all site pages.
      Include MediaSDK for JavaScript by adding the following line of code in the <head> or <body> tag on each page. For example:
      <script type="text/javascript"
      src="http://INSERT-DOMAIN-AND-PATH-TO-CODE-HERE/MediaSDK.min.js"></script>
    5. To quickly verify that the library was successfully imported, instantiate the ADB.va.MediaHeartbeatConfig class.
    Note: From Version 2.1.0, the JavaScript SDK is compliant with the AMD and CommonJS module specifications, and MediaSDK.min.js can also be used with compatible module loaders.
  2. 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;
    
  3. 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 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;
    
  4. Implement the MediaHeartbeatDelegate protocol.
    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>);
    };
  5. 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 media session. This instance will be used for all of the following 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";

Migrate from version 1.x to 2.x in JavaScript

In version 2.x, all of the public methods are consolidated into the ADB.va.MediaHeartbeat class to make it easier on developers. Also, all configs are now consolidated into the ADB.va.MediaHeartbeatConfig class.

For detailed information about migrating from 1.x to 2.x, see Media Analytics 1.x to 2.x Migration.