Is it possible to detect whether a customer's mouse is left-clicked or right-clicked?

  • 23 May 2023
  • 1 reply


I am trying to capture if our customer right-clicks on any of our page links on our website, and would like to see the customer journey after that. 

Is there a way to set up an event to capture right clicking? 


Best answer by GlennS 24 May 2023, 15:06

View original

1 reply

Userlevel 2
Badge +1

Hi @Jonathan_T

To capture a right-click, you’ll need to add an event listener similar to what is described here.  This page in our developer documentation describes how to detect a mouse hover event over a specific element on the page and track that event using the heap.track API call.  To detect a right-click, you’ll need to modify the sample code to listen for a contextmenu event.  The example provided below will capture a right-click when it occurs on an element that has a class of myTargetClass.

I hope this helps.


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

  if (/myTargetClass/.test( {

    heap.track("Context menu event");


}, false);