Re: Track anchor links with munchkin?

Grant_Booth
Level 10

Track anchor links with munchkin?

Hi all,

I did some testing on our pages and noticed that munchkin doesn't make a Click Link activity for anchor links: for example someone on examplepage.com won't create an activity if they click the link examplepage.com#someID.

Is there a simple way to get munchkin to do this?

Grant

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Track anchor links with munchkin?

Yep, see

More links Munchkin won't track (unless you tell it to) - Part 1 of 2

and the mchReDecorate technique:

document.addEventListener('DOMContentLoaded', function(e) {

var arrayify = getSelection.call.bind([].slice);

var canonicalDocLocation = document.createElement("a");

canonicalDocLocation.href = document.location;

canonicalDocLocation.hash = "";

arrayify(document.links)

.map(function(link){

var canonicalLink = document.createElement("a");

canonicalLink.href = link.href;

canonicalLink.hash = "";

return {

original : link,

canonical : canonicalLink

}

})

.filter(function(linkDescriptor){

return linkDescriptor.canonical.href == canonicalDocLocation.href &&

( linkDescriptor.original.hash || /#$/.test(linkDescriptor.original.href) );

})

.forEach(function(linkDescriptor){

console.log("reattaching Munchkin to jump link", linkDescriptor.original);

linkDescriptor.original.addEventListener("click", function(){

Munchkin.munchkinFunction("clickLink",{

href : this.href

});

});

});

});

Diego_Lineros2
Level 7

Re: Track anchor links with munchkin?

This is very good, It is a shame Marketo is not giving the option out of the box. By the way, I was using this script in one LP, and it was working well across the board, but lately I noticed stop working in Chrome.

Grant_Booth
Level 10

Re: Track anchor links with munchkin?

Thanks Sanford! I was about to post that I'd found something that would work by putting the clickLink munchkin function into the hyperlink's onclick attribute, but I will check out the blog post as I would love to find something universal.

SanfordWhiteman
Level 10 - Community Moderator

Re: Track anchor links with munchkin?

Use the code above. No need to hijack the inline onclick attribute.