Skip to main content

πŸš€ Complete Integration Guide

πŸ“¦ Installation

⚠️ Important: CSS Import (REQUIRED)

The CSS file MUST be imported for the widget to display correctly. Without it, the widget will appear unstyled. React/Vite:
Next.js App Router:
Next.js Pages Router:

Option 2: Component-Level Import

Option 3: CSS File Import


🎯 Basic Usage

Fixed Positioning (Default)

Embedded Positioning


Instead of manually placing <EmbedButton /> on every page, wrap your app once with EmbedProvider and let it handle widget visibility automatically.
BEST PRACTICE: Use EmbedProvider to automatically manage the EmbedButton based on the current route.The EmbedProvider component:
  • βœ… Automatically tracks route changes and shows/hides the widget
  • βœ… Conditionally renders the EmbedButton based on the current page
  • βœ… Supports delays before the button appears on a route
  • βœ… Supports visibility groups for per-route delay, continuity, and position
  • βœ… Built-in component - no need to create a custom provider

Basic Setup

Show on specific routes only

EmbedProvider Props

Advanced usage guide β†’

🎨 Responsive Behavior

Fixed Positioning

  • Desktop (> 500px): Widget stays at specified position
  • Mobile (≀ 500px): Widget expands to full width with 1rem padding from edges

Embedded Positioning

  • Wide parent (> 400px): Widget aligns to left/right based on side prop
  • Narrow parent (≀ 400px): Widget auto-centers with equal padding

πŸ”§ API Reference

EmbedButton Props

Hooks

useInitialize

Initializes the SDK with your API key. Must be called before using any other SDK features.

useEmbed

Reads currentPath from EmbedProvider context. Useful for accessing the current route within your components.

useLiveKit

Provides programmatic control over voice calls:
  • connect(): Initiate a voice call
  • disconnect(): End the current voice call
  • toggleMute(): Mute/unmute the microphone

useSSRSafe / useBrowserSafe

SSR-safe mount detection hooks. Returns true when component is mounted on the client side. Useful for Next.js and other SSR frameworks to prevent hydration mismatches.

πŸ“‘ Event Management

The SDK provides a powerful event system for tracking user data, custom events, and listening to agent state changes.

EventKeys

Available event types:
Note: Only USER_DATA , CUSTOM_EVENT and ANALYTICS_DATA are available for manual use. Agent connection events are automatically tracked by the SDK and can be listened to via callbacks.

Sending Events with embedEvent API

The embedEvent object provides methods for sending events to track user data and custom application events.

Send User Data

Send Custom Events

Send Analytics Events

Event Method Signature


Listening to Agent Events

Monitor voice agent connection status in real-time. These events are automatically sent to your backend AND emitted locally for you to listen to.

Available Event Types for Listening

Automatic Backend Sync:
  • Agent events are automatically sent to your backend with app_user_id
  • Events are also emitted locally for real-time UI updates
  • Backend receives all event data including timestamps and metadata
  • No manual API calls needed - it’s all handled automatically

Event Listener Methods

Basic Event Listening Example

Complete Agent Monitoring Example

Advanced: Multiple Event Listeners

Use Cases for Agent Events

AGENT_CONNECTED:
  • Show visual indicators (green dot, badge)
  • Enable voice-related features in UI
  • Start analytics timers
  • Update user presence status
  • Show notifications to user
  • Pause background music/media
AGENT_DISCONNECTED:
  • Update UI to show agent unavailable
  • Log analytics (call duration, success)
  • Show feedback forms
  • Resume background media
  • Clean up resources
  • Save conversation state

What Gets Sent to Backend

When an agent event fires, the SDK automatically sends this data to your backend:
This allows you to:
  • Track agent usage analytics
  • Monitor call durations
  • Understand user engagement patterns
  • Build reports on voice agent interactions
  • Audit agent connections

Event Data Structure

Handling Connection Errors


πŸ“± Mobile Optimization

The widget automatically adjusts for mobile devices:

Extra Small Screens (≀ 375px)

  • iPhone SE, small Android devices
  • Reduced padding and font sizes
  • Optimized button and text layouts

Small Screens (376px - 500px)

  • Standard smartphones
  • Balanced sizing for readability

🎯 Common Use Cases

1. Customer Support Widget with User Tracking

2. E-commerce with Purchase Tracking

3. Help Section Widget with Agent Status

4. With Bottom Navigation

5. Multi-Department Support

6. Contextual Events Based on User Actions


πŸ”„ Complete Integration Example

Here’s a complete example showing initialization, user tracking, event listening, and the widget all working together:

Key Points in This Example:

  1. βœ… CSS Import: Imported at the top of the file
  2. βœ… SDK Initialization: Using useInitialize hook with loading/error states
  3. βœ… User Data: Sent first before rendering the widget
  4. βœ… Event Listeners: Set up to monitor agent connection status
  5. βœ… Custom Events: Tracked when user performs actions
  6. βœ… Widget Rendering: Only rendered after successful initialization

⚑ Framework-Specific Notes

React + Vite

βœ… Works perfectly with no additional configuration

Next.js

βœ… Fully compatible with both App Router and Pages Router ⚠️ Import CSS in root layout or _app file

Create React App

βœ… Works out of the box ⚠️ Import CSS in index.tsx

Tailwind CSS Projects

βœ… No conflicts! The library uses custom embed-* prefixed classes βœ… Your Tailwind styles won’t affect the widget βœ… Widget styles won’t affect your app

πŸ› Troubleshooting

Widget appears unstyled

Solution: Make sure you’ve imported the CSS file:

Widget not appearing

Solution: Ensure useInitialize has completed:

Widget overlaps with bottom navigation

Solution: Use the bottomOffset prop:

Widget too small on mobile

Solution: This is handled automatically! The widget is fully responsive.

Events not being sent

Solution: Ensure you’ve sent USER_DATA event first with app_user_id:

Agent event listeners not firing

Solution: Make sure callbacks are registered before agent connection:

β€œUser identity not found” error

Solution: Send USER_DATA event before any other events:

Custom events being blocked

Solution: Only USER_DATA and CUSTOM_EVENT are allowed for manual sending. Agent events (AGENT_CONNECTED, AGENT_DISCONNECTED) are auto-tracked and can only be listened to, not manually sent.

πŸ“‹ Checklist

Before deploying, ensure: Basic Setup:
  • CSS file is imported
  • API key is configured
  • isInitialized is checked before rendering
  • Parent container has position: relative (for embedded mode)
  • Parent container has sufficient height (for embedded mode)
  • Bottom offset is set if you have bottom navigation
Event System:
  • USER_DATA event sent first with app_user_id
  • USER_DATA sent before rendering EmbedButton
  • Event listeners registered before agent connection
  • Event listeners cleaned up on component unmount
  • Custom events include proper context (screen, flow)
Production Readiness:
  • Error handling for failed event sends
  • Loading states during SDK initialization
  • Agent connection status displayed to users
  • Analytics tracking for agent events
  • Proper cleanup of callbacks on unmount

πŸ†˜ Support


πŸŽ‰ You’re All Set!

The widget is now ready to use. It’s:
  • βœ… Fully responsive
  • βœ… Framework-agnostic
  • βœ… Tailwind-compatible
  • βœ… Production-ready
  • βœ… Mobile-optimized
  • βœ… Real-time event tracking
  • βœ… Voice agent monitoring
  • βœ… User context aware

Quick Reference

Import everything you need:
Initialize and track:
Happy coding! πŸš€