Documentation

Analytics API

Player API analytics methods

Analytics data can be delivered by the player with JavaScript. See our player API documentation for a better understanding of how to use the player API and a list of generally available API methods. In addition we provide the following analytics-oriented API methods:

getTimeViewed()

rmp.getTimeViewed()

This methods returns a Number expressed in milliseconds that represents the cumulative time viewed for the current player instance. Returns 0 if not available. This number can exceed content duration if the same part of content is viewed multiple times for a given player session.

getPercentViewed()

rmp.getPercentViewed()

This methods returns a Number expressed in % that represents the cumulative percent viewed for the current player instance (example: 20 for 20%). This is calculated against content duration. It will only return valid values for on-demand content as for live/DVR content the duration is unknown. Returns 0 if not available. This number CAN exceed 100 if the same part of content is viewed multiple times for a given player session.

getCurrentTimeInPercent()

rmp.getCurrentTimeInPercent()

This methods returns a Number expressed in % that represents the current percent viewed for the current player instance (example: 20 for 20%). This is calculated against content duration. It will only return valid values for on-demand content as for live/DVR content the duration is unknown. Returns -1 if not available. This number CANNOT exceed 100.

getTimeReady()

rmp.getTimeReady()

This methods returns a Number expressed in milliseconds that represents the time for the player to be ready, i.e. fully appended to DOM, ready to receive user interaction (or autoplay if required) and API calls. It computed from the moment init player method is called on player. See example below to also take into account the time required to load Radiant Media Player core library (rmp.min.js). Returns -1 if not available.

getStartUpTime()

rmp.getStartUpTime()

This methods returns a Number expressed in milliseconds that represents the time needed for the player to display the first frame of content or pre-roll ad when available, whichever comes first, after the viewer has requested playback through an initial user interaction (or when autoplay is requested). Returns -1 if not available. This method should be queried when the startuptimeavailable player event fires.

Computing time to load Radiant Media Player core file library

In addition to getting time to reach player ready state (getTimeReady), you may want to get the time it took for Radiant Media Player core library (rmp.min.js) to load, either from our cloud service or when self-hosted. The code below shows an example of how to get this data:

<!-- Here we start our timer to compute time to load rmp.min.js -->
<script>
const timeAfterLoad;
const timeBeforeLoad = Date.now();
</script>
<script src="https://cdn.radiantmediatechs.com/rmp/9.16.6/js/rmp.min.js"></script>
<div id="rmp"></div>
<script>
const src = {
  hls: 'https://your-hls-url.m3u8'
};
const settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  contentMetadata: {
    poster: [
      'https://your-poster-url.jpg'
    ]
  }
};  
const elementID = 'rmp';
const rmp = new RadiantMP(elementID);
// We wire our events before calling init
rmp.on('ready', () => {
  // ready event fires this is when the timer for getTimeReady API method stops
  const timeToLoad = timeAfterLoad - timeBeforeLoad;
  const timeToReady = rmp.getTimeReady();
  const totalReadyTime = timeToLoad + timeToReady;
  // print our data to console
  console.log('timeToLoad is ' + timeToLoad + ' ms');
  console.log('timeToReady is ' + timeToReady + ' ms');
  console.log('totalReadyTime is ' + totalReadyTime + ' ms');
});
// Here we also print the player start-up time
rmp.on('startuptimeavailable', () => {
  const startupTime = rmp.getStartUpTime();
  console.log('startupTime is ' + startupTime + ' ms');
});
// Here we stop our timer to compute time to load rmp.min.js
// In this case we also add the time it took to create Radiant Media Player instance and to wire our app logic
timeAfterLoad =  Date.now();
// init is called this is when the timer for getTimeReady API method starts
rmp.init(settings);
</script>

Make sure to review our performance guide to get the most out of Radiant Media Player.

Player API analytics events

Player events can be used to track analytics data. See our player API events documentation for a list of generally available player events.

3rd-party analytics service integration

By default, Radiant Media Player integrates with Google Analytics, Mux Data and MediaMelon. For MediaMelon integration please contact us or MediaMelon directly as this integration is not public. You could also want to build your own custom Google Analytics integration or support other analytics services like comScore, Adobe Site Catalyst or Nielsen. This can be achieved through our player API. Assuming your analytics service can send and receive information through JavaScript, all player API events and methods can be tracked.

In the example below we show how to retrieve commonly needed analytics information through the player API.

<script src="https://cdn.radiantmediatechs.com/rmp/9.16.6/js/rmp.min.js"></script>
<div id="rmp"></div>
<script>
const src = {
  hls: 'https://your-hls-url.m3u8'
};
const settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  ads: true,
  adTagUrl: 'https://www.radiantmediaplayer.com/vast/tags/inline-linear.xml', 
  contentMetadata: {
    poster: [
      'https://your-poster-url.jpg'
    ]
  }
};
const elementID = 'rmp';
const rmp = new RadiantMP(elementID);

// We attached our listeners to be notified of player events
rmp.on('ready', () => {
  // player is ready
  // TODO: send data to your custom analytics service
}); 

rmp.on('error', () => {
  // player has encountered a fatal error preventing playback
  // TODO: send data to your custom analytics service
});

rmp.on('bufferstalled', () => {
  // current buffer is empty - media playback is stopped until enough buffer has been downloaded to resume playback
  // TODO: send data to your custom analytics service
});

rmp.on('buffernotstalledanymore', () => {
  // player has resumed playback after a bufferstalled event (e.g. it exits buffering state)
  // TODO: send data to your custom analytics service
});

rmp.on('ended', () => {
  // player has ended content
  // TODO: send data to your custom analytics service
});

rmp.on('timeupdate', () => {
  // player has moved its playhead
  const currentTime = rmp.getCurrentTime(); // current playback position in milliseconds
  if (currentTime > XX) {
    const fullscreen = rmp.getFullscreen(); // current fullscreen state of the player
    const volume = rmp.getVolume(); // current player volume 
    // TODO: send data to your custom analytics service
  }
});

rmp.on('adimpression', () => {
  // player has pinged the VAST impression URL
  // TODO: send data to your custom analytics service
});

// Player initialisation only after API events are registered
rmp.init(settings);
</script>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License.

©2015-2024 Radiant Media Player. All Rights Reserved.