MouseTracker element

Collecting mouse-tracking data can rapidly produce large results files, because it reports mouse coordinates every few milliseconds. Make sure you only track mouse movements during relevant time periods during your trials, and consider regularly backing up your results files before deleting them from the farm.

MouseTracker elements let you track where on the page is your participant’s mouse cursor every few milliseconds.



The only parameter is the element name ("mouse") which is optional. Make sure to call log to collect data in the results file.

The coordinates are reported in the results file as a long compressed string. The string always start with xXyYwWhH, where X and Y are numbers corresponding to the mouse coordinates when recording starts, and W and H correspond to the page’s width and height. It then continues with sequences of tT+A-B bits, where T corresponds to the number of milliseconds since the last bit, and +A and -B, which can be positive (+) or negative (-) correspond to how many pixels the mouse has moved horizontally and vertically, respectively. This script illustrates how to decompress the string in R, assuming the results datatable was previously subset to MouseTracker rows only:

[php]timestamps_get_response <- vector() xpos_get_response <- vector() ypos_get_response <- vector() for(row in 1:nrow(results)){ time <- 0 stream <- as.character(results[row,"Value"]) pos <- data.frame(time=c(time),x=as.numeric(gsub("^x(\\d+)y.+$","\\1", stream)), y=as.numeric(gsub("^.+y(\\d+)w.+$","\\1", stream))) ptime <- time counter <- 1 px <- pos[1,'x'] py <- pos[1,'y'] for(s in (strsplit(stream,'t')[[1]][-1])){ row <- strsplit(gsub("^(\\d+)([+-]\\d+)([+-]\\d+)$","\\1 \\2 \\3",s),' ') ntime <- as.numeric(ptime+as.numeric(row[[1]][1])) nx <- as.numeric(px+as.numeric(row[[1]][2])) ny <- as.numeric(py+as.numeric(row[[1]][3])) pos <- rbind(pos, data.frame(time=ntime,x=nx,y=ny)) ptime <- ntime px <- nx py <- ny counter <- counter +1 } times <- toString(pos[["time"]]) timestamp <- paste("[", times, "]", sep = "") timestamps_get_response <- c(timestamps_get_response, timestamp) xpos <- toString(pos[["x"]]) xpos_str <- paste("[", xpos, "]", sep = "") xpos_get_response <- c(xpos_get_response, xpos_str) ypos <- toString(pos[["y"]]) ypos_str <- paste("[", ypos, "]", sep = "") ypos_get_response <- c(ypos_get_response, ypos_str) } results$timestamps <- timestamps_get_response results$xpos <- xpos_get_response results$ypos <- ypos_get_response[/php]


[yadawiki-list category=”NonTest command,MouseTracker element”]


[yadawiki-list category=”Test command,MouseTracker element”]

Published by Jeremy

Researcher in semantics and pragmatics; Programmer of PennController for IBEX