How Rage Click Detection Works: Algorithm Behind Frustration Signals
11 clicks in under two seconds, then a closed tab. How does session replay detect rage clicks?
Picture a replay of someone hitting "Submit Payment" 11 times in under two seconds, then closing the tab. The button's loading state never disabled pointer events, so clicks piled up while the first request hung. Nobody filed a ticket. The only evidence is a cluster of clicks.
That cluster is what a session replay tool labels a rage click. Clicking a lot in one spot sounds trivial to detect. The implementation is trickier than it looks.
How many clicks? How close together? How do you tell frustration from a carousel's "next" button or a cookie-clicker game? A naive "if clicks > 5, flag it" check falls over fast. The real thing is sliding-window burst detection with spatial clustering and debounced event emission. (The centroid math is the bit that's easiest to get subtly wrong.)
What Qualifies as a Rage Click
A rage click is a rapid sequence of clicks in a concentrated area that indicates user frustration—typically because something isn't responding.
But "rapid" and "concentrated" need numbers.
Click velocity threshold. A reasonable starting point is 3-5 clicks within a 500-800ms window. The exact numbers vary:
- Some tools use 3 clicks in roughly half a second
- Others want 4 or 5 clicks in a slightly wider window
- Treat any vendor's exact numbers as a moving target and check their docs
Why numbers in this range? Human click speed tops out around 8-10 clicks per second for someone deliberately spam-clicking. Normal intentional clicking—paging through a carousel, selecting items—rarely exceeds 2 clicks per second. The 3-5 clicks in 500ms threshold sits right in the "too fast to be normal" zone.
Spatial clustering. Clicks need to happen near each other. Clicking rapidly across different parts of the screen isn't frustration—it's probably navigation or a drag selection gone wrong.
The spatial component typically uses a radius of 30-50 pixels. If consecutive clicks land within that radius, they're considered part of the same sequence. Some implementations use bounding boxes instead of circular radii. Others calculate centroids and measure distance from the centroid.
Here's a simplified version of the core algorithm:
const CLICK_THRESHOLD = 3;
const TIME_WINDOW_MS = 500;
const RADIUS_PX = 40;
let recentClicks = [];
function onClickEvent(event) {
const now = Date.now();
const { clientX, clientY } = event;
// Remove clicks outside the time window
recentClicks = recentClicks.filter(
click => now - click.timestamp < TIME_WINDOW_MS
);
// Check if this click is near the recent cluster
const isNearCluster = recentClicks.length === 0 ||
recentClicks.every(click =>
Math.hypot(clientX - click.x, clientY - click.y) <= RADIUS_PX
);
if (isNearCluster) {
recentClicks.push({ x: clientX, y: clientY, timestamp: now, target: event.target });
if (recentClicks.length >= CLICK_THRESHOLD) {
emitRageClick(recentClicks);
recentClicks = []; // Reset after detection
}
} else {
// Click is far from cluster—start new sequence
recentClicks = [{ x: clientX, y: clientY, timestamp: now, target: event.target }];
}
}
This is the naive version. It'll work. But it'll also flag your game widgets, miss edge cases at time boundaries, and flood your dashboard if someone really loses it on a broken button. Production implementations add several refinements—and honestly, getting these right is where the interesting engineering happens.
Sliding Windows vs Fixed Windows
The code above uses a sliding window—clicks expire as time passes. Some implementations use fixed windows instead: divide time into 500ms buckets and count clicks per bucket.
Fixed windows are simpler but miss rage clicks that span bucket boundaries. User clicks at 300ms, 450ms, 550ms and 700ms. That's 4 clicks in 400ms—obviously rage—but a 500ms bucket sees 2 and 2.
Sliding windows catch boundary cases but require storing more state. You need the timestamp of every recent click, not just a count. For session replay tools that already store every DOM event with a timestamp, this isn't a problem. The data's already there.
Real implementations use sliding windows. The computational cost is negligible compared to DOM mutation recording. For teams already tracking error monitoring alongside replay, sliding windows integrate cleanly with the existing event stream.
(Fixed windows look "good enough" until a test case puts clicks at 499ms and 501ms and the bucket boundary splits them. They're not good enough.)
Target-Area Grouping Details
Spatial clustering sounds simple—"clicks within 40 pixels"—but there's a subtlety. Clicks rarely hit the exact same coordinate twice. Cursor drift during rapid clicking, elements that shift slightly on click (CSS :active transitions), and touch event coordinate jitter all mean consecutive clicks are 5-20 pixels apart.
Centroid approach. Compute the center of all clicks in the current sequence, then check if new clicks fall within RADIUS_PX of that centroid.
function computeCentroid(clicks) {
const sumX = clicks.reduce((sum, c) => sum + c.x, 0);
const sumY = clicks.reduce((sum, c) => sum + c.y, 0);
return { x: sumX / clicks.length, y: sumY / clicks.length };
}
function isNearCentroid(click, centroid, radius) {
return Math.hypot(click.x - centroid.x, click.y - centroid.y) <= radius;
}
Bounding box approach. Track the min/max X and Y of all clicks. If the box stays smaller than RADIUS_PX * 2 in both dimensions, the clicks are clustered.
Pairwise distance. Check if every pair of clicks is within RADIUS_PX * 2. More expensive computationally, but avoids edge cases where a long thin cluster passes centroid checks.
Centroid is a sensible default. It's fast and handles the common case where users click the same button repeatedly. Pairwise distance is more accurate—but when you're processing click events on the main thread, "more accurate" loses to "fast enough."
Debounce Windows: Why One Rage Click Shouldn't Fire 10 Events
Here's a problem: if the threshold is 3 clicks and the user clicks 15 times, how many rage-click events should fire?
Without debouncing: every click after the third triggers another rage-click event. Click 3, 4, 5, 6... each one crosses the threshold. You'd record 13 rage-click events for a single frustration episode.
Debounce window. After detecting a rage click, ignore additional clicks for 1-3 seconds. This ensures one burst = one event.
let lastRageClickTime = 0;
const DEBOUNCE_MS = 2000;
function emitRageClick(clicks) {
const now = Date.now();
if (now - lastRageClickTime < DEBOUNCE_MS) {
return; // Still in debounce window
}
lastRageClickTime = now;
recordFrustrationEvent({
type: 'rage_click',
clickCount: clicks.length,
centroid: computeCentroid(clicks),
targetElement: clicks[0].target,
timestamp: now
});
}
Some implementations reset the debounce on every click during the burst and emit only once the user stops clicking. Others emit immediately on threshold crossing and ignore the rest. Both work. The important thing is not flooding your analytics with duplicate events.
(Opinion: emit immediately. If you wait until they stop clicking, you're adding latency to your real-time dashboard. And real-time matters when you're watching a user struggle.)
What Gets Recorded
When a rage click fires, what data should the session replay capture?
Click count. How many clicks in the burst—3, 7, 15? Higher counts suggest more severe frustration.
Centroid/target area. The approximate location. Often mapped back to a DOM element.
Target element. The element that received the clicks. A CSS selector, element ID, or XPath. This is what makes rage clicks actionable—knowing that users rage-clicked .submit-button.disabled tells you exactly what to fix.
Timestamp. When it happened in the session timeline.
Surrounding context. Did an error fire around the same time? Was there a network request pending? Did the element have a disabled attribute that should've blocked clicks?
Pairing the click burst with error tracking in the same platform is the useful part. This is where correlating errors with funnel drop-off becomes useful—rage clicks near checkout combined with payment API errors tells a story.
False Positives: When Rapid Clicking Isn't Rage
Here's where naive implementations fail. Not all rapid clicking is frustration. It's an easy mistake to ship a detector that flags a game widget on a marketing page and sends everyone chasing phantom "frustration" reports.
Games. Cookie clicker, rhythm games, any mechanic involving rapid tapping. These users click 20 times in a second intentionally.
Music/media apps. Beat-tapping features, drum machines, sample triggers.
Power users with auto-clicker accessibility tools. Some motor-impaired users use software that auto-repeats clicks on hold.
Legitimate UI patterns. Volume buttons, increment/decrement steppers, carousel navigation. If your UI encourages rapid clicking, don't flag it as rage.
Handling false positives:
-
Element exclusions. Mark elements or container classes as exempt:
.game-area,[data-no-rage-detection],input[type="range"]. -
Domain context. If you're running a browser-based game, rage-click detection probably isn't useful. Disable it entirely or require element-level opt-in instead of opt-out.
-
Correlation weighting. A rage click accompanied by no errors, no pending requests, and a successful state transition is probably a false positive. Weight rage clicks higher when they coincide with dead clicks (clicks that produce no DOM change) or visible error states.
-
Sampling and thresholds. For high-traffic sites, you might sample rage clicks or require 5+ clicks instead of 3. Better to miss some frustration than flood your replay queue with false positives from a popular in-page game widget.
Look—false positive management is annoying. But a rage-click detector that flags everything is worse than useless. It trains your team to ignore the alerts.
Dead Clicks vs Rage Clicks
Related concept: a dead click is a click that produces no visible response. No DOM mutation, no navigation, no state change. The user clicked something that looked clickable but wasn't.
Dead clicks and rage clicks overlap but aren't the same:
- Dead click only: User clicks a non-interactive element once and gives up
- Rage click only: User clicks a working button rapidly while waiting for a slow response
- Both: User clicks a broken/unresponsive element repeatedly (most common case)
The algorithm for dead-click detection is different—it tracks DOM mutations and network requests within a time window after each click. If nothing happens, it's dead. Dead clicks on "Next" buttons during onboarding tutorials are a particularly strong signal, and masking PII in session replay matters when you review those sessions.
Combining the two: a rage click that's also dead (no DOM mutations during the burst) is the strongest frustration signal. A rage click on a button that's producing successful responses is probably not frustration—or your threshold is too low.
Performance Considerations
Rage-click detection runs in the browser, on the main thread, processing every click event. How expensive is it?
Not very. Even genuine rage clicking tops out around 10 click events per second. The algorithm does:
- Array filter (O(n), n is ~5-10 elements max)
- Distance calculation (a single
Math.hypot) - Possibly centroid computation (O(n) sum)
Microseconds at most. The session replay's DOM mutation observer is orders of magnitude heavier. If rage-click detection is your performance bottleneck, something else is very wrong.
Memory footprint. Storing 10 recent clicks with x, y, timestamp, and target reference: maybe 500 bytes. Irrelevant compared to the DOM snapshot buffer.
The performance concern is more about event emission: don't fire analytics requests synchronously on every rage click. Batch them with your other session replay events.
Implementing Rage-Click Detection Yourself
If you're building this from scratch (maybe for a custom analytics setup or debugging tool), here's a solid starting pattern:
class RageClickDetector {
constructor(options = {}) {
this.threshold = options.threshold || 3;
this.timeWindow = options.timeWindow || 500;
this.radius = options.radius || 40;
this.debounce = options.debounce || 2000;
this.excludeSelector = options.excludeSelector || '[data-no-rage]';
this.clicks = [];
this.lastEmit = 0;
this.onRageClick = options.onRageClick || (() => {});
}
handleClick(event) {
// Skip excluded elements
if (event.target.closest(this.excludeSelector)) {
return;
}
const now = Date.now();
const click = {
x: event.clientX,
y: event.clientY,
timestamp: now,
target: event.target
};
// Prune old clicks
this.clicks = this.clicks.filter(
c => now - c.timestamp < this.timeWindow
);
// Check spatial clustering
if (this.clicks.length > 0) {
const centroid = this.getCentroid();
const distance = Math.hypot(click.x - centroid.x, click.y - centroid.y);
if (distance > this.radius) {
this.clicks = []; // New cluster
}
}
this.clicks.push(click);
if (this.clicks.length >= this.threshold) {
this.emit();
}
}
getCentroid() {
const n = this.clicks.length;
return {
x: this.clicks.reduce((s, c) => s + c.x, 0) / n,
y: this.clicks.reduce((s, c) => s + c.y, 0) / n
};
}
emit() {
const now = Date.now();
if (now - this.lastEmit < this.debounce) {
return;
}
this.lastEmit = now;
this.onRageClick({
clickCount: this.clicks.length,
centroid: this.getCentroid(),
target: this.clicks[0].target,
timestamp: now
});
this.clicks = [];
}
}
Wire it up to document.addEventListener('click', ...) and you've got the core. Production versions add touch event support, handle shadow DOM, and integrate with the replay event stream.
Is this overkill for your debugging needs? Maybe. But it's useful outside session replay too: drop it into a page you're actively developing and broken interactions show up before QA gets to them.
Where JustAnalytics Fits
JustAnalytics bundles session replay and error tracking in one script, so a frustration signal can sit next to the errors and traces around it instead of in a separate tool. Replay is a Pro-plan feature. Privacy masking applies to what the replay records.
What to look for in any rage-click implementation, ours included:
- Correlation with errors. A user who rage-clicked, hit a TypeError and abandoned the session is a story. A raw count isn't.
- Dead-click awareness. A rage click with no DOM change means something is broken, not just slow.
- Stable element selectors. You want to search every session where users hammered
.checkout-form .submit-btn. - Masked text. Record the element type and position, not PII inside it.
For teams using error tracking alongside replay, rage clicks become a funnel metric: "sessions with rage clicks that also had errors" vs "sessions with rage clicks but no errors" tells you whether the frustration is a bug or a UX problem.
Raw rage-click counts are interesting. Rage clicks plus errors plus session context is actionable. That's the opinion, and it's why correlation beats counting.
Frequently Asked Questions
What click threshold counts as a rage click?
A reasonable starting point is 3-5 clicks within 500-800ms. The exact numbers vary by platform, so check each vendor's docs. The threshold represents clicks that happen faster than any intentional UI pattern (like a double-click or carousel navigation) would require.
How does target-area grouping work in rage click detection?
Target-area grouping clusters clicks within a pixel radius (typically 30-50px) rather than requiring exact coordinate matches. This handles slight cursor drift during rapid clicking and accounts for elements that shift slightly on each click. The algorithm computes bounding boxes or uses centroid distance to determine if clicks belong to the same frustration event.
Why do rage click detectors use debounce windows?
Debounce windows prevent a single rage-click burst from being counted multiple times. After detecting a rage click, the system ignores additional clicks for 1-3 seconds. Without debouncing, a user clicking 15 times in frustration would trigger 10+ separate rage-click events instead of one. Debouncing also prevents alert fatigue in session replay dashboards.
Can rage click detection produce false positives?
Yes. Games with rapid-fire mechanics, music apps with beat-tapping, cookie clickers, and some accessibility tools that auto-repeat clicks all trigger false positives. Good implementations exclude known game elements, allow domain-specific overrides, and weight rage clicks by whether they coincide with other frustration signals like dead clicks or error states.
Try JustAnalytics
All-in-one observability in one under-5KB script: cookieless analytics + error tracking + APM + session replay + uptime + structured logs. Replaces GA4 + Sentry + Datadog + Pingdom + LogRocket. Free tier (100K events/mo), Pro $49/month, or $39/month billed annually.
Author at JustAnalytics.