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
View originalI 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
View originalHi
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(e.target.className)) {
heap.track("Context menu event");
}
}, false);
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.