Capture JavaScript errors, exceptions, and stack traces automatically with session replay context and team assignment
Error tracking captures exceptions and errors in your application automatically. See full stack traces, session context, and user impact to debug issues faster than logs alone.
// Throw a test errorposthog.capture('$exception', { $exception_message: 'Test error', $exception_type: 'TestError'})// Or throw naturallythrow new Error('Testing error tracking')
Errors are automatically grouped into issues by fingerprint:
// These errors group together (same root cause)function loadUser(userId) { const user = api.getUser(userId) // Throws if user not found return user.name // TypeError: Cannot read property 'name' of undefined}loadUser(123) // Error instance 1loadUser(456) // Error instance 2 - same issue
PostHog generates fingerprints based on:
Error type and message
Stack trace signature
File and line number
Function name
Customize fingerprinting with grouping rules if PostHog groups too broadly or narrowly.
TypeError: Cannot read property 'name' of undefined at loadUser (app.js:145:23) at handleClick (components/UserProfile.tsx:89:12) at onClick (node_modules/react-dom/index.js:4567:8)
Click any frame to:
See surrounding code context
View the full file (with source maps)
Jump to GitHub/GitLab (with integration)
Understand how many users are affected:
Total error occurrences
Unique affected users
Error frequency over time
Most common user properties
Use this to prioritize which issues to fix first.
See what users did before the error:
Link to session replay
User properties and cohorts
Browser, OS, device info
Previous events and actions
Click View recording to watch the session that triggered the error.
Event trail leading to the error:
1. Page loaded: /dashboard2. Clicked: "View profile" button 3. API call: GET /api/users/1234. ERROR: Cannot read property 'name' of undefined
Breadcrumbs show navigation, clicks, API calls, and console logs.
Don’t just track uncaught exceptions. Track errors you catch and handle:
const result = await api.fetchData()if (result.error) { // Track even though we handle it posthog.capture('$exception', { $exception_message: result.error, $exception_type: 'APIError' }) showFallbackUI()}
Use consistent error types
Create custom error classes for better grouping:
class PaymentError extends Error { constructor(message, orderId) { super(message) this.name = 'PaymentError' this.orderId = orderId }}throw new PaymentError('Card declined', orderId)