Error Tracking & Elimination

Finding silent failures with server logs, window.onerror, and sendBeacon

Why Error Tracking Matters

The most immediate value of analytics for developers is finding errors that users never report. Most users who encounter a broken page simply leave — they do not file a bug report. Interestingly, the marketing of all things means we adopt a specialized term for this use of analytics to see how software is behaving: observability.

Server-Side Error Detection

Server access logs contain HTTP status codes for every request. Filter for 4xx (client errors: broken links, missing resources) and 5xx (server errors: crashes, timeouts). This requires no code changes — just log analysis.

Client-Side Error Detection

JavaScript errors, failed resource loads, and unhandled promise rejections are invisible to the server unless you explicitly capture and report them:

// Capture JavaScript errors window.addEventListener('error', function(event) { const errorData = { type: 'js_error', message: event.message, source: event.filename, line: event.lineno, column: event.colno, timestamp: Date.now(), url: location.href, userAgent: navigator.userAgent }; // sendBeacon guarantees delivery even during page unload navigator.sendBeacon('/collect', JSON.stringify(errorData)); }); // Capture unhandled promise rejections window.addEventListener('unhandledrejection', function(event) { navigator.sendBeacon('/collect', JSON.stringify({ type: 'promise_rejection', reason: String(event.reason), timestamp: Date.now(), url: location.href })); });