Back to main demo page

Web event tracking via Marketo munchkin API with YouTube example

How to track web events in Marketo

Marketo munchkin does not (yet) have events like Google Analytics, so in order to track web events like video plays there are only two choices:

My preference is to use the clickLink as URL parameters are harder to segment inside Marketo. My scheme for storing events is to build a fake url as follows:

ElementDescriptionExample
Base Pathjust the page name, strip the URL of the domain and any parameters/marketo-munchkin-event-tracking
Event Sourcesomething to uniquely identify the content source such as the video name or id. You're going to use this name later as part of the segmenation and should be unqiue across all your creatives/no-cookies
Event TypeOne of a list of possible tracking events you would like to categorize. This is your created list, below are some suggestions:
  • video
  • youtube
  • etc
/youtube
Event ActionAn action associated with to the particular event. You can choose your action names to suit your needs but I would suggest they make sense in the context the action names are used. For videos, you might choose:
  • play
  • pause
  • stop
/play

So a visitor on this page, playing a video in a youtube container would have an fake event url built up as follows:

     /marketo-munchkin-event-tracking/no-cookies/youtube/play.

Note: for this tracking to work you must have already loaded and initialized Marketo's munckin tracking code before calling this function, otherwise the clickLink function will fail.

sample code for tracking callback function


<script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" language="Javascript" src="/jQuery.tubeplayer-1.0.3.min.js"></script>
<script type="text/javascript" language="Javascript" src="http://munchkin.marketo.net/munchkin.js"></script>
<script type="text/javascript" language="Javascript">

// use no conflict mode for jQuery
if (typeof $jQ == 'undefined') { var $jQ = jQuery.noConflict();}

function mktoVidEventTrack(event, eventType) {
  // clean up the pathname
  if (window.location.pathname.search(/\?/) != -1) {
     var refUrl = window.location.pathname.slice(sUrl.search(/\?/));
  } else {
     var refUrl = window.location.pathname;
  }
  // dynamically build the event url with the event name and event action
  refUrl += '/' + event.videoID + '/' + eventType;
  mktoMunchkinFunction('clickLink', { href: refUrl });
  return;
}

...

$jQ('document').ready({

  // make sure Munchkin is loaded and initalized
  mktoMunchkin("999-AAA-999");

  $jQ('#youtube-player-container').tubeplayer({
    autoPlay: false,
    initialVideo: 'ZJlkplvYdgA',
    onPlayerPlaying: function(){mktoVidEventTrack(jQuery('#youtube-player-container').tubeplayer('data'), 'play');},
    onPlayerEnded:   function(){mktoVidEventTrack(jQuery('#youtube-player-container').tubeplayer('data'), 'stop');},
    onPlayerPaused:  function(){mktoVidEventTrack(jQuery('#youtube-player-container').tubeplayer('data'), 'paused');}
  });
});
</script>

Marketo Smart Campaign Samples

Inside Marketo, you should build a "listener" campaign for each of your assets or events and then take an appropriate action. If your choose your action names wisely and uniquely, then you could build generic event tracking, only look for the action names in any urls using the contains criteria. In the example below, its built for tracking a specific video and I have shorten the relative URL link in the flow steps for illustration purposes.

Campaign Smart List

Marketo campaign trigger for tracking event

Campaign Flowsteps

Marketo campaign flowsetup for tracking event actions

 

Event Type handlers

To be able to track events for various items, it must have some sort of API/callback mechanism. Most modern JavaScript video players provide a mechanism and YouTube has created one as well. You aren't only limited to just video, you could put a link tracker in an ROI calculator and capture the data each time your lead fill it out.

Video JavaScript API reference documentation

jQuery video plugins with event callbacks

Tracking example

Use the YouTube example below to demonstrate video play events that you might want recorded in Marketo. To get started, just play the video and look for your events to the right of the video player.

Event



Back to main demo page