wani.track(). Usage recipes are in Events.
TrackEvent
EventType
required
The event name. Must be one of the built-in
EventType values listed below.Record<string, unknown>
Event payload. For built-in events, the type is narrowed (for example,
link.clicked expects { url?: string }).Record<string, unknown>
MCP request metadata, typically
extra._meta inside a tool handler. This is where the SDK reads the session id from. See Sessions.string
Explicit session id override. Prefer passing
meta instead.string
Anonymous visitor id (the analytics “device id”). Counts as identity on its own; the chat widget uses it for pre-session events like
page.viewed. See Sessions.string
Client-generated id. If you omit it, the SDK generates
evt_<uuid>. Supplying your own enables idempotent resends.track() returns { eventId } as soon as the envelope is enqueued, before the network request completes.
EventType union
A closed union exported from @waniwani/sdk. Only these names are accepted by track(). The same list is available at runtime as the EVENT_TYPES constant.
The five revenue events also have flat typed helpers on
track (for example wani.track.leadQualified({ ... })). Each helper accepts its event’s properties plus the shared tracking context (sessionId, externalUserId, meta, and so on). Placement guidance for each lives in Instrumentation.
Typed property interfaces
session.error carries no error message, stack, or handler input, only the bounded tokens above. The code and cause unions are available at runtime as the SESSION_ERROR_CODES and ERROR_CAUSES constants exported from @waniwani/sdk. That keeps the properties safe to surface to a customer. The SDK also writes a console.error line prefixed [waniwani][session-error], but that line carries only the same code:tool:cause token and the node name, not the thrown error. To keep the underlying error, log it yourself in the handler where it is thrown.Browser surfaces (
useWaniwani(), chat.track) send the same EventType union through the same envelope; there is no separate widget event schema. See Widgets & chat.