Track File Links?

Lisa_Heay2
Level 3

Track File Links?

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.

Tags (2)
36 REPLIES 36
SanfordWhiteman
Level 10 - Community Moderator

Re: Track File Links?

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.

Lisa_Heay2
Level 3

Re: Track File Links?

Interesting - ok.  How do I implement a redirector page so that I can track the pageview?

Lisa_Heay2
Level 3

Re: Track File Links?

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!

SanfordWhiteman
Level 10 - Community Moderator

Re: Track File Links?

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.

Lisa_Heay2
Level 3

Re: Track File Links?

Perfect - thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Track File Links?

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 = [

         'http://pages.example.com',

         'http://www.example.com',

         'http://example.com'

        ], // which domains are allowed for redirection

        redirectMs = 3500, // how long before redirecting 

        progressMs = 500,  // how long between updates of the "progress meter"

        progressChar = '&bull;', // 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:

2017-01-27 23_37_04-Marketo _ Redirect detect (Smart List) • Marketing Activities.png

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: Track File Links?

JD_Nelson
Level 10 - Community Advisor

Re: Track File Links?

Hey Sandy - I've been using this functionality for quite a while and love it -- thanks.

We've started putting some links in an email here or there that are directing people to a 3rd party site -- for us it's when we're mentioned in a certain publication or press release. I'd like to track the clicks to that article with the justification of 'visited web page' so I know it's not spam, but the redirector doesn't work for sites off my domain, right? So is there a workaround you'd suggest for that scenario?

SanfordWhiteman
Level 10 - Community Moderator

Re: Track File Links?

Sure, it'll work for sites off your domain, just whitelist them (you don't want to create an open redirector) in the allowedDomains array at the top of the code.