Skip to main content

Overview

The AI Chat SDK provides a comprehensive event system that notifies your application about user interactions and UI state changes. Events enable you to track user behavior, trigger analytics, and respond to interactions across the chat panel, badge, and inline input.

Registering event listeners

Pass event listeners to initializeAiChatSdk as the third parameter:
You can register multiple listeners, and all will be called when an event occurs.

Event structure

All events follow this structure:
  • type: The event type (see available events below)
  • data: Event-specific data
  • chatSessionId: Unique identifier for the current chat session (present in all events)

Badge events

Events emitted by the floating badge entry point.

BADGE_SHOWN

Emitted when the badge becomes visible. Event type: AiChatSdkEventType.BADGE_SHOWN Payload:
Example:

BADGE_CLICKED

Emitted when the user clicks the badge. Event type: AiChatSdkEventType.BADGE_CLICKED Payload:
Example:

BADGE_CLOSED

Emitted when the badge is closed or hidden. Event type: AiChatSdkEventType.BADGE_CLOSED Payload:

BADGE_PROMPT_CLICKED

Emitted when the user clicks a prompt on the badge. Event type: AiChatSdkEventType.BADGE_PROMPT_CLICKED Payload:
Example:

Inline events

Events emitted by the inline input entry point.

INLINE_SHOWN

Emitted when the inline input becomes visible. Event type: AiChatSdkEventType.INLINE_SHOWN Payload:

INLINE_CLICKED

Emitted when the user clicks the inline input. Event type: AiChatSdkEventType.INLINE_CLICKED Payload:

INLINE_PROMPT_CLICKED

Emitted when the user clicks a prompt in the inline input. Event type: AiChatSdkEventType.INLINE_PROMPT_CLICKED Payload:

Chat events

Events emitted by the chat panel.

CHAT_SHOWN

Emitted when the chat panel becomes visible. Event type: AiChatSdkEventType.CHAT_SHOWN Payload:
Example:

CHAT_CLOSED

Emitted when the user closes the chat panel. Event type: AiChatSdkEventType.CHAT_CLOSED Payload:

CHAT_MESSAGE_SENT

Emitted when the user sends a message in the chat. Event type: AiChatSdkEventType.CHAT_MESSAGE_SENT Payload:
For privacy reasons, the message content is not included in the event payload. Use this event to track engagement metrics like message frequency.

CHAT_PROMPTS_SHOWN

Emitted when suggested prompts are displayed to the user. Event type: AiChatSdkEventType.CHAT_PROMPTS_SHOWN Payload:

CHAT_PROMPT_CLICKED

Emitted when a user clicks a suggested prompt. Event type: AiChatSdkEventType.CHAT_PROMPT_CLICKED Payload:
Emitted when a user clicks a link within the chat interface. Event type: AiChatSdkEventType.CHAT_LINK_CLICKED Payload:
Example:

CHAT_ERROR_SHOWN

Emitted when an error is displayed to the user in the chat interface. Event type: AiChatSdkEventType.CHAT_ERROR_SHOWN Payload:

CHAT_TOP_MERCHANTS_SHOWN

Emitted when a list of top merchants is displayed in the chat. Event type: AiChatSdkEventType.CHAT_TOP_MERCHANTS_SHOWN Payload:

CHAT_TOP_MERCHANTS_CLICKED

Emitted when a user clicks on a merchant in the top merchants list. Event type: AiChatSdkEventType.CHAT_TOP_MERCHANTS_CLICKED Payload:

CHAT_PRODUCTS_SHOWN

Emitted when products are displayed in the chat. Event type: AiChatSdkEventType.CHAT_PRODUCTS_SHOWN Payload:

CHAT_PRODUCTS_CLICKED

Emitted when a user clicks on a product. Event type: AiChatSdkEventType.CHAT_PRODUCTS_CLICKED Payload:

CHAT_PRODUCTS_PAGE_NEXT_CLICKED

Emitted when the user clicks to view the next page of products. Event type: AiChatSdkEventType.CHAT_PRODUCTS_PAGE_NEXT_CLICKED Payload:

CHAT_PRODUCTS_PAGE_PREVIOUS_CLICKED

Emitted when the user clicks to view the previous page of products. Event type: AiChatSdkEventType.CHAT_PRODUCTS_PAGE_PREVIOUS_CLICKED Payload:

Event types reference

All available event types:

Event flow examples

Badge to chat flow

Product browsing flow

Analytics integration example

Here’s a complete example of integrating SDK events with an analytics service:

Debugging events

Enable debug mode to see all events logged to the console:
You can also add a simple debug listener:

Best practices

1. Track meaningful metrics

Focus on events that provide business value:
  • Entry point engagement: BADGE_SHOWNBADGE_CLICKEDCHAT_SHOWN
  • Conversion funnel: CHAT_PROMPTS_SHOWNCHAT_PROMPT_CLICKEDCHAT_PRODUCTS_CLICKED
  • Session duration: Time between CHAT_SHOWN and CHAT_CLOSED
  • Error monitoring: CHAT_ERROR_SHOWN frequency

2. Handle errors gracefully

Wrap event handlers in try-catch to prevent one handler from breaking others:

3. Avoid blocking operations

Event handlers should be fast and non-blocking:

4. Clean up resources

Use events to manage resources like timers:

5. Respect user privacy

Be mindful of what data you collect: