Tracking Mouse Position in jQuery for Web Analytics without Mouse Events

Looking for another way to track mouse position within web analytics without mouse events? This blog posting will describe how to put that in place for your web site.

The easiest way to do this is to use a mousemove handler that stores the infomation way so that you can easily query the stored information to pass into your web analytics solution. Below is the code that you can use to achieve this:

jQuery(function($) {
var currentMousePos = { x: -1, y: -1 };
$(document).mousemove(function(event) {
currentMousePos.x = event.pageX;
currentMousePos.y = event.pageY;

// Pass to Analytics
if (currentMousePos.x < 10) {
//Adobe Analytics
s.linkTrackVars = “propXX,events”;
s.linkTrackEvents = “eventXX”;
s.propXX = currentMousePos.x + “:” + currentMousePos.y;

//Google Analytics
ga(‘send’, ‘event’, ‘Mouse Position’, window.location.href, currentMousePos.x + “:” + currentMousePos.y;


That’s it! With this, you can now track mouse movement without events tied to the mouse movement within your analytics solution whether that be Adobe Analytics or Google Analytics.