AnsweredAssumed Answered

Tracking how long an embedded video was watched

Question asked by Jimmy Forde on Aug 23, 2019
Latest reply on Aug 27, 2019 by Jimmy Forde

Hello-

 

I am trying to edit some video tracking mechanisms into landing page templates using munchkin. I was able to implement the below code without issue and am able to track video starts and finishes. However, I want to be able to parse out how much of the video they watched into percentages ( like 25%, 50%, 75%). I have tried implementing code shown here: Track YouTube Videos in Marketo  but the video wont embed on the page whenever i try.

 

Is there a way to edit my current code ( below) to capture the percentages?

 

<div id="player"></div>  
    <script> 
    var tag = document.createElement('script'); 
    tag.src = "https://www.youtube.com/iframe_api"; 
    document.getElementsByTagName('head')[0].appendChild(tag); 
     
    //Change 'iiqxcjxJ5Us' to video needed 
    var player, videoId = '{{my.Links_YoutubeID}}'; 
    function onYouTubeIframeAPIReady() { 
    player = new YT.Player('player', { 
    height: '390', 
    width: '640', 
    videoId: videoId, 
    events: { 
    'onStateChange': onPlayerStateChange 
    } 
    }); 
    } 
     
    function onPlayerStateChange(event) { 
    switch( event.data ) { 
    //Send video started event to Marketo 
    case YT.PlayerState.PLAYING: Munchkin.munchkinFunction('visitWebPage', { 
    url: '/video/'+videoId 
    , params: 'video=started' 
    } 
    ); 
    break; 
    //Send video finished event to Marketo 
    case YT.PlayerState.ENDED: Munchkin.munchkinFunction('visitWebPage', { 
    url: '/video/'+videoId 
    , params: 'video=finished' 
    } 
    ); 
    break; 
    } 
     
    } 
    </script>  

Outcomes