Edit in JSFiddle

// This work by S├ębastien Brodeur is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
// By : Sebastien Brodeur (brodseba@gmail.com)

var gaLimeLightMediaID = '';
var gaLimeLightTitle = '';
var gaLimeLightDuration = 0;
var gaLimeLightPlayTimeInPercent = 0;
var gaLimeLightPlayTimeInMillis = 0;
var gaLimeLightState = '';



function delvePlayerCallback(playerId, eventName, data) {  
  var id = "limelight_player";
  if (eventName == 'onPlayerLoad' && (DelvePlayer.getPlayers() == null || DelvePlayer.getPlayers().length == 0)) {
    DelvePlayer.registerPlayer(id);
  }
  
  switch (eventName) {
    case 'onMediaLoad':
      doOnMediaLoad(data);
      break;

    case 'onPlayStateChanged':
      doOnPlayStateChanged(data);
      break;

    case 'onPlayheadUpdate':
      doOnPlayheadUpdate(data);
      break; 
      
    case 'onMediaComplete':
      doOnMediaComplete(data);
      break;
    
    case 'onError':
      doOnError(data);
      break;
  }
}



function doOnMediaLoad(e) {
  if (gaLimeLightPlayTimeInMillis > 0 && gaLimeLightPlayTimeInPercent != 100) {
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + Math.round(gaLimeLightPlayTimeInMillis / gaLimeLightDuration * 100)]);
  }
  gaLimeLightMediaID = e.id;
  gaLimeLightMediaTitle = e.title;
  gaLimeLightDuration = e.durationInMilliseconds;
  gaLimeLightPlayTimeInPercent = 0;
  gaLimeLightPlayTimeInMillis = 0;
  gaLimeLightState = '';
}



function doOnPlayStateChanged(e) {
  if (e.isBusy) {
    gaLimeLightState = 'buffer';
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', 'buffer', 0, true]);
  } else if (e.isPlaying) {
    gaLimeLightState = 'play';
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', 'play']);
  } else {
    gaLimeLightState = 'pause';
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', 'pause']);
  }
}



function doOnMediaComplete(e) {
  gaLimeLightPlayTimeInPercent = 100;
  gaLimeLightState = 'complete';
  _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '100']);
}



function doOnError(e) {
  _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', 'errorMessage="' + e.message + '"', 0, true]);
}



function doOnPlayheadUpdate(e) {
  gaLimeLightPlayTimeInMillis = e.positionInMilliseconds;
  
  if (gaLimeLightPlayTimeInPercent == 0 && (e.positionInMilliseconds / e.durationInMilliseconds * 100) > 10) {
    gaLimeLightPlayTimeInPercent = 10;
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + gaLimeLightPlayTimeInPercent]);
  } else if (gaLimeLightPlayTimeInPercent < 30 && (e.positionInMilliseconds / e.durationInMilliseconds * 100) > 30) {
    gaLimeLightPlayTimeInPercent = 30;
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + gaLimeLightPlayTimeInPercent]);
  } else if (gaLimeLightPlayTimeInPercent < 50 && (e.positionInMilliseconds / e.durationInMilliseconds * 100) > 50) {
    gaLimeLightPlayTimeInPercent = 50;
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + gaLimeLightPlayTimeInPercent]);
  } else if (gaLimeLightPlayTimeInPercent < 70 && (e.positionInMilliseconds / e.durationInMilliseconds * 100) > 70) {
    gaLimeLightPlayTimeInPercent = 70;
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + gaLimeLightPlayTimeInPercent]);
  } else if (gaLimeLightPlayTimeInPercent < 90 && (e.positionInMilliseconds / e.durationInMilliseconds * 100) > 90) {
    gaLimeLightPlayTimeInPercent = 90;
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + gaLimeLightPlayTimeInPercent]);
  }
}



window.onbeforeunload = function() { 
  if (gaLimeLightState != '' && gaLimeLightState != 'complete') {
    _gaq.push(['_trackEvent', 'LimeLight video', 'mediaTitle="' + gaLimeLightMediaTitle +'" mediaId="' + gaLimeLightMediaID + '"', '' + Math.round(gaLimeLightPlayTimeInMillis / gaLimeLightDuration * 100)]);
  }
};