How to track mouse movements?

Hello,

is there currently a way to track mouse movements / the mouse position? As far as I understand, page pings are triggered by page scrolls and mouse movements, so it should be easy to not only send the scroll position, but the mouse position as well.

Thanks,

  • Marius

I’d be careful about tracking mouse movements - going to be very chatty! Might be able to build custom context and do a client side track like this:

document.onmousemove = function(e){
  var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
  console.log(pageCoords);
};

And instead of console logging could store in local storage and batch send. Could also poll every N seconds (set at appropriate interval) and send that way.

1 Like

Ideally the page pings would just contain the current mouse position. If they are already triggered by mouse movements, this should be fairly trivial, no?

What’s your specific use case for mouse coordinates?

Firing with page ping could give you mouse coordinates but your resolution will be limited by how often you are sending these pings (customisable, but generally not lower than 5 seconds). If you want higher temporal resolution than that you may want to use a specialised tool/library, or alternately look into a method to store locally and batch send as @13scoobie has suggested.

If you’re looking at whether a user hovers/clicks over an element or certain elements you may be best off binding events to these parts of the DOM (or DOM changes).

I want to analyze user behavior. I’m currently sending page pings every 5 seconds and for now that resolution would be sufficient. I would just be looking at the mouse coordinates.

Of course I can build this myself or use another library, but I’m already using Snowplow for page views and pings and I don’t want to use multiple tracking libs. So the question is, can this be done with Snowplow right now? Would DOM element tracking work with Snowplow right now?