I want to fire an action to dataLayer if the mouse moves off the page. I'm assuming adding an event listener would work and passing in 'mouseout' but needed some help setting it up as I am new to javascript. Thank you !
something like:
document.addEventListener("mouseleave", (event) => {
if (event.clientY <= 0 || event.clientX <= 0 || (event.clientX >= window.innerWidth || event.clientY >= window.innerHeight)) {
/* do what you have to do here */
}
});
Following Luke McCrea, I made the test with the following:
document.addEventListener("mouseleave", (event) => {
/* do what you have to do here */
}
});
Seems to work same. It was a quick on a blank HTML page, with nothing else loaded. But no real reason it's not working on real big project.