Overview
TheuseErrorTracking hook provides methods for tracking JavaScript errors and custom error events. It also automatically tracks unhandled errors and promise rejections when the component is mounted.
Usage
Automatic Error Tracking
When mounted,useErrorTracking automatically listens for:
- JavaScript errors (
window.errorevent) - Unhandled promise rejections (
window.unhandledrejectionevent)
Returns
function
Track JavaScript Error objects with additional contextSignature: Tracked Data:
(error: Error, properties?: EventProperties) => voidmessage: Error messagestack: Stack trace- Any additional properties passed
function
Track custom error messages with optional contextSignature: Tracked Data:
(message: string, properties?: EventProperties) => voidmessage: Custom error message- Any additional properties passed
Type Definitions
EventProperties
Examples
API Error Tracking
Form Validation Errors
React Error Boundary Integration
Tracking Third-Party Library Errors
Automatic Tracking Details
JavaScript Errors
Automatically tracked with:message: Error messagestack: Stack tracefilename: File where error occurredlineno: Line numbercolno: Column number
Unhandled Promise Rejections
Automatically tracked with:message: Rejection reasontype: “unhandledrejection”
Notes
Avoid tracking sensitive information in error properties. Always sanitize user data before including it in error tracking.
Related Hooks
- useAnalytics - Access core analytics methods including
trackCustomError - useSessionTracking - Track session context when errors occur