Error Handling
The library provides built-in error tracking at multiple levels, reporting client-side errors back to the Segmentify API.
The ErrorHandler Event
Section titled “The ErrorHandler Event”Send error information explicitly via SegmentifyEventManager().ErrorHandler:
try { await SegmentifyEventManager().ProductView(payload);} catch (error) { await SegmentifyEventManager().ErrorHandler(error as Error);}This sends a CUSTOM_EVENT with type error_handler containing the error message.
Internal Error Handling
Section titled “Internal Error Handling”The library catches errors internally so a single failure doesn’t break the integration:
- Initializer — wraps setup steps in try-catch. Logs the error, sends an
ErrorHandlerevent, and continues for non-critical failures. - Events — if a single event fails (network error, bad response), it’s skipped and the queue continues processing.
- Page Detection — if
preExecuteFunctionorpostExecuteFunctionthrows, the error is caught and logged.
Best Practices
Section titled “Best Practices”- Wrap custom callbacks in try-catch — handle errors in your
preExecuteFunction/postExecuteFunctionto prevent breaking page detection. - Use debug mode during development — set
debug: trueto see error traces in the console (see Logger). - Monitor ErrorHandler events — check your Segmentify dashboard for
CUSTOM_EVENTentries with typeerror_handler.