Set up JavaScript 2.x set-up-javascript

Prerequisites

  • 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
    For more information about the Adobe Mobile SDK documentation, 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:

      code language-none
      <script type="text/javascript"
      src="https://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 note
      NOTE
      From Version 2.1.0, the JavaScript SDK is compliant with the AMD and CommonJS module specifications, and VideoHeartbeat.min.js can also be used with compatible module loaders.
  2. For easy access to the APIs, create local references to the MediaHeartbeat classes.

    code language-js
    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:

    code language-js
    //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.

    code language-js
    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.

    code language-js
    this.mediaHeartbeat = new MediaHeartbeat(mediaDelegate, mediaConfig, appMeasurement);
    
    note important
    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.
    note tip
    TIP
    MediaHeartbeat requires an instance of AppMeasurement to send calls to Adobe Analytics. Here is an example of an AppMeasurement instance:
    code language-js
    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 JavaScript 1.x to 2.x

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 information about migrating from 1.x to 2.x, see the Legacy Implementation documentation.

recommendation-more-help
c8eee520-cef5-4f8c-a38a-d4952cfae4eb