Jquery detect all dom event calls and user interactions

Alp picture Alp · Sep 21, 2011 · Viewed 6.9k times · Source

I want to track all user actions in order to record the user behavior. For example, a user clicks on a link and I want to call a method that does something with that information before executing the page load. This should also work with mouse hover events, keyboard input or any other user interaction.

Answer

mekwall picture mekwall · Sep 21, 2011

Wow, that's some big brother stuff you're asking for ;)

You could do something like this:

function bigBro(e) {
    console.log(e);
}

$(document).bind("click keydown keyup mousemove", bigBro);

This can be used before load and DOM-ready, and you can get lots of info from the Event Object.

Regarding hover, you'll have to detect that yourself by checking the element the cursor is over by the target property of the Event Object.

On a side note, this code will be very cpu intensive since the callback will be executed everytime you move the mouse, click or type.