Mura Content Personalization Blog

Insights from the Tactical to the Strategic

Sending Custom Querystrings to Marketo

Marketo is great for tracking page-based activity on your site, such as the user landing on a particular page, or clicking a link. But what about non page-load actions? Many of today's websites use asynchronous elements, otherwise known as AJAX, which is activity that that can happen on a site without the page actually reloading (think of when you scroll to the bottom of your Facebook page and more posts load). This kind of activity can be difficult to track in Marketo because it's usually an even that happens in the background, and the Munchkin tracking code mostly tracks things only when the page loads. 

Another issue is if you're utilizing personalization, A/B Testing, or any other form of "versioned" content. Marketo may track a web page visit, but might not be aware of which version that user is visiting.

One trick I came across to help with this, is Munchkin's ability to send custom events to Marketo via Javascript. By using this, I can not only hook into my custom ajax events (videos, slideshows, etc), but I can also pass in custom variables into the function that includes more info about that users specific interaction. 

How it works

When you look at a lead's activity, you will see several different events, such as "Clicked Link", "Visited Webpage", etc. We're going to tie into the "Visits Web Page" function so we can pass in a custom query parameter.

The basic structure of the function looks like this:

Munchkin.munchkinFunction('visitWebPage', {
    url: '/Some/URL', params: 'x=y&2=3'
});

Note: the URL doesn't even have to be real!

Now, this is nice for a one-off approach, but I like to make things reusable for other use cases down the road. So I turned this into a function:

function addParam(params){
    var querystring='';
    
    //loop through the params to build the querystring
    for (var i in params){
        querystring += i + '=' + params[i] + '&';
    }
    
    //let's lose the final '&'
    querystring = querystring.substring(1, querystring.length - 1);
    // add the querystring to the current URL
    Munchkin.munchkinFunction('visitWebPage', {
         url: document.location.path, params: querystring
    });
}

What this does is allow us to call the addParam function wherever I want and pass in an array of values to build a final querystring.

So, for a video play button for example, we can do this:

<!-- Create our video play button -->
<a id="play-video-button" href="#" data-videoTitle="HomepageVideo">Play</a>
<!-- when the user clicks the play button, send the custom event -->
<script>
$('#play-video-button').on("click", function(){
    var videoTitle = $(this).data('videoTitle');
    
    addParam({
        "playedVideo":true,
        "videoTitle":videoTitle
    });
});
</script>

Or, maybe we're doing some A/B testing on the homepage and trying to see which layout gets the most video clicks. We could pass in a version variable as well to our button:

<a id="play-video-button" href="#" data-videoTitle="HomepageVideo" data-layoutVersion="A">Play</a>
<script>
$('#play-video-button').on("click", function(){
    var videoTitle = $(this).data('videoTitle');
    var layoutVersion = $(this).data('layoutVersion');
    
    addParam({
        "playedVideo":true,
        "videoTitle":videoTitle,
        "layoutVersion":layoutVersion
    });
});
</script>

Now, when the user clicks the "Play Video" button, it will log a "Visit Web Page" activity for the user with ?playedVideo=true&videoTitle=HomepageVideo&layoutVersion=A attached to the current URL:

Creating a Marketo Trigger Campaign

Now that we have this logged in the users Activity Log in Marketo, now we can hook into it with a trigger campaign.

Start with a new Smart Campaign:

In the Smart List, pick the "Visits Web Page" trigger:

In the top right of the module, you will see "Add Constraint". Select "Querystring":

From there, you will be able to put in any or all of the querystring parameters for your criteria:

You can mix and match your criteria as you wish. For instance, if you want to see all people who played a video and were viewing Version A, you would add playedVideo=true & layoutVersion=A

You can use this technique to pull all kinds of reports later, such as all users who played a video.

Conclusion

When it comes to content marketing, tracking landing page activity just doesn't tell the whole story. Now that you are tracking more robust information with your leads, you can use Marketo to create trigger campaigns and send those leads to more meaningful nurture programs.  

About the Author