Send to your own code

Forward editor telemetry to any function, such as Datadog RUM, PostHog, or your own logger, or write your own exporter.

@docx-editor.dev/telemetry is available in version 2.29.0 and later.

Forward events to a callback

Use callbackExporter to forward events to any function, then register telemetry.module as Set up an editor shows:

import { callbackExporter, createTelemetry, isFailure } from '@docx-editor.dev/telemetry';

export const telemetry = createTelemetry({
  exporters: [
    // isFailure is false for expected refusals and for deduplication summaries.
    callbackExporter((event) =>
      isFailure(event)
        ? datadogRum.addError(new Error(event.kind), event)
        : datadogRum.addAction(event.kind, event)
    ),
  ],
});

Implement an exporter

Implement TelemetryExporter with event, metric, or both.

MemberRequiredPurpose
nameYesShown in onExporterError reports.
event(event)One of event or metricReceives each event.
metric(record)One of event or metricReceives each metric record.
flush()If bufferedSends buffered events and waits for delivery.
shutdown()If bufferedFlushes and releases resources.
attach(context)NoCalled once with a context.
context.consented()n/aWhether the user allows telemetry. Check it before sending buffered events.
context.pageClosing()n/aWhether the page is hidden or closing. Use a transport that completes in that state.

Limits

  • Exporters own pending delivery.
  • Telemetry catches rejected callback promises and reports each exporter failure once through onExporterError.
  • Every event that reaches an exporter has passed the privacy checks. For payloads, see Privacy.

See also