Updated: Tracking Embedded YouTube and Wistia Videos in Marketo

Update 5/26 – I’ve fixed a player dimensions issue with the Wistia embed script, and added the ability to track both video starts and video completions. I’ve also updated the token naming conventions with a clearer, more consistent naming convention. Finally I removed the munchkin script call at the top of each embed code (though enabling Munchkin API is still necessary). It’s not necessary if you already have munchkin installed on your pages. Let me know if these changes are helpful!

A common need among Marketo users lies in the ability to track embedded video engagement with their prospects and customers. Marketo will natively track form submissions and web page activity, but it does not have great built-in video tracking functionality.

Since it’s important for marketers to understand when their target audiences actually view or interact in a certain way with a video, and not just that they visited a web page that happened to have a video on it, a more robust solution is needed. There are vendors who specialize in tracking video behavior in your marketing automation, but for basic tracking, you can do it yourself, and I’ll show you how.

By leveraging Marketo’s munchkin API in conjunction with an API-enabled video hosting service like YouTube or Wistia, it’s easy to build this integration yourself. Before we get any further: don’t get scared off by terms like “API”–this particular piece of functionality is actually pretty simple to implement with a basic understanding of HTML and Marketo, and I’ve hopefully done most of the heavy lifting for you. Plus, it’s a great practical demonstration of the extensibility of the Marketo platform.

This implementation works by using the video player to tell Marketo when it’s state changes from not playing to playing (in other words, when the lead clicks the play button on an embedded video). Then Marketo logs a web page visit event in the lead’s activity log, which can be used to trigger other actions off of Marketo, such as an interesting moment or program status change.

First Things First: Enable Munchkin API

Before we get into the specifics of how this works, you’ll first need to set up your Marketo instance to use the Munchkin API. Marketo Admins should first navigate to their admin section > Integration > Munchkin > Edit API Configuration. You’ll want to check the box labeled “Enable Munchkin API”

Enable Munchkin APIWhile you’re on your Munchkin Settings, also make note of your nine-digit Munchkin ID (formatted as XXX-XXX-XXX). You’ll need this later.

Now that you have this squared away, you’re set to start setting up your customized embed code. I’ve set up codes for both YouTube and Wistia. While YouTube is certainly a more widely used platform, I’ve started using Wistia more recently because of the issues with corporate IT filters blocking YouTube videos for B2B users. While this isn’t always an issue for embedded videos, I ended up preferring the the customization and business focus of Wistia. It’s a matter of personal preference I’ll leave up to you. For each guide, I’ve included standard embed codes, and tokenized codes (if you’re using your Marketo Programs).

Option 1: Embedding with My.Tokens

I mentioned that there are two versions of these embed codes – a standard and a token enabled script. If possible, you really should use the token-enabled script. You’ll find it’s far easier to work with, so long as the page you want to embed your video on is contained within a Marketo Program.

First are the modified versions of the embed codes for Wistia and YouTube that are set to accept Marketo’s My Tokens, which work within Programs. Also make special note the highlighted section for Munchkin ID. You will want to set this manually, since it’s the same value for your entire Marketo instance. Your tracking will not work without setting this up.

To set up video play tracking for a Wistia or YouTube video, you’ll need a few things:

  1. Your video ID (10 digit code that you can find in the embed code on Wistia, or on the video URL – The same is true for YouTube, but the code is 9 digits)
  2. Video height and width dimensions (eg 550×309)
  3. A “play” URL that you want Marketo to log anytime the video is played
  4. Your 9-digit Munchkin ID

Next, you’ll need a landing page to embed your video to. Generally it’s advisable to do this within a program so that you can make use of the token-enabled script, however if you’re comfortable editing the script yourself and cannot make use of program tokens, you can install the videos on really any landing page using the standard scripts at the end of this post.

If you plan to use the token-enabled script, here are the tokens you’ll need to create (all should be plain text tokens):

  • My.Video – ID: the 10 digit video ID from wistia  (9 digit for YouTube)
  • My.Video – Width: The pixel width of the video (note: this should be input as a numerical value only, eg: “550”, and not “550px”.)
  • My.Video – Height: the pixel height of the video (same instructions as my.videowidth)
  • My.Video – Name No Spaces: this is the fictitious URL you define that will display in the Marketo activity log. You can set anything you want here, but I generally like to follow a similar naming convention to the page that the video is embedded on. I’ll clarify with an example: if your video is embedded on info.yourdomain.com/myvideo.html,  you might want the log to display info.yourdomain.com/myvideo/play when the video is played. In that case, you’ll want to set this token value as “myvideo”. Do not include any other part of the URL – Marketo will do that automatically. Note that this script logs a video start and a video complete event. You can opt to use one or the other, or both at the same time.
  • My.Video – Player Color: This one is optional, and only for Wistia, but it controls the color of the video player. You don’t need to set a value here, but if you want to customize it to your own video branding, feel free to use your own hexadecimal color code. (eg 6688AAD – no # needed)

Below are the scripts you’ll want to place within an HTML object on a Marketo landing page. Note: The codes below will replace any embed code you would ordinarily retrieve from Wistia or YouTube directly. These will handle both the embed of the video and the tracking and integration within Marketo.

Remember – you must update the highlighted sections with your specific Marketo 9-digit Marketo ID (including hyphens).

You can also download all the scripts via my GitHub repository of this project.

 Wistia (With Tokens)

<!--Video embed (this is what embeds the Wistia player)-->
<div id="wistia_{{my.Video - ID:default=c6xf9ao18h}}" class="wistia_embed" style="width:{{my.Video - Width:default=550}}px;height:{{my.Video - Height:default=309}}px;" data-video-width="{{my.Video - Width:default=550}}" data-video-height="{{my.Video - Height:default=309}}"></div>
<script charset="ISO-8859-1" src="//fast.wistia.com/assets/external/E-v1.js"></script>
<script>
 wistiaEmbed = Wistia.embed("{{my.Video - ID:default=c6xf9ao18h}}", {
 videoWidth: {{my.Video - Width:default=550}},
 videoHeight: {{my.Video - Height:default=309}},
 playerColor: "{{my.Video - Player Color:default=688AAD}}"
 });
 // the functions below will watch for the video to be started or ended (tracked via state changes), and translating that to page visits in Marketo. 
 wistiaEmbed.bind('play', function() {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/{{my.Video - Name No Spaces}}/played', params: 'x=y&2=3'
 });
 });
 wistiaEmbed.bind('end', function() {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/{{my.Video - Name No Spaces}}/completed', params: 'x=y&2=3'
 });
 });
</script>

YouTube (With Tokens)

<!--Youtube iframe embed script with Munchkin integration-->
<div id="player"></div>
 <script>
 // 2. This code loads the IFrame Player API code asynchronously.
 var tag = document.createElement('script');
 tag.src = "https://www.youtube.com/iframe_api";
 var firstScriptTag = document.getElementsByTagName('script')[0];
 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
 // 3. This function creates an <iframe> (and YouTube player)
 // after the API code downloads.
 var player;
 function onYouTubeIframeAPIReady() {
 player = new YT.Player('player', {
 height: '{{my.Video - Height:default=309}}',
 width: '{{my.Video - Width:default=550}}',
 videoId: '{{my.Video - ID:default=c6xf9ao18h}}',
 playerVars: { 'showinfo': 0, 'controls': 2, 'rel': 0 },
 events: {
 'onReady': onPlayerReady,
 'onStateChange': onPlayerStateChange
 }
 });}
 // 4. The API will call this function when the video player is ready.
 function onPlayerReady(event) {
 }
 // 5. The API calls this function when the player's state changes, and sends a visit web page action to Marketo via the Munchkin API
 var done = false;
 function onPlayerStateChange(event) {
 if (event.data == YT.PlayerState.PLAYING && !done) {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/{{my.Video - Name No Spaces}}/started', params: 'x=y&2=3'
 });
 }
 else if (event.data == YT.PlayerState.ENDED && !done) {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/{{my.Video - Name No Spaces}}/completed', params: 'x=y&2=3'
 });
 }
 }
 </script>

Standard Embed Codes

If for some reason you can't use your video within a Marketo program and use the tokenized codes above, the standard codes below will also work, just know that you must edit the highlighted portions with your video and Marketo info. Take extra care with the Wistia embed code, as variables like video player dimensions and ID must be edited in several places. Again, use the tokenized version above if you can! Finally, note the highlighted portion for “url”. Remember, this is the name of the URL you wish to have logged in a lead’s Marketo activity log when the video is played. This can be set to anything, and doesn't need to be an actual working URL. In the example of a webinar, your URL could be “myQ2Webinar/play”. Note to only include the page name and then something afterwards to distinguish the actual page from the play action, such as  "/play". Do not include any prefixes or domains (http, www, domainname.com, etc).

Wistia (Standard Script, no Tokens)

<!--Video embed (this is what embeds the Wistia player)-->
<div id="wistia_29b0fbf547" class="wistia_embed" style="width:550px;height:309px;" data-video-width="550" data-video-height="309"></div>
<script charset="ISO-8859-1" src="//fast.wistia.com/assets/external/E-v1.js"></script>
<script>
wistiaEmbed = Wistia.embed("29b0fbf547", {
 videoWidth: 550,
 videoHeight: 309,
 playerColor: "688AAD"
});
 // the functions below will watch for the video to be started or ended (tracked via state changes), and translating that to page visits in Marketo.
wistiaEmbed.bind('play', function() {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/YourVideoName/started', params: 'x=y&2=3'
});
});
 wistiaEmbed.bind('end', function() {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/YourVideoName/completed', params: 'x=y&2=3'
 });
 });
</script>

YouTube (Without Tokens)

<!--Youtube iframe embed script with Munchkin integration-->
<div id="player"></div>
 <script>
 // 2. This code loads the IFrame Player API code asynchronously.
 var tag = document.createElement('script');
 tag.src = "https://www.youtube.com/iframe_api";
 var firstScriptTag = document.getElementsByTagName('script')[0];
 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
 // 3. This function creates an <iframe> (and YouTube player)
 // after the API code downloads.
 var player;
 function onYouTubeIframeAPIReady() {
 player = new YT.Player('player', {
 height: '390',
 width: '640',
 videoId: 'kTcRRaXV-fg',
 layerVars: { 'showinfo': 0, 'controls': 2, 'rel': 0 },
 events: {
 'onReady': onPlayerReady,
 'onStateChange': onPlayerStateChange
 }
 });}
 // 4. The API will call this function when the video player is ready.
 function onPlayerReady(event) {
 }
 // 5. The API calls this function when the player's state changes, and sends a visit web page action to Marketo via the Munchkin API. Make sure to update the mktoMunchkin value to match your specific account ID (Admin > Integration > Munchkin)
 var done = false;
 function onPlayerStateChange(event) {
 if (event.data == YT.PlayerState.PLAYING && !done) {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/YourVideoName/started', params: 'x=y&2=3'
 });
 }
 else if (event.data == YT.PlayerState.ENDED && !done) {
 mktoMunchkin("XXX-XXX-XXX");
 mktoMunchkinFunction('visitWebPage', {
 url: '/YourVideoName/completed', params: 'x=y&2=3'
 });
 }
 }
 </script>
Once you've successfully embedded your codes, It's time to test out your page. Visit the Marketo landing page you've just created, and click the play button on your video. Make sure to be using a browser that has already been cookied by Marketo (An easy way to confirm this is to visit a Marketo page with a form on it - if the form is pre-filled with your information, you're cookied). Then, search for your lead record in the Marketo lead database, and click over to the activity log. You should see something like this: activity log This web page will now appear anytime the video you've set up is played. Cool, huh?

Triggering flowsteps off video play behavior

So what do you do now? Now that you've got your videos tracked in Marketo, it's time to have Marketo do something interesting with that information. Since you've logged a web page visit, you can now use the "visited web page" trigger or corresponding filter in a Marketo Smart Campaign to trigger activities off of video plays. web page trigger   For example, you could log an interesting moment anytime your video is played. Your sales team will thank you for this, as you can log something very explanatory, like "Viewed Video: Q2 Product Demo" instead of "visited web page my-landing-page-Q2_Demo-V8.html/play." In the past I've discussed how to centralize your content tracking through Marketo programs. You can do the same with videos too, and log a program success when a lead plays one of your videos. This is especially helpful if you want to view all the leads who've watched your video, or to calculate return on the investment of a video's production. Flowstep   Keep in mind that these examples work best when the lead is already known in your database. So in the case of a recorded webinar, where you've probably got a form sitting in front of that video, it's safe to assume that you'll probably have known visitors being tagged with video views. But if the video is a general marketing video that may be sitting on its own, you will likely have anonymous as well as known visitors. Marketo will still track both, but logging a program status change or interesting moment is really only of value to known leads. So you may consider dropping in a filter to your smart campaigns to exclude anonymous leads, or just be willing to accept some anonymos leads in your program reports.

Moving beyond the basics

I built this integration because it solved a very specific problem for me, yet there are pretty limitless possibilities with expanding on this. With a bit of work, it's likely possible to track more nuanced behavior, such as viewing a video for a specified period of time, or observing the degree to which the video is started and stopped. I constructed this integration using the following resources. Feel free to use these in your own efforts! Marketo Munchkin API Documentation Wistia Player API Documentation Youtube JS Player API Reference As I mentioned earlier, I've started with Wistia and YouTube, but there are probably plenty of other video players you could build similar integrations with, such as Vimeo. Most of their APIs are fairly similar to work with, so it's probably just a matter of adapting the existing scripts to other players' specific operations. If you're interested in other applications of this, let me know in the comments!


Comments

23 responses to “Updated: Tracking Embedded YouTube and Wistia Videos in Marketo”

  1. Thanks for the tip Jeff. Have you found a way to integrate Wistia Turnstile form fills for email capture with Marketo cookies so you can get Marketo inferred company data on turnstile form fills? The turnstile integration is all via API so it doesn’t use any other data Marketo may know about the user.

    Seems doable with the Wistia Conversion event, but haven’t thought it through yet…

    Travis

  2. Jeff Shearer Avatar
    Jeff Shearer

    Hey Travis,

    I haven’t played with Turnstile much yet. Part of me has avoided it because the prospect of an incredibly short form – just name and email, causes some problems on my end from a data processing & routing perspective. I am very interested in the idea of passing external integrations into Marketo’s cookies, so would love to hear anything you may find. I’m admittedly still a novice when it comes to anything developed around cookies though.

  3. Hey Jeff! This is pretty awesome! Do you know if this code would work with Brightcove, with modification, but was curious.

    Thanks!

    Danielle

  4. Jeff Shearer Avatar
    Jeff Shearer

    Hey Danielle,

    Thanks! Looks like Brightcove has a media API, so I would be willing to bet it’s possible with modification. The main piece you just need to figure out is how to map the video player’s state changes to the Munchkin web page event. If you find a way to modify it, definitely let me know, as I’d love to point to it for anyone interested in that particular integration!

  5. hi Jeff;
    Thanks for your support.
    I am facing a problem in tracking videos on a normal website page hosted by wordpress.
    I want to track the play and pause actions of a video by the user.
    So i tried the past steps but they didnot work.
    Please help;

  6. Thanks for the tip Jeff.
    I used your code on my website but the results are not showing in Marketo.
    I am using WordPress and youtube api.
    The results appear in marketo are the simple visit web page URL .
    So please help.

  7. Thanks for this! Will the code work with the Wistia popover embed?

  8. Jeff Shearer Avatar
    Jeff Shearer

    Hey Naor,

    I haven’t tested it there, but I’d assume so, but could require a bit of work around the code to make it happen.

  9. Jeff Shearer Avatar
    Jeff Shearer

    Hey Tarek,

    Hard to say what exactly is going on there – I mainly built the integration to play within Marketo landing pages, and while it’d theoretically work on non-Marketo pages with Munchkin installed, it’s not a use case I was building to. One thought would be if you’re using the token-enabled script, those tokens may not render on your offsite page.

  10. Cameron Avatar
    Cameron

    Hey Jeff,
    First, GREAT POST, thanks very much!!
    Second, @Travis, did you get anywhere further with Wistia Turnstile? While I agree with Jeff that the form isn’t great, it’s something that I can track and score – if I can get it to work.
    I’ve got a number of recorded webinars I need to gate and want to use Turnstile to do it, but in testing I’m not seeing activities logged in the lead database.
    Background: videos live in Wistia, SEO embed type using FOAM on non-Marketo wordpress pages.
    Any advice?
    Cheers,
    Cameron

  11. @cameron I never found a way to connect the dots with Turnstile + Inferred company info in Marketo. The fact that Wistia creates the lead via API on the backend makes connecting to the browser session tricky. We haven’t seen a huge increase in gated webinar views in using turnstile, so I’m going to try to just build a Forms 2.0 form in Marketo that mimics the look of Turnstile with the additional fields I want (first, last, company, website, phone, email), then the follow-up/thank you page would return the ungated wistia video in the same div. It’d be a similar experience for the end user I think and still give us all the additional fields we need to score & route leads appropriately.

  12. Hi Jeff! Just was googling about and came across your post here. Thanks for sharing such useful content!

    We actually _just_ launched a proper integration with Marketo (http://wistia.com/product/marketo), it handles the viewing activity tracking that you explain here and also pipes Turnstile entries to Marketo (complete with the Marketo cookie so you can tie it to that contact’s other activity).

    @travis, regarding the “inferred company info” (or lead enrichment), we’re planning to do some work on that in the coming months. Curious to hear your thoughts on it and what you’re looking for. Feel free to email me at brendan at wistia!

  13. Jeff Shearer Avatar
    Jeff Shearer

    Hey Brendan–awesome news, I’ll be sure to check it out. Love Wistia!

  14. Jason Hamilton Avatar
    Jason Hamilton

    Hi Jeff,
    This is great!!
    Do you know of any way to make it responsive?

  15. Jeff Shearer Avatar
    Jeff Shearer

    Hey Jason,

    It depends more on what framework you’re using for responsive pages. If you’re using bootstrap, just call one of their video embed divs, or note the class directly in the iframe as noted here: http://getbootstrap.com/components/#responsive-embed

    That’s what I do!

  16. Jason Hamilton Avatar
    Jason Hamilton

    I am using Bootstrap, so this is perfect! I just wrapped a div around it, but if I did want to add the class directly to the iframe, how would I do that since it dynamically being created by the api?

    Thanks,
    Jason

  17. Jeff Shearer Avatar
    Jeff Shearer

    Hey Jason,

    Good question. And actually, I’ve got my wires crossed. For this implementation, you can’t put the class within the iframe for the reasons you specified.

    That said, I’ve actually started using a variation on this implementation that leverages Google Tag Manager to fire page views to the Munchkin API when specific play events occurs. It works with less code on the embed script, so in that case, my embed code looks pretty much like any other YouTube embed code, which is why I was initially thinking you could put the class in the iframe.

    I’ll share that new process when I get a chance, as it has some pretty cool implications for video view progress tracking, but in the meantime, I’d say calling the responsive class within the div will be your best bet.

  18. Christina Avatar
    Christina

    Hi Jeff, great session at Summit today! Just to check – the Youtube code posted is meant to work with the marketo youtube local asset, right? That’s how I’m adding videos to my landing pages – via a local youtube asset.

  19. Jeff Shearer Avatar
    Jeff Shearer

    Hey Christina – It may be possible to use the video element (I believe that’s what you’re referring to) and track, however the method I’ve outlined above is intended to be used as a straight embed into a rich text or HTML element. The reason for this is that there is some custom code within the embed script itself, and I believe the video element will strip all that out.

    That said, I’m actually working on a v2 of this method that is much easier to implement (no custom embed code required), and offers deeper tracking on video view progress. I’ll update this article once I have it ready, so stay tuned.

  20. Hi Jeff,

    Thank you for your informative article. I’m wondering if either of the approaches you’ve outlined for tracking YouTube plays will work on a landing page built outside of Marketo? I’m working on a WordPress-based site with Marketo integration, and creating a landing page with a YouTube video that opens in a modal/lightbox, and we’d like to track plays in this way– is this possible with your approach?

    Thank you for any feedback!
    Nick

  21. Jeff Shearer Avatar
    Jeff Shearer

    Hey Nick,

    Sorry for the huge delay in my response – I must have missed the notification for this one. I can say that an adapted version of this approach will work outside of Marketo landing pages, so long as you have munchkin installed on the pages you’re working in. The token method won’t work, but a straight embed of the video, plus the additional code to reference the YouTube API and the Munchkin API should work on any site that uses Munchkin.

    I’ve also been sitting on an update for this article, as I currently use an entirely new method with Google Tag Manager. I’ll try and get that update posted, as it may be of use to you as well.

    Hope this helps,

    -Jeff

  22. Hello,

    Is there a way to use this script with a popover video ?

    Thank you,
    Radu

  23. Jeff Shearer Avatar
    Jeff Shearer

    Possibly – but I’ll admit that would be out of my wheelhouse to explain. As long as you can get the script to fire on the popup, I see no reason why this wouldn’t work, however. You’d just need to make sure munchkin exists on the popup as well.