How to sync eye-tracking data with DOM events?
ability to fuse two real-time data streams with different timestamps and frequencies.
record gaze points with millisecond precision, map to DOM via bounding box lookup, correlate with click events via shared timestamp.
Why it exists
Eye-tracking research needs to correlate what users look at with what they do. Latency from fixation to interaction is a key metric; longer latency suggests the element is hard to find or parse. But gaze trackers and browsers timestamp events independently, often on different clocks.
The mental model
Two asynchronous streams: (a) gaze points (x, y, timestamp) at 30-60 Hz from the tracker, (b) DOM events (click, focus, etc.) from the browser. Both need a shared clock and spatial mapping. When a gaze point lands on a button's bounding box, start a timer. When the click fires, record the elapsed time.
How it works
Instrument the page: instrument() each interactive element (button, link, form input) to expose its bounding box and fire custom events (e.g., onGazeEnter, onGazeExit) when gaze enters/exits. Receive gaze data from the tracker via WebSocket or a callback; each point includes (x, y, timestamp, confidence). On each gaze point, look up its DOM element via elementFromPoint or a spatial index. If the element differs from the last one, emit onGazeExit from the old element and onGazeEnter from the new. Simultaneously, listen for native click events. When a click fires and the element matches a recent gaze target, compute the time delta and log the record. Synchronization: use the tracker's system time as the source of truth. If the tracker and browser clocks drift, estimate drift by correlating a few manual calibration events (user clicks a target while looking at it) and applying a linear correction to gaze timestamps.
When it matters
UX research, usability studies, and accessibility testing all rely on this correlation. Long fixation-to-click times can indicate cognition overhead (user confused) or motor delay (accessibility issue). Eye-tracking dashboards often surface these metrics.
A concrete example
A form with a "Submit" button. Gaze tracker logs fixations on the button starting at t=5000ms. Click event fires at t=5300ms. Time from first fixation to click: 300ms. If baseline is 200ms (other buttons), this suggests the button is slightly harder to locate or understand, warranting A/B testing of its label or position.
Interview question
You receive gaze data at 60 Hz from a tracker and click events from the browser, timestamped independently. The tracker clock drifts ~50ms over 10 seconds. How should you align them to compute fixation-to-click latency accurately?
- a.Calibrate clock drift by correlating known events (e.g., manual clicks) and apply linear correctionCorrect
- b.Assume the browser clock is authoritative and adjust all gaze timestamps to UTC
- c.Use a Kalman filter to smooth gaze noise and ignore timing differences
- d.Resample gaze data to match the browser event frequency
Why? this is the answer
Clock drift is systematic and can be estimated from known synchronization points. Linear correction (Option A) is practical and reliable. A Kalman filter (C) smooths noise but doesn't solve clock skew. Resampling (D) discards data. Browser-only timestamps (B) lose gaze granularity.
Just read this? Test yourself on what you have been reading.
- #eye-tracking
- #event-correlation
- #ux-metrics
- #clock-sync
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles