mixpanel-js icon indicating copy to clipboard operation
mixpanel-js copied to clipboard

Unwanted link navigation from `LinkTracker`

Open zzzzBov opened this issue 2 years ago • 0 comments

LinkTracker explicitly causes navigation to occur after tracking, which is fine for most types of links, however there are some circumstances where the link has other behaviors associated with it, and the navigation has already been prevented through preventDefault.

In these cases, LinkTracker will continue to make the link navigate to its location.

Please update the event_handler to also check evt.defaultPrevented before attempting to force a navigation.

As a simple example, the following link should not change the URL when clicked on:

<a href="#" role="button">Example</a>
<script>
document.querySelector('[role="button"]').addEventListener('click', (e) => {
  e.preventDefault();
  // ...other event handling here...
}, false);
</script>

zzzzBov avatar Oct 26 '23 22:10 zzzzBov