@dialog-ai/dialog-bot-analytics
v1.2.0
Published
Frontend analytics library for Dialog chat SDK integration
Maintainers
Readme
Dialog Bot Analytics SDK
Client library for sending UI events, conversation messages, and agent actions to the Dialog analytics API.
Package: @dialog-ai/dialog-bot-analytics
Install
npm install @dialog-ai/dialog-bot-analyticsQuick start
import { BotAnalytics, EventSource } from "@dialog-ai/dialog-bot-analytics";
const analytics = new BotAnalytics(
{
accountId: "acc_enterprise_01",
projectId: "proj_chatbot_v2",
endpointUrl: "https://your-analytics-api.example.com",
apiKey: "your-analytics-api-key",
source: EventSource.UI,
},
{
botId: "bot_123",
sessionId: "session_456",
userId: "user_789",
},
);
await analytics.track("chat_opened", { position: "right" });
await analytics.trackMessage({
sender: "user",
message: "Hello",
messageType: "text",
});
analytics.destroy();endpointUrl is the analytics API origin with no /api/v1 suffix. The client posts to /api/v1/events/, /api/v1/conversations/, and /api/v1/agents/.
If botId or sessionId is missing at construct time, events are buffered until you call updateContext() or setSession().
Config
| Field | Required | Description |
| --- | --- | --- |
| accountId | Yes | Tenant account id |
| projectId | Yes | Tenant project id |
| endpointUrl | Yes | Analytics API base URL |
| apiKey | Yes | Sent as X-API-Key |
| source | No | Default event source (EventSource.UI for the chat widget) |
| requestTimeoutMs | No | Request timeout (default 10000) |
| maxRetries | No | Retries for transient failures (default 2) |
| maxRequestsPerSecond | No | Client-side rate limit (default 10) |
| maxQueueSize | No | Max queued events (default 200) |
| onError | No | Transport error callback |
| silent | No | Suppress console.error (default false) |
API
track(eventType, properties?, metadata?, source?)trackMessage({ sender, message, messageType?, metadata? })trackAgentAction({ agentId, actionType, durationSeconds })updateContext({ botId?, sessionId?, userId? })identify(userId)setSession(sessionId)destroy()
