Let’s say you want to segment leads in Marketo based on if they have a started or finished a specific video. This is possible to do using Munchkin, YouTube’s Iframe API, and Smart Lists in Marketo.
The example code in this post will let you to send video started and video finished events into Marketo through Munchkin. For this to work, Munchkin must also be loaded on the page before you can start sending video view events into Marketo.
The video started and finished will show up on the lead’s activity log as shown in the first and second screenshot below.
After the data is in Marketo, you can then create a smart list and segment leads that have started or finished a video, as shown in the screenshot below.
Step One: Get the id of the YouTube video you want to embed.
From the URL of the YouTube video you would like to use, note the id, which is the series of random characters after “v=”.
Step Two: Place YouTube video id from Step One in the eighth line of this code sample. Then place the code before the </body> in the HTML of your page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<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 = 'iiqxcjxJ5Us'; 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> |
Step Three: Create a Smart List in Marketo with the URL of the video and the view event you are looking for as the value of “Querystring contains”.
Here is a page with a working example of the implementation below.
For more information about YouTube Iframe API, please visit YouTube’s API documentation. For more information about Munchkin, please review the Marketo developer documentation.