YouTube tracking w/ Munchkin

Anonymous
Not applicable

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.

6 REPLIES 6
Jim_Thao7
Level 9

Re: YouTube tracking w/ Munchkin

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 - Community Moderator

Re: YouTube tracking w/ Munchkin

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.

Anonymous
Not applicable

Re: YouTube tracking w/ Munchkin

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: YouTube tracking w/ Munchkin

The code is setting the pathname (part of the "Web Page" in Marketospeak) to /video/12345, so this is the appropriate Smart List.

?video=finished is the Query String.

Anonymous
Not applicable

Re: YouTube tracking w/ Munchkin

Thanks for the response, Sanford. That makes sense-- I'm just still confused as to why the original Smart List wasn't showing any results, as described in the article. When reviewing network activity in the console, I can see Munchkin firing 'visitWebPage' along with the query string parameter "video=started" (for example) as expected-- but that wasn't resulting in an activity record in Marketo when using a filter for the query string (unless I somehow made a different error in configuring the Smart List...)

SanfordWhiteman
Level 10 - Community Moderator

Re: YouTube tracking w/ Munchkin

I can only imagine there was something off in the SL.  The Visit Web Page activity is "synthetic" on the browser side, but the server treats it like any other VWP activity.