Skip to content

Error Handling

The library provides built-in error tracking at multiple levels, reporting client-side errors back to the Segmentify API.

View as Markdown llms.txt

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.

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 ErrorHandler event, 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 preExecuteFunction or postExecuteFunction throws, the error is caught and logged.
  1. Wrap custom callbacks in try-catch — handle errors in your preExecuteFunction / postExecuteFunction to prevent breaking page detection.
  2. Use debug mode during development — set debug: true to see error traces in the console (see Logger).
  3. Monitor ErrorHandler events — check your Segmentify dashboard for CUSTOM_EVENT entries with type error_handler.