This article shows how to set up video tracking in Tealium iQ for embedded Ooyala videos.

In this article:

Setup

Attached is a block of code that you can copy and paste into a JavaScript Code Extension. Once pasted into the extension there are three configuration fields at the very top of the code that you can customize:

  1. video_events
    This is a list of events that you would like to track with the code. By default this is set up to track play, pause, complete and milestones, but you can simply add events to this like like "mute" to track when a user mutes the volume. You can also see a list of available events here.
  2. milestone_percentages
    This is a list of percentages that you would like to track as milestones. By default this is set to trigger an event when the video has reached 25, 50, 75 and 90 percent complete. However, this can be customized to your specific milestones. You can deactivate milestone tracking by removed the "onTime" event from the video_events list. 
  3. player_object_name
    When the Ooyala library loads on the page it should call a function called "OO.Player.create." This creates the video on the page and gets it ready for viewing. When this function is called it will create an object of data points and function specific to that video player. It would look something like: 
     window.player = OO.Player.create('playerwrapper','w3ZHc0Njr33Tdp-RRcwfZMjaOrmzOP82',{
        // More code here doing something.   
     });

The player_object_name variable should contain "player" in this case. In the JavaScript code provided below you can see that "window.player" gets set to the object that is created from calling "OO.Player.create." This object (player) is getting set in the global scope (window) so it can be used by other libraries like Tealium. 

This extension code will wait until the Ooyala player has been defined then run through the necessary functions to attach the listeners. 

Though the code has logic to wait for the player to be defined, the JavaScript Code extension where you paste the code should be scoped to DOM Ready.

Output Variables

This code will output a set of data sources that you can add in the UI and then use to send data to your tag vendors. The variables are available as follows:

  • event_type - This will always equal "video" for these events.
  • event_name -These are the default names that will be output. 
    "play", "pause", "resume", "complete", "milestone" 
  • video_position - This will output the position, in seconds, of the video when one of the events took place. i.e. pause or milestone.
  • video_duration - This tells the over length of the video.
  • video_milestone - This outputs the milestone number "1" and the milestone percentage "25." This allows you to see where your users are dropping out of the videos. Example: "M:1:25". 

Attached is a csv file with these variables and descriptions for easy uploading into the Data Sources tab of the Tealium UI. 

This code will call utag.link, but there are lines that are commented out that will support the Media Module for Adobe Analytics. The thought behind calling utag.link is then you'll have another extension that will determine when to call the Media Module functions so this extension is more "plug and play" with less customizations. 

Source Code

var video_events = ["playing","playheadTimeChanged","paused"];
var milestone_percentages = ["25","50","75","90"];
var player_object_name = "player";

var played = false;
var m1 = false;
var m2 = false;
var m3 = false;
var m4 = false;

// Call utag.link in Ooyala event listeners
window._tealium_OO = {
  name : "Ooyala",
  init_tries : 0,
  eventsAdded : false,
  events : video_events,
  milestone_percentages : milestone_percentages,
// Attaching Event Listeners for Begin, Play, Stop, and Video Completion
// Each Event Handler has a callback function attached to it (mediaEventHandler) which will be called when the event occurs  
  addEvents : function(){
        for(var i=0;i<video_events.length;i++){
          if(video_events[i]=="playing" || video_events[i]=="paused" || video_events[i]=="playheadTimeChanged"){
            _tealium_OO.player_object.subscribe(video_events[i],video_events[i],_tealium_OO[video_events[i]]);
          }else {
            _tealium_OO.player_object.subscribe(video_events[i],video_events[i],_tealium_OO.extraEvents);
          }
        }
  },
  playing:function(e,pos,dur){
    pos = _tealium_OO.player_object.getPlayheadTime();
    dur = _tealium_OO.player_object.getDuration();
    if (!played) {
      played = true;
      utag.DB("**** video started ****");
      utag.link({event_type:"video",event_name:"play"})
      ////s.Media.open(video_name, video_duration, video_player);
      ////s.Media.play(video_name, 0);
      //s.Media.track(video_name);
    } else{
      //s.Media.play(video_name, 0);
      //s.Media.track(video_name);
      _tealium_OO.pause = false;
      utag.link({event_type:"video",event_name:"resume",video_position:pos,video_duration:dur})
      utag.DB("**** video resumed ****");
    }
  },
  paused:function(e,pos,dur){
    pos = _tealium_OO.player_object.getPlayheadTime();
    dur = _tealium_OO.player_object.getDuration();
    //s.Media.stop(video_name, video_position);
    //s.Media.track(video_name);
    if(((pos/dur)*100)>90){
      _tealium_OO.complete();
    }else if(!_tealium_OO.pause){
      _tealium_OO.pause = true;
      utag.link({event_type:"video",event_name:"pause",video_position:pos,video_duration:dur})
      utag.DB("**** video paused****");
      utag.DB("**** Position: " + pos);
      utag.DB("**** Total Duration: " + dur);
    }
  },
  complete : function(e,pos,dur){
    pos = _tealium_OO.player_object.getPlayheadTime();
    dur = _tealium_OO.player_object.getDuration();
    //s.Media.complete(video_name, video_position);
    //s.Media.stop(video_name, video_position);
    //s.Media.track(video_name);
    played = false;
    _tealium_OO.resetMilestones();
    utag.link({event_type:"video",event_name:"complete",video_position:pos,video_duration:dur})
    utag.DB("**** video complete****");
  },
  playheadTimeChanged: function(data,pos,dur){
    pos = _tealium_OO.player_object.getPlayheadTime();
    dur = _tealium_OO.player_object.getDuration();
    var pct = parseFloat(pos / dur) * 100;
    if (pct > _tealium_OO.milestone_percentages[0] && !m1) {
      m1 = true;
      utag.link({event_type:"video",event_name:"milestone",video_milestone:"M:1:"+_tealium_OO.milestone_percentages[0],video_position:pos,video_duration:dur})
      utag.DB("**** 25% viwed****");
    } else if (pct > _tealium_OO.milestone_percentages[1] && !m2) {
      m2 = true;
      utag.link({event_type:"video",event_name:"milestone",video_milestone:"M:2:"+_tealium_OO.milestone_percentages[1],video_position:pos,video_duration:dur})
      utag.DB("**** 50% viewed****");
    } else if (pct > _tealium_OO.milestone_percentages[2] && !m3) {
      m3 = true;
      utag.link({event_type:"video",event_name:"milestone",video_milestone:"M:3:"+_tealium_OO.milestone_percentages[2],video_position:pos,video_duration:dur})
      utag.DB("**** 75% viewed****");
    } else if (pct > _tealium_OO.milestone_percentages[3] && !m4) {
      m4 = true;
      utag.link({event_type:"video",event_name:"milestone",video_milestone:"M:4:"+_tealium_OO.milestone_percentages[3],video_position:pos,video_duration:dur})
      utag.DB("**** 90% viewed****");
    }
  },
  extraEvents : function(pEvent,pos,dur){
    utag.link({event_type:"video",event_name:pEvent.type,video_position:pos,video_duration:dur})
    utag.DB(pEvent);
  },
  resetMilestones : function(e){
    m25 = false;
    m50 = false;
    m75 = false;
    m90 = false;
  },
  init : function(){
    _tealium_OO.player_object = window[player_object_name];
    //utag.DB("Connecting Tealium with Ooyala object");
    if(typeof _tealium_OO.player_object!="undefined"){
        _tealium_OO.addEvents()
        utag.DB("TEALIUM: Connecting Tealium with Oyala Player - SUCCESS");
        _tealium_OO.eventsAdded = true;
        return;
    }else{
      // If Ooyala object is not defined we will increment the number of tries by 1
      _tealium_OO.init_tries += 1;
      //Stop trying to connect to the Video Player if tried 100 times
      if(_tealium_OO.init_tries>100){
        utag.DB("TEALIUM: Cannot connect to Ooyala Video");
        return;
      }
      // Calls init function repeatedly either 100 times or Ooyala Object is defined
      setTimeout(function(){_tealium_OO.init()}, 100);
    }
  }
}

if(typeof _tealium_OO.videoPlayer == "undefined"){
  setTimeout(function(){_tealium_OO.init()}, 300);
}

 

Attachments
Version history
Revision #:
3 of 3
Last update:
‎10-31-2020 08:20 AM
Updated by: