Radiant Media Player

Analytics API



Documentation sections


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 -1 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 -1 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>
var timeAfterLoad;
var timeBeforeLoad = Date.now();
</script>
<script src="https://cdn.radiantmediatechs.com/rmp/5.5.5/js/rmp.min.js"></script>
<div id="rmpPlayer"></div>
<script>
var src = {
  hls: 'https://your-hls-url.m3u8'
};
var settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  poster: 'https://your-poster-url.jpg'
};  
var elementID = 'rmpPlayer';
var rmp = new RadiantMP(elementID);
var rmpContainer = document.getElementById(elementID);
// We wire our events before calling init
rmpContainer.addEventListener('ready', function() {
  // ready event fires this is when the timer for getTimeReady API method stops
  var timeToLoad = timeAfterLoad - timeBeforeLoad;
  var timeToReady = rmp.getTimeReady();
  var 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
rmpContainer.addEventListener('startuptimeavailable', function () {
  var 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 and Mux Data. You could 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/5.5.5/js/rmp.min.js"></script>
<div id="rmpPlayer"></div>
<script>
var src = {
  hls: 'https://your-hls-url.m3u8'
};
var settings = {
  licenseKey: 'your-license-key',
  src: src,
  width: 640,
  height: 360,
  ads: true,
  adTagUrl: 'https://www.radiantmediaplayer.com/vast/tags/inline-linear.xml', 
  poster: 'https://your-poster-url.jpg'
};
var elementID = 'rmpPlayer';
var rmp = new RadiantMP(elementID);

// Player container which will receive API events
var rmpContainer = document.getElementById(elementID);

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

rmpContainer.addEventListener('error', function() {
  // player has encountered a fatal error preventing playback
  // TODO: send data to your custom analytics service
});

rmpContainer.addEventListener('bufferstalled', function() {
  // 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
});

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

rmpContainer.addEventListener('ended', function() {
  // player has ended content
  // TODO: send data to your custom analytics service
});

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

rmpContainer.addEventListener('adimpression', function() {
  // 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.