SOLVED

How to track clicks on anchor links?

Go to solution
NestoJosa
Level 3

How to track clicks on anchor links?

Hello community!

 

How to track clicks on anchor links?

 

We have implemented tracking on a page, but we are not getting any logs for clicks on anchor links.

 

According to (Marketo Master Jedi 😀) @SanfordWhiteman, Munchkin ignores clicks by default on 'links whose destination appears to be a hash (fragment) on the current page: - a below-the-fold jump link like <a href="#section1">"...' - https://blog.teknkl.com/more-munchkin-untracked-links-part-1/

Note I was not able to find the part 2 of the above mentioned post.


Furthermore, he provides the code that should solve the problem, in the following post, using what he calls the 'the mchReDecorate technique': https://nation.marketo.com/t5/product-discussions/track-anchor-links-with-munchkin/td-p/97774

Now, I tried to implement it, but it's not working - we are still not getting any logs for clicks on anchor links.

 

Do you know how to solve this problem and can you please share the solution?

 

Or can you give further info on how to properly apply the so called mchReDecorate technique?

 

I have written to Marketo Support for further assistance, and I will make sure to update this post for future googlers if I manage to solve it via their help.

Thanks in advance for your time!

 

Best,
ernie

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to track clicks on anchor links?

The code is designed to run on DOMContentLoaded, but you’re loading it after that event fires because you’re injecting it via GTM. Therefore it’s waiting for an event that never comes.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: How to track clicks on anchor links?

You’d have to show the page you’re trying this on. Nothing particularly complex about the code unless you have other code deliberately calling stopImmediatePropagation(), which stops additional listeners from firing.

NestoJosa
Level 3

Re: How to track clicks on anchor links?

Here is the page where I am trying your code:

<url-to-site-removed>

The code used is from your post found here:

https://nation.marketo.com/t5/product-discussions/track-anchor-links-with-munchkin/m-p/97775/highlig...

How did I implement it?

- Added via GTM

- The code is added when user gives consent to cookies (via "Accept all" on the cookie banner).

Thanks for the help!

NestoJosa
Level 3

Re: How to track clicks on anchor links?

Update


Now that I removed the code, and added it again it seems like something is actually happening:
<screenshot-removed>

But I am getting inconsistent results - not all anchor links are being tracked.

I'm currently in the process of finding out what works and what does not work...

SanfordWhiteman
Level 10 - Community Moderator

Re: How to track clicks on anchor links?

The code is designed to run on DOMContentLoaded, but you’re loading it after that event fires because you’re injecting it via GTM. Therefore it’s waiting for an event that never comes.

NestoJosa
Level 3

Re: How to track clicks on anchor links?

@SanfordWhiteman Thanks for the help!

I was under the impression that one could use the DOM Ready GTM trigger in order to run the code on DOMContentLoaded, but that was not correct.

After moving the code injection (from GTM to adding it directly to the head tag) it now works - clicks on anchor links are now being tracked.

Thanks again for the help!

Best,
ernie