Set up an editor

Create the telemetry client, register its module in React or Vue, and choose what to record.

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

Register telemetry

Create the client once, outside your components:

// telemetry.ts
import { createTelemetry } from '@docx-editor.dev/telemetry';
import { sentryExporter } from '@docx-editor.dev/telemetry/sentry';
import * as Sentry from '@sentry/react';

export const telemetry = createTelemetry({
  exporters: [sentryExporter(Sentry)],
  include: { documentOpen: true, trackedChanges: true, editing: true },
  consent: () => consentManager.analytics === true, // your consent manager
  resource: { 'service.name': 'contracts-app' },
});

Register telemetry.module so it receives diagnostics from the first document the editor opens:

import { DocxEditor } from '@docx-editor.dev/react';
import { reviewModule } from '@docx-editor.dev/pro';
import { telemetry } from './telemetry';

const MODULES = [reviewModule(), telemetry.module];

export function Editor({ bytes }: { bytes: Uint8Array }) {
  return <DocxEditor document={bytes} modules={MODULES} />;
}

Register the module or call telemetry.record(event) yourself. Doing both records each event twice.

Choose recorded areas

If you omit include, all areas are on. If you set it, list every area you want, including ones with default options.

AreaRecords
documentOpenOpens with size and page buckets and duration. Refused opens with the reason.
documentSaveEach save() call: saved with size bucket and duration, or failed with the reason.
sessionsEditor start and end, active editing time, and edits by origin. See Sessions.
editingRefused edits and commands while changes are not tracked.
trackedChangesRefused tracked edits, tracking errors, and changes skipped during accept, reject, or reassign.
fontsFonts that failed to load and were substituted.
historyUndo steps that did not group as the gesture intended.
customNodesCustom node payloads that could not be read.
collaborationClientStatus changes, failure codes, connect time, and participant count.
performanceKey press or click to next frame, plus layout and paint times. See Performance.

Configure collection

OptionDefaultBehavior
consentCollection allowedboolean or () => boolean. When false, new events are dropped, not buffered. Checked per event and per timed key press, layout, and paint. Keep it fast. Never runs during server rendering. Applies to every exporter, including the console.
include.<area>.sampleRate10 to 1. Samples events only; metrics count every event. For performance and sessions, the rate selects editors. performance at 0 stops measurement and its metrics.
documentShape'basic''detailed' adds part, paragraph, review item, and embedded font buckets. See Privacy.
dedupeWindowMs10000Identical refusals send once per window. 0 sends every event. A summary then reports repeated, the count of extra events only. Participant counts and repeated statuses also send once per window.

To allow all exporters in local builds, use consent: () => import.meta.env.DEV || consentManager.analytics === true.

Inspect development events

Add consoleExporter() to print each event with its hint and documentation link:

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

export const telemetry = createTelemetry({ exporters: [consoleExporter()] });

For every code and hint, see Diagnostics.

Limits

  • consent controls only this package. Your OpenTelemetry SDK can still export metrics it recorded earlier. Apply the same decision to your Sentry and OpenTelemetry SDKs.
  • A deduplication summary is not a new failure.
  • Which areas become Sentry issues is set by the exporter. See Send to Sentry.

Next steps