@getcredify/credify-insurance-widget 1.24.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -318,6 +318,23 @@ Listen for these events from the widget:
318
318
  - `{ type: 'opened', source: 'credify-insurance-widget' }` - Widget has opened
319
319
  - `{ type: 'closed', source: 'credify-insurance-widget' }` - Widget has closed
320
320
 
321
+ Funnel/analytics events are also forwarded with `type: 'event'`:
322
+
323
+ - `{ type: 'event', source: 'credify-insurance-widget', event, data }`
324
+
325
+ where `event` is one of `widgetOpened`, `widgetClosed`, `stageViewed`,
326
+ `stageCompleted`, `flowCompleted`, `ratesViewed`, `ratesBack`, and `data` is the
327
+ matching payload documented under [Events](#events). Example:
328
+
329
+ ```javascript
330
+ window.addEventListener('message', (e) => {
331
+ if (e.data?.source !== 'credify-insurance-widget' || e.data.type !== 'event') return;
332
+ if (e.data.event === 'stageCompleted') {
333
+ analytics.track('insurance_step', { step: e.data.data.stageKey });
334
+ }
335
+ });
336
+ ```
337
+
321
338
  ## Server Configuration
322
339
 
323
340
  When serving the widget for iframe embedding, ensure your server:
@@ -355,6 +372,8 @@ interface CredifyInsuranceWidgetAPI {
355
372
  open(): void;
356
373
  close(): void;
357
374
  destroy(): void;
375
+ on<E extends WidgetEventName>(event: E, callback: (data: WidgetEventMap[E]) => void): void;
376
+ off<E extends WidgetEventName>(event: E, callback: (data: WidgetEventMap[E]) => void): void;
358
377
  }
359
378
  ```
360
379
 
@@ -362,6 +381,39 @@ interface CredifyInsuranceWidgetAPI {
362
381
  - `open()` - Open the widget
363
382
  - `close()` - Close the widget
364
383
  - `destroy()` - Remove the widget from the DOM
384
+ - `on(event, callback)` - Subscribe to a widget event (see below)
385
+ - `off(event, callback)` - Unsubscribe a previously registered callback
386
+
387
+ ### Events
388
+
389
+ Subscribe to widget lifecycle and funnel events to forward them to your own
390
+ analytics (Segment, GTM, Amplitude, etc.). Register listeners **before** calling
391
+ `init`/`open`, since `widgetOpened` fires as the widget mounts.
392
+
393
+ ```javascript
394
+ CredifyInsuranceWidget.on('stageCompleted', (data) => {
395
+ analytics.track('insurance_step', { step: data.stageKey });
396
+ });
397
+ ```
398
+
399
+ | Event | Payload | Fires when |
400
+ | ---------------- | --------------------------------------------------------------- | ----------------------------------------------- |
401
+ | `widgetOpened` | _none_ | The widget overlay opens |
402
+ | `widgetClosed` | _none_ | The widget overlay closes |
403
+ | `stageViewed` | `{ stageKey, stageTitle, stepIndex, totalSteps }` | A form stage becomes visible |
404
+ | `stageCompleted` | `{ stageKey, stageTitle, stepIndex, totalSteps }` | A form stage is successfully completed |
405
+ | `flowCompleted` | _none_ | All stages are done and rate generation starts |
406
+ | `ratesViewed` | `{ rateCount: number }` | The rates screen is shown |
407
+ | `ratesBack` | _none_ | The user navigates back from the rates screen |
408
+
409
+ The event names and payload types (`WidgetEventName`, `WidgetEventMap`,
410
+ `StageEventData`) are exported from the package for TypeScript consumers. Host
411
+ callbacks are invoked in isolation — a throwing callback is reported and never
412
+ breaks the widget.
413
+
414
+ > **Iframe embedding:** the same events are delivered to the parent window over
415
+ > postMessage instead (see [Events (Widget → Parent)](#events-widget--parent)),
416
+ > because the in-iframe emitter is not reachable from the host page.
365
417
 
366
418
  ## Examples
367
419