Engineer an eye-tracking replay platform mapping scan paths to interaction outcomes and…
- User
Engineer an eye-tracking replay platform mapping scan paths to interaction outcomes and copy adjustments.
Assistant
Engineer an eye-tracking replay platform mapping scan paths to interaction outcomes and copy adjustments.
The user wants to "Engineer an eye-tracking replay platform mapping scan paths to interaction outcomes and copy adjustments."
1. Deconstruct the Request:
2. Analyze the "Product/Feature" Concept:
3. High-Level Architecture:
4. Detailed Components:
Component 1: Data Acquisition (The Client SDK)
Component 2: Data Pipeline & Storage
Component 3: The Replay Engine (The UI)
Component 4: The Intelligence Layer (Mapping to Outcomes/Copy)
h1, button#submit).5. Drafting the Engineering Plan (Iterative Refinement):
Stack: Python/FastAPI (backend), React (frontend viewer), Postgres/Mongo (DB). Let's use rrweb for session replay—it's the industry standard for DOM recording. I'll augment it with eye-tracking data.
Algorithm for "Copy Adjustment":
6. Structuring the Output:
7. Refining the "Copy Adjustment" Aspect: How does the system actually tell you to change the copy?
8. Writing the Content (Mental Sandbox):
9. Final Polish: Make it actionable. Provide code snippets (pseudocode or Python/JS) for the core logic. Structure it as a CTO/Lead Engineer brief.
(Self-Correction during drafting): Don't just build a heatmap. The prompt asks for replay and mapping to outcomes. The temporal aspect (video-like replay) is crucial, not just a static aggregate image.
Key Features to Highlight:
Let's assemble the plan. This is a comprehensive architectural blueprint and implementation strategy for GazeFlow, an eye-tracking replay platform.
This system is designed to move beyond simple heatmaps. It treats eye movements (scan paths) as a first-class event type alongside clicks and scrolls, allowing you to correlate visual attention with specific conversion outcomes and textual content.
The system consists of three distinct layers:
We need a time-series database (like TimescaleDB or InfluxDB) optimized for high-frequency writes (60–120Hz).
{
"session_id": "uuid-v4",
"user_id": "user-123",
"variant_id": "hero-btn-red", // For A/B testing context
"outcome": "CONVERSION", // or "DROP_OFF", "BOUNCE"
"device_meta": { "width": 1920, "height": 1080, "dppx": 1.5 }
}
Instead of raw JSON, we batch these into binary blobs (Protobuf/MessagePack) for transfer.
{
"t": 1698765432123, // Unix timestamp (ms)
"x": 540.2, // Viewport X
"y": 820.5, // Viewport Y
"p": 0.98 // Pupil confidence (0.0 - 1.0)
}
{
"t": 1698765432250,
"type": "CLICK",
"target_xpath": "/html/body/div[3]/button",
"text_snapshot": "Buy Now" // Snapshot of text at interaction moment
}
We need to smooth raw jittery eye data before sending it to the server. We will use a Kalman Filter to predict the true gaze position.
File: gaze-capture.js
import KalmanFilter from 'kalmanjs';
import WebGazer from 'webgazer';
class GazeTracker {
constructor() {
this.kfX = new KalmanFilter({ R: 0.01, Q: 3 });
this.kfY = new KalmanFilter({ R: 0.01, Q: 3 });
this.eventBuffer = [];
this.isRecording = false;
}
async init() {
await WebGazer.setGazeListener((data, elapsedTime) => {
if (data == null) return;
// 1. Apply Kalman Filtering for smoothing
const smoothedX = this.kfX.filter(data.x);
const smoothedY = this.kfY.filter(data.y);
// 2. Map to DOM Element
const element = document.elementFromPoint(smoothedX, smoothedY);
const interactionContext = element ? element.innerText.substring(0, 50) : null;
// 3. Push to buffer
this.eventBuffer.push({
t: Date.now(),
x: smoothedX,
y: smoothedY,
context: interactionContext // Used for "Copy Adjustment" analysis
});
}).begin();
}
// Map interaction outcomes
logOutcome(type) {
fetch('/api/outcome', {
method: 'POST',
body: JSON.stringify({
session_id: this.sessionId,
type: type, // e.g., 'FORM_SUBMIT'
timestamp: Date.now()
})
});
}
}
This is the core differentiator. We need to map where the user looked to what they read and correlate it with what they did.
Logic Algorithm (Python/Pseudo):
def analyze_copy_effectiveness(session):
"""
Correlates gaze fixation time on specific text nodes
with the interaction outcome.
"""
interactions = session.interactions
gaze_data = session.gaze_points
copy_analysis = {}
for point in gaze_data:
# Raycast point to DOM Text Node (Server-side DOM recreation required)
# Ideally, this is done client-side and passed as 'context'
text_node = point.context
if text_node not in copy_analysis:
copy_analysis[text_node] = {
"total_fixation_ms": 0,
"reread_count": 0, # Back-and-forth scan path detection
"led_to_click": False
}
copy_analysis[text_node]["total_fixation_ms"] += (1000 / 60) # Assuming 60fps
# Detect "Confusion Loops" (Read -> Look away -> Read again)
# This signals the copy was unclear or the user was hesitating
return {
"confusing_elements": [k for k, v in copy_analysis.items() if v['reread_count'] > 2],
"ignored_elements": [k for k, v in copy_analysis.items() if v['total_fixation_ms'] < 300]
}
The replay engine must render the website snapshot (DOM) and overlay the gaze path using a Canvas or SVG layer.
File: replay-engine.jsx
import React, { useEffect, useRef } from 'react';
const ReplayEngine = ({ events, domSnapshot }) => {
const canvasRef = useRef(null);
const iframeRef = useRef(null);
useEffect(() => {
const ctx = canvasRef.current.getContext('2d');
let frameIndex = 0;
// Load the DOM snapshot into an iframe to preserve original layout
iframeRef.current.srcdoc = domSnapshot;
const animate = () => {
if (frameIndex >= events.length) return;
const currentEvent = events[frameIndex];
// Clear canvas
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
// Draw Scan Path (Line)
ctx.beginPath();
ctx.moveTo(events[frameIndex-1]?.x, events[frameIndex-1]?.y);
ctx.lineTo(currentEvent.x, currentEvent.y);
ctx.strokeStyle = 'rgba(0, 255, 0, 0.5)';
ctx.stroke();
// Draw Gaze Point (Circle)
ctx.beginPath();
ctx.arc(currentEvent.x, currentEvent.y, 15, 0, 2 * Math.PI);
ctx.fillStyle = 'rgba(255, 0, 0, 0.3)'; // Fixation opacity based on confidence
ctx.fill();
// Draw Interaction Marker if click occurred at this timestamp
if (currentEvent.type === 'CLICK') {
drawClickRipple(ctx, currentEvent.x, currentEvent.y);
}
frameIndex++;
requestAnimationFrame(animate);
};
animate();
}, [events]);
return (
<div className="replay-container" style={{ position: 'relative' }}>
{/* The Website Layer */}
<iframe ref={iframeRef} style={{ width: '100%', height: '100%', border: 'none' }} />
{/* The Gaze Overlay Layer */}
<canvas ref={canvasRef} style={{ position: 'absolute', top: 0, left: 0, pointerEvents: 'none' }} />
</div>
);
};
Instead of just showing replays, the platform suggests copy changes.
We cluster sessions by outcome.
rrweb for DOM replay fidelity and HTML5 Canvas for gaze rendering.| Challenge | Solution |
|---|---|
| Resolution Mismatch | Record device pixel ratio (DPPX). Normalize all coordinates to a standard resolution (e.g., 1920x1080) before storage. |
| DOM Drift | Eye coordinates are absolute. If the page scrolls, coordinates must be adjusted. Use window.scrollY offset during capture to store relative coordinates. |
| Privacy (PII) | Implement a "scrubbing" logic in the capture agent. Never record input field values (passwords/emails). Blacklist specific DOM selectors. |
This platform moves beyond "where did they look" to "did the text do its job?" by quantifying the relationship between visual attention and user intent.