We have our resource files (PDFs - guides, ebooks, etc.) loaded in Marketo. We share these links via landing pages, Marketo emails, etc, but often times we will also share a direct link to a file through a social post (tweet, facebook, LinkedIn, etc.) or personal/Outlook (non-Marketo) email. We want to be able to track link clicks when someone engages through one of those outside means. I'd also like to be able to trigger a Marketo campaign with a follow up cadence when a click occurs. Is this possible? This may be a dumb question - forgive me, it's Friday.
It's not a dumb question.
You can't track the actual click/tap event on a site that isn't running Munchkin. You can, however, track the subsequent pageview that results from visiting a Munchkin-tracked redirector page, before that page redirects to the actual downloadable asset.
In fact this is the way everyone should share assets. Sending direct links to assets, even from Marketo-generated emails, is bad for tracking.
Genius solution Sanford Whiteman, love your work... AGAIN!
Thank you
Interesting - ok. How do I implement a redirector page so that I can track the pageview?
Most importantly, I'd like to be able to trigger a smart campaign when someone clicks one of these asset links. Any guidance you could provide would be much appreciated. Thank you!
Yep, triggering an SC works fine. Your goal is to capture the pageview, and what you do with it is up to you.
I'm on my phone but a little later I'll give you a few lines of lightweight/primitive code to create a flexible redirector page.
Perfect - thank you!
OK, I'm going to give you the easiest, dirt-simple, this-isn't-the-way-I-would-do-it-but-here-I-am-showing-it-to-you-anyway method.
Add this to the document <head> of your redirector page (which should be otherwise empty). Turn off Munchkin at the page level as you're loading it manually.
<script type="text/javascript">
document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin-beta.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
Munchkin.init('111-222-333'); // your Munchkin ID and options, obviously!
</script>
<script>
(function(redirectTarget){
var allowedOrigins = [
], // which domains are allowed for redirection
redirectMs = 3500, // how long before redirecting
progressMs = 500, // how long between updates of the "progress meter"
progressChar = '•', // progress character (HTML bullet)
errNoAsset = 'Asset URL not found.', // message when no asset in hash
errInvalidAsset = 'Asset URL not allowed.', // when asset not our domain
progress = setInterval(function(){
if (redirectTarget) {
document.body.insertAdjacentHTML('beforeend',progressChar);
} else {
clearInterval(progress), clearTimeout(redirect);
document.body.insertAdjacentHTML('beforeend',errNoAsset);
}
}, progressMs),
redirect = setTimeout(function(){
var redirectLoc = document.createElement('a');
redirectLoc.href = redirectTarget;
clearInterval(progress);
if (allowedOrigins.indexOf(redirectLoc.origin) != -1) {
document.location.href = redirectTarget;
} else {
document.body.insertAdjacentHTML('beforeend',errInvalidAsset);
}
}, redirectMs);
})(document.location.hash.substring(1));
</script>
Then, to link to your assets, append your asset URL after the hash (#) in the redirector page: http://pages.example.com/redirector.html#http://example.com/redirected.pdf
You can then trigger on the asset downloads as pageviews:
The reason I don't do it exactly this way on my own production sites is that it adds a mandatory minimum delay before redirecting in expectation/hope that Munchkin will load + log completely in that period. The delay above is 3.5 seconds (3500ms) which is okay for, let's say, 99.99% of cases -- but not all. Instead we have a custom Munchkin library (we call it "Munchkin Enhanced") that can ensure the delay is just long enough for the hit to be logged, but no longer. Anyway, this should fit your needs for the most part.
For some reason this is not working in Internet Explorer (works in all other browsers), after the progress bar, page is stuck. But my Marketo campaign is still reporting that I have visited the pdf link...
Grab the updated code from the post now. There's an IE bug w/Location objects and I forgot to update the code inline.
There's another bug we discovered as we were using older versions of IE that does not process "IndexOf" properly, to fix this I added this if statement before the function and this fixed the issue.
<script>
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
}
(function(redirectTarget){
var allowedOrigins = [
'http://example.com' .......
Oh you were testing in IE 8? I don't build for IE 8 compat in a Marketo environment as core Mkto features don't work in IE 8, anyway.
Array#indexOf is in IE 9 and later.
Yes, unfortunatly our IT dept are slow to update browsers, the same applies to alomst all big companies out there, I know our clients still use older browsers. So for those out there still using older browsers, adding that fix for IndexOf will make this solution work for them. Either case thank you for your overall solution! and for anyone who is not following your blog.. IT IS A MUST READ for anyone in the Marketo world!
Yeah, I know IE8 is out there (though in finserv IT should be looking at it from from a security perspective, difficult or not!).
Just make sure you guys don't expect other Mkto things to work in IE8, like secure LPs and forms (the former being a valuable tracking tool, not just a security measure). And all my code is written for IE9+.
Sandy, i used the code from your blog. Was that code affected as well?
Hmm, maybe -- better get the latest from the demo: http://codepen.io/figureone/pen/GWZmGo/?editors=0010
Works fine in all browsers now - even Edge! Thanks Sandy.
This is a great tip, Sandy. We're always trying to provide for an optimized user experience - which includes minimizing the number of clicks to get to the call-to-action - and this approach works fantastic. I just finished building this in our instance and look forward to using it in our future campaigns.
Great, Dan!
Hi Sanford, I tried this and it seemed like a great solution. I also created a trigger to place people into salesforce campaigns to track those who had viewed the content. Seemed to work great for a few months, However It seemed to stop working recently - where If i tested redirect link myself or had a coworker test the link, they wouldn't be tracked or brought into the triggered campaign. No changes where done recently it just seemed to have stopped. I do have to admit that I don't know what the requirements are and for who this work work for and for who it will not. On the very basic level, my assumptions are that it works for people whom we've already cookie'd with the munchkin previously? Does the munckin expire and perhaps that's why It may no longer work for some people?