YouTube Video Milestones tracking

Rookie Contributor

I have found only one comperehensive post on YouTube Video Events tracking here:

https://community.tealiumiq.com/t5/Tealium-iQ/Tracking-a-YouTube-Video-in-Tealium-iQ/m-p/1933/highli...

(Successfully implemented)

 

The only question that was not fully answered was about YouTube Video Milestones tracking.

 

Is it possible to get any assistance with the YouTube Video Milestones tracking in Tealium iQ? A couple of code examples will suffice.

 

 

2 REPLIES 2

YouTube Video Milestones tracking

Employee Emeritus

Hi @alexander_shabe. We are working on getting an answer for you. Thank you for your patience. 

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better! Also remember that search is your friend.

YouTube Video Milestones tracking

Tealium Employee

@alexander_shabe

 

So after some experimenting here is a code snippet that I got working that would fire a milestone event once, per each milestone.

 

      var playerCheckInterval;
      var mileStones = [1,2,25,50, 75]
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING) {
          playerCheckInterval = setInterval(mileStoneCheck, 100);          
        } else if (event.data == YT.PlayerState.PAUSED) {
          clearInterval(playerCheckInterval);          
          //Send PAUSED Event
        } else if (event.data == YT.PlayerState.ENDED ) {
          clearInterval(playerCheckInterval);          
          //Send ENDED Event
        }
      }
      function mileStoneCheck() {
        var duration = player.getDuration();
        var percComplete = (player.getCurrentTime() / player.getDuration()) * 100;
        var ms_len = mileStones.length;
        
        if (ms_len > 0) {
          var next_ms = mileStones[0];
          if (next_ms <= percComplete) { 
            mileStones.shift();
            console.log("mileStoneCheck", next_ms, percComplete, player.getCurrentTime());  
          }        
        }
      }

Hope this helps.

 

Adrian 

Ask me anything Tealium related or TypeScript/JavaScript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.
Public