6 Replies Latest reply on Sep 13, 2016 6:34 PM by Sanford Whiteman

    YouTube tracking w/ Munchkin

      I'm trying to implement YouTube event tracking via the Munchkin API as detailed in this article, but the events don't seem to be logging in Marketo. The primary difference between the example in the article and my own page is that the video is being opened in (Bootstrap) modal window, and I'm using jQuery's on method to trigger to play/pause events when the modal is shown/hidden.

       

      My code is as follows (per the aforementioned article):

       

      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";

      document.getElementsByTagName('head')[0].appendChild(tag);

      var player, videoId = 'iiqxcjxJ5Us';

       

      function onYouTubeIframeAPIReady() {

          player = new YT.Player('player', {

              height: '720',

              width: '1280',

              videoId: videoId,

              events: {

                  'onStateChange': onPlayerStateChange

              }

          });

      }

       

      function onPlayerStateChange(event) {

          switch (event.data) {

              case YT.PlayerState.PLAYING:

                  Munchkin.munchkinFunction('visitWebPage', {

                      url: '/video/' + videoId,

                      params: 'video=started'

                  });

                  // test

                  if ( window.console && window.console.log ) {

                      console.log('player started via munchkin');

                  }

                  break;

              case YT.PlayerState.ENDED:

                  Munchkin.munchkinFunction('visitWebPage', {

                      url: '/video/' + videoId,

                      params: 'video=finished'

                  });

                  break;

          }

      }

       

      function stopVideo() {

          player.stopVideo();

      }

       

      function playVideo() {

          player.playVideo();

      }

       

      function pauseVideo() {

          player.pauseVideo();

      }

       

      And the jQuery function I'm using to play/pause the video in the modal windows is as follows:

       

      jQuery(document).ready(function($){

          $('#video-modal').on('show.bs.modal', function () {

            playVideo();

          });

          $('#video-modal').on('hidden.bs.modal', function () {

            pauseVideo();

          });

      });

       

      Does anyone know why the events wouldn't be getting captured and reported in Marketo? Thanks for any assistance here.