Measuring Additional Metrics using Media.monitor

You can define a custom Media.monitor method to track additional video metrics.

A custom Media.monitor method gives you the most granular control over video tracking. AppMeasurement automatically calls the Media.monitor method in the following circumstances:

Use this functionality to monitor the status of each video that is currently playing. With it, you can setup additional variables (Props, eVars, Events) and call Media.track based on the current state of the video as it is playing.

s.Media.monitor(s, media)

This method takes the following parameters:

s: The AppMeasurement instance.

media: An object with members providing the state of the video. These members include:

State Property Description
media.name The name of the video given in the call to Media.open.
media.length The length of the video in seconds given in the call to Media.open.
media.openTime A Date object set to the time video tracking started.
media.offset The current offset into the video, in seconds.
media.percent The current offset into the video, as a percentage of the video length ((media.offset / media.length) * 100).
media.timePlayed The total video playback time, in seconds. This includes replay time due to rewind, and excludes time skipped by fast forwarding.
media.playerName The name of the media player given in the call to Media.open.
media.mediaEvent

The event that initiated the call to the Media.monitor method. Options include the following:

OPEN: The start of video playback. For a non-autoTrack (manual) implementation, this is the first time Media.play is called after calling Media.open.

PLAY: Video playback restarted.

STOP: Video playback stopped due to pause, seek forward or backwards, scrubbing started, etc.

CLOSE: The end of video playback. For a non-autoTrack (manual) implementation, this is when Media.close is called.

MONITOR: A check of the video state, which occurs every second.

MILESTONE: A video milestone was reached, as defined by the Media.trackMilestones method. The media.milestone property identifies the specific milestone that was reached.

SECONDS: The playback time specified by media.trackSeconds has been reached.

media.eventFirstTime A boolean property. When set to true, indicates the media.mediaEvent occurred for the first time. If media.mediaEvent = "MILESTONE" a true value indicates that this is the first time to reach the video milestone identified in media.milestone.
media.milestone

The milestone reached during video playback, as defined in the Media.trackMilestones method.

This property is only set when media.mediaEvent is set to "MILESTONE".

media.player Player-specific data created by some autoTrack implementations.
media.player.metadata Player-specific method for retrieving video metadata from the player.

A custom Media.monitor method should do similar to the following:

Define a method or function for Media.monitor

To create a custom Media.monitor method you can set Media.monitor to an anonymous function or a class method. The anonymous function or class method you define should take the AppMeasurement instance and media object as shown in the media monitor reference.

//JavaScript or Flash anonymous function example
s.Media.monitor = function (s,media)  {
...
}
//Silverlight class method example
s.Media.monitor = new AppMeasurement_Media_Monitor(myMediaMonitor);
//OSMF anonymous function example
s.Media.monitor = function (s:Object,media:Object) {
...
}

Media.monitor Code Sample

The following code sample demonstrates using Media.monitor to send custom variables.

/* Import line for ActionScript 3 */
import com.omniture.AppMeasurement;

/* Uncomment for ActionScript 2 with Flash Player 8+ and comment out other import lines */
/* import com.omniture.AS2.AppMeasurement; */

/* Uncomment for ActionScript 2 with Flash Player 6, 7, or Lite and comment out other import lines */
/* import com.omniture.AS2.FPL.AppMeasurement; */

var s:AppMeasurement = new AppMeasurement();
/* Uncomment for Flex and comment out addChild(s); */
/* rawChildren.addChild(s); */
addChild(s);

/* Specify the Report Suite ID(s) to track here */
s.account = "jdoe";
/* Turn on and configure debugging here */
s.debugTracking = true;
s.trackLocal = true;
/* You may add or alter any code config here */
s.pageName = "";
s.pageURL = "";
s.charSet = "UTF-8";
s.currencyCode = "USD";

s.Media.autoTrack=true;
s.Media.segmentByMilestones=true;
s.Media.trackMilestones="25,50,75";
s.Media.trackVars="eVar2,eVar3,eVar1,events,prop51,prop50";
s.Media.trackEvents="event1,event2,event3,event4,event5,event6,event7";

/* Turn on and configure ClickMap tracking here */
s.trackClickMap = true;
s.movieID = "";

/* WARNING: Changing any of the below variables will cause drastic changes
to how your visitor data is collected.  Changes should only be made
when instructed to do so by your account manager.*/
s.visitorNamespace = "corp1";
s.trackingServer = "corp1.d1.sc.omtrdc.net";
var tracked25:Boolean
var tracked50:Boolean
var tracked75:Boolean
var fireRequest:Boolean

s.Media.trackUsingContextData = true;

s.Media.contextDataMapping = {
"a.media.name":"eVar2",
"a.media.segment":"eVar3",
"a.contentType":"eVar1",
"a.media.timePlayed":"event3",
"a.media.view":"event1",
"a.media.segmentView":"event2",
"a.media.complete":"event7",
"a.media.milestones":{
25:"event4",
50:"event5",
75:"event6"
}
};

s.Media.monitor = function (s,media){
  
    if ((media.event == "MILESTONE") && (media.eventFirstTime)) {
     if (media.milestone == 25) {
          s.prop51 = media.name+ " : " +"25%";
          fireRequest = true;
     }
     if (media.milestone == 50) {
          s.prop51 = media.name+ " : " +"50%";
          fireRequest = true;
     }
     if (media.milestone == 75) {
          s.prop51 = media.name+ " : " +"75%";
          fireRequest = true;
     }
     if (fireRequest) {
          fireRequest = false;
          sendRequest();
     }
}
                
    if(media.event=="OPEN") {
        s.prop50="Home page"
        sendRequest();
        s.prop50=""

    }
    
    if(media.event=="CLOSE") {
        s.prop51=media.name+ " : " +"100%"
        sendRequest();
        s.prop51=""

    }

    function sendRequest(){
        s.Media.track(media.name);
    }
}

The following custom Media.monitor method sets eVar1 to the “series” key, eVar2 to the “season” key, and eVar3 to the “episode” key in the http://www.corp1.com/ namespace using OSMF metadata:

s.Media.monitor = function (s:Object,media:Object) {
    s.trackVars = "events,eVar1,eVar2,eVar3";
    s.trackEvents = "event1,event2";
    s.eVar1 = media.player.metadata("http://www.corp1.com/","series");
    s.eVar2 = media.player.metadata("http://www.corp1.com/","season");
    s.eVar3 = media.player.metadata("http://www.corp1.com/","episode");
    if (media.mediaEvent == "OPEN") {
        s.events = "event1";
        s.Media.track(media.name);
    } else if (media.mediaEvent == "CLOSE") {
        s.events = "event2";
        s.Media.track(media.name);
    }
}

The following example shows a Media.monitor implementation in Silverlight:

s.Media.media = new AppMeasurement_Media_Monitor(myMediaMonitor);

// ...

// custom variables (Props, eVars, Events) are sent automatically on an OPEN event, and when manually tracked here (in media monitor below)
private void myMediaMonitor(AppMeasurement s,AppMeasurement_Media_State media) {
     if (media.mediaEvent == "OPEN") { //executes when the video opens
          s.Media.trackVars = "eVar1,events";
          s.Media.trackEvents = "event1";
          s.events = "event1";
          s.eVar1 = media.name;
          s.Media.track(media.name);
     }
     if (media.mediaEvent == "CLOSE") { //executes when the video completes
          s.Media.trackVars = "eVar1,events";
          s.Media.trackEvents = "event4";
          s.events = "event4";
          s.eVar1 = media.name;
          s.Media.track(media.name);
     }