Prompt
I’m building a frontend app and need to see clicks, scrolls, and errors in one timeline
Latest observation
Oct 30, 2026
OpenAI APIWeb search: off
To see clicks, scrolls, and errors in one timeline for a frontend app, you want a lightweight event recorder that captures each event with a timestamp and pushes it into a single ordered stream.
Here’s a practical approach:
1) Define a unified event shape
Use one schema for all events:
type TimelineEvent =
| { type: "click"; ts: number; x: number; y: number; target: string }
| { type: "scroll"; ts: number; scrollX: number; scrollY: number }
| { type: "error"; ts: number; message: string; source?: string; line?: number; col?: number };
2) Capture events in the browser
const timeline: TimelineEvent[] = [];
function pushEvent(event: TimelineEvent) {
timeline.push(event);
// optionally emit to UI, store, or send to backend
console.log(event);
}
window.addEventListener("click", (e) => {
const target = (e.target as HTMLElement)?.tagName || "unknown";
pushEvent({
type: "click",
ts: Date.now(),
x: e.clientX,
y: e.clientY,
target,
});
});
window.addEventListener("scroll", () => {
pushEvent({
type: "scroll",
ts: Date.now(),
scrollX: window.scrollX,
scrollY: window.scrollY,
});
}, { passive: true });
window.addEventListener("error", (e) => {
pushEvent({
type: "error",
ts: Date.now(),
message: e.message,
source: e.filename,
line: e.lineno,
col: e.colno,
});
});
window.addEventListener("unhandledrejection", (e) => {
pushEvent({
type: "error",
ts: Date.now(),
message: String(e.reason),
});
});
3) Render the timeline
Sort by timestamp and display each event in a list:
timeline.sort((a, b) => a.ts - b.ts);
You can then show:
- clicks as markers
- scrolls as position changes
- errors highlighted in red
4) Make it useful in practice
A few improvements:
- Throttle scroll events so you don’t flood the timeline
- Record page route changes if using a SPA
- Capture element info for clicks: id, class, text, selector
- Persist events to localStorage or send them to your backend
Example scroll throttling:
let scrollTimeout: number | null = null;
window.addEventListener("scroll", () => {
if (scrollTimeout) return;
scrollTimeout = window.setTimeout(() => {
scrollTimeout = null;
pushEvent({
type: "scroll",
ts: Date.now(),
scrollX: window.scrollX,
scrollY: window.scrollY,
});
}, 100);
}, { passive: true });
5) If you want this ready-made
If you want a production-grade solution instead of building from scratch, look at:
- Sentry Replay — captures user interactions and errors
- LogRocket — session timeline and replay
- Datadog RUM — interactions + errors + performance
If you want, I can also give you:
- a React hook for this,
- a Vue composable, or
- a tiny vanilla JS implementation with a timeline UI.