YouTube tracking w/ Munchkin | Community
Skip to main content
September 12, 2016
Question

YouTube tracking w/ Munchkin

  • September 12, 2016
  • 1 reply
  • 3627 views

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 = "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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Jim_Thao7
Level 8
September 13, 2016

My wild guess is that you do not have the Munchkin script running on your modal. 


"For this to work, Munchkin must also be loaded on the page before you can start sending video view events into Marketo."

SanfordWhiteman
Level 10
September 13, 2016

Unless the modal is wrapping a second IFRAME, Munchkin would still be available on the window.

We really need, as usual, a link to a live URL.

September 14, 2016

Interestingly, we found a working solution, but it involved adjusting the Smart View in Marketo-- the script itself as I have it implemented works fine. We started getting results to show when we changed the "Visited Web Page" filter to 'Web Page -> Contains --> '/video/{videoID}' -- that is, not using querystring 'Contains' to look for the appropriate parameter as described in the aforementioned article. I'm still not quite clear on why this alternate Smart View yields results and the other doesn't-- if anyone has any explanation, I'd be very curious to hear it. I should also note that the project is an external landing page (WordPress-based) and not a Marketo landing page.