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.
| Member | Required | Purpose |
|---|---|---|
name | Yes | Shown in onExporterError reports. |
event(event) | One of event or metric | Receives each event. |
metric(record) | One of event or metric | Receives each metric record. |
flush() | If buffered | Sends buffered events and waits for delivery. |
shutdown() | If buffered | Flushes and releases resources. |
attach(context) | No | Called once with a context. |
context.consented() | n/a | Whether the user allows telemetry. Check it before sending buffered events. |
context.pageClosing() | n/a | Whether 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.