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
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
});
});
});
});
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.
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.
Use the code above. No need to hijack the inline onclick attribute.