Track anchor links with munchkin? | Community
Skip to main content
Grant_Booth
New Participant
February 15, 2019
Question

Track anchor links with munchkin?

  • February 15, 2019
  • 2 replies
  • 3772 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Grant_Booth
New Participant
February 15, 2019

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
New Participant
February 15, 2019

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

SanfordWhiteman
New Participant
February 15, 2019

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
New Participant
December 10, 2020

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.