Re: How do you create a Munchkin API call to track video plays?

SanfordWhiteman
Level 10 - Community Moderator

Re: How do you create a Munchkin API call to track video plays?

Looks like it's working to me:

pastedImage_0.png

KanakoTone
Level 5

Re: How do you create a Munchkin API call to track video plays?

Interesting. Is it how it looks like in Marketo? As I posted initially, my Marketo doesn't show the details more than clicked.

SanfordWhiteman
Level 10 - Community Moderator

Re: How do you create a Munchkin API call to track video plays?

That's the Developer Tools >> Network log in my browser.  You can see it is sending the Click Link events successfully to your Marketo instance.  Note I used the second video player on the page -- you are statically embedding a player and then calling my code to insert the IFrame player, which as noted above means you have 2.  You want to use my code to dynamically insert and not have the static one.

If you click, play 10 seconds, and pause, you should see the same tracks in your browser.  Can you do this and post a screenshot of your Network log?

KanakoTone
Level 5

Re: How do you create a Munchkin API call to track video plays?

I don't have access to Developer Tools. I got rid of the video element and played the IFrame player video for 1 mins. The below is what shows on Marketo, which doesn't tell me what exact action has taken. I need to give reports of who have watched (at least started playing) the video, so I need to get the info on Marketo side, but not in developer view.

Capture.PNG

SanfordWhiteman
Level 10 - Community Moderator

Re: How do you create a Munchkin API call to track video plays?

I don't have access to Developer Tools.

Sure you do!  Every browser has Dev Tools.

Here's a video of me playing the video.  Check the Dev Tools >> Network on the right side.

     2016-01-28_1813 - swhiteman's library

I think what's confusing you is that you aren't looking at the Query String for those activities.  The QS will be like

     /?video=lxqCi6Ndciw&movie-action=passed-im-mark

Click the Activity ID and you'll see the QS.  Build your Smart Lists constrained by the QS.

KanakoTone
Level 5

Re: How do you create a Munchkin API call to track video plays?

Ok, then I need to rephrase that I don't know how to get into dev tools.

Click the Activity ID and you'll see the QS.  Build your Smart Lists constrained by the QS.

This is it! I thought the QS will show up right on the activity log, but it is deep inside.

KanakoTone
Level 5

Re: How do you create a Munchkin API call to track video plays?

But smart list doesn't work

KanakoTone
Level 5

Re: How do you create a Munchkin API call to track video plays?

Oops, accidentally hit Post before finishing.

The smart list with Visited Webpage filter with "QS contains movie-action=passed-im-mark" doesn't show up anyone. The Clicked Link on Webpage filter doesn't work either. Am I missing anything?

filter.PNG

SanfordWhiteman
Level 10 - Community Moderator

Re: How do you create a Munchkin API call to track video plays?

It's a Clicked Link on Web Page ​activity, not a view.

Anonymous
Not applicable

Re: How do you create a Munchkin API call to track video plays?

Sanford Whiteman

This is great! I have a couple questions for you:

1) Is it possible to implement this in a way to capture this activity without specifying which video it is? I'd like to track embedded YouTube videos and score them across the entire website. We have a tag in Google Tag Manager that is firing off any time a video is played and it captures the ID and sends the data to Google Analytics. I'd love to be able to track this similarly. The script used for GA events is this:

<script type="text/javascript">

// OPTIONAL: Enable JSAPI if it's not already on the URL

// note: this will cause the Youtube player to "flash" on the page when reloading to enable the JS API

for (var e = document.getElementsByTagName("iframe"), x = e.length; x--;)

  if (/youtube.com\/embed/.test(e[x].src))

     if(e[x].src.indexOf('enablejsapi=') === -1)

        e[x].src += (e[x].src.indexOf('?') ===-1 ? '?':'&') + 'enablejsapi=1';

var gtmYTListeners = []; // support multiple players on the same page

// attach our YT listener once the API is loaded

function onYouTubeIframeAPIReady() {

    for (var e = document.getElementsByTagName("iframe"), x = e.length; x--;) {

        if (/youtube.com\/embed/.test(e[x].src)) {

            gtmYTListeners.push(new YT.Player(e[x], {

                events: {

                    onStateChange: onPlayerStateChange,

                    onError: onPlayerError

                }

            }));

            YT.gtmLastAction = "p";

        }

    }

}

// listen for play/pause, other states such as rewind and end could also be added

// also report % played every second

function onPlayerStateChange(e) {

    e["data"] == YT.PlayerState.PLAYING && setTimeout(onPlayerPercent, 1000, e["target"]);

    var video_data = e.target["getVideoData"](),

        label = video_data.video_id+':'+video_data.title;

    if (e["data"] == YT.PlayerState.PLAYING && YT.gtmLastAction == "p") {

        dataLayer.push({

            event: "youtube",

            action: "play",

            label: label

        });

        YT.gtmLastAction = "";

    }

    if (e["data"] == YT.PlayerState.PAUSED) {

        dataLayer.push({

            event: "youtube",

            action: "pause",

            label: label

        });

        YT.gtmLastAction = "p";

    }

}

// catch all to report errors through the GTM data layer

// once the error is exposed to GTM, it can be tracked in UA as an event!

// refer to https://developers.google.com/youtube/js_api_reference#Events onError

function onPlayerError(e) {

    dataLayer.push({

        event: "error",

        action: "GTM",

        label: "youtube:" + e

    })

}

// report the % played if it matches 0%, 25%, 50%, 75% or completed

function onPlayerPercent(e) {

    if (e["getPlayerState"]() == YT.PlayerState.PLAYING) {

        var t = e["getDuration"]() - e["getCurrentTime"]() <= 1.5 ? 1 : (Math.floor(e["getCurrentTime"]() / e["getDuration"]() * 4) / 4).toFixed(2);         if (!e["lastP"] || t > e["lastP"]) {

            var video_data = e["getVideoData"](),

                label = video_data.video_id+':'+video_data.title;

            e["lastP"] = t;

            dataLayer.push({

                event: "youtube",

                action: t * 100 + "%",

                label: label

            })

        }

        e["lastP"] != 1 && setTimeout(onPlayerPercent, 1000, e);

    }

}

// Crossbrowser onbeforeunload hack/proxy

// https://developer.mozilla.org/en-US/docs/WindowEventHandlers.onbeforeunload

window.onbeforeunload = function (e) {

var e = e || window.event;

// For IE and Firefox prior to version 4

if(e)

e.returnValue = 'na';

// For Safari

return 'na';

};

window.onbeforeunload = trackYTUnload;

function trackYTUnload() {

for (var i = 0; i < gtmYTplayers.length; i++)

if (gtmYTlisteners[i].getPlayerState() === 1) { // playing

var video_data = gtmYTlisteners[i]['getVideoData'](),

label = video_data.video_id+':'+video_data.title;

dataLayer.push({

event: 'youtube',

action: 'exit',

label: label

});

}

}

// load the Youtube JS api and get going

var j = document.createElement("script"),

    f = document.getElementsByTagName("script")[0];

j.src = "//www.youtube.com/iframe_api";

j.async = true;

f.parentNode.insertBefore(j, f);

</script>

2) How can I embed the video so that the size is fluid? The code currently defines the width and height in a static manner. This is how I'm embedding each video currently:

<center>

<style>

   .videoWrapper { position: relative; padding-bottom: 56.25%; /* 16:9 */ padding-top: 25px; height: 0; }

.videoWrapper iframe { position: absolute; top: 0; left: 0; width: 100%!important; height: 100%!important; }

</style>

<div class="videoWrapper">

<iframe width="640" height="360" src="https://www.youtube.com/embed/R5mdtglmRnk?rel=0" frameborder="0" allowfullscreen></iframe>

</div>

</center>

Thank you in advance for your help!