Embed React SDK Integration Guide
Overview
The Embed React SDK is a powerful voice-enabled AI agent library that provides real-time communication capabilities. This comprehensive guide will walk you through the complete integration process from installation to deployment.Prerequisites
- Node.js 18+
- React 16.8+ or Next.js 12+
- Modern browser with WebRTC support
This SDK requires proper setup of browser permissions and real-time communication dependencies.
Installation
Install the Embed React SDK using your preferred package manager:Required CSS Import
CRITICAL: Always import the CSS file for proper styling. Missing this import will cause the widget to display incorrectly.
SDK Initialization
useInitialize Hook
Initialize the SDK at the root level of your application using theuseInitialize hook:
Configuration Options
| Property | Type | Required | Description |
|---|---|---|---|
apiKey | string | ✅ | Your Embed API key |
App Setup
1. Basic React Application
Add the EmbedButton component to your screen:2. Next.js Integration
App Router (app/layout.tsx)
Pages Router (_app.tsx)
Event System
The SDK provides a powerful event system for sending user context and application state to the AI agent.Available Events
Event Usage Rules
CRITICAL REQUIREMENTS:
- USER_DATA event MUST be sent first before any other events
- USER_DATA must include
app_user_idfor user identification - EmbedButton should only be rendered AFTER USER_DATA event is sent
- Other events can only be sent after USER_DATA is established
Event Methods
Event Flow Example
Usage Examples
Complete Integration Example
Widget Customization
Positioning
Automatic Event Tracking
The library automatically tracks user interactions and sends them through the event system:Automatic Tracking Features
- Button Clicks: All button and submit inputs (tracked as
EventKeys.FORM_STATE) - Form Inputs: Text fields, textareas, dropdowns (tracked as
EventKeys.FORM_STATE) - Field Focus: When users focus on form fields (tracked as
EventKeys.FORM_STATE) - Screen Views: Page navigation (React Router & Next.js) (tracked as
EventKeys.SCREEN_VIEW) - Form Changes: Dropdowns, checkboxes, radio buttons (tracked as
EventKeys.FORM_STATE)
The tracking system is automatically initialized when you use the
useInitialize hook. All tracked events are sent with appropriate event keys without additional configuration.Troubleshooting
Common Issues
Widget not appearing
Widget not appearing
Check these requirements:
- ✅ CSS file imported:
import '@revrag-ai/embed-react/dist/ai-assistant-widget.css' - ✅ SDK initialized successfully (
isInitializedis true) - ✅ Valid API key provided
- ✅ USER_DATA event sent first
- ✅ EmbedButton rendered after USER_DATA
User identity not found error
User identity not found error
This error occurs when you try to send events before USER_DATA:
- ✅ Send
USER_DATAevent first withapp_user_id - ✅ Wait for the event to complete before sending other events
- ✅ Only render
EmbedButtonafter USER_DATA is sent
Voice calls not working
Voice calls not working
This issue is usually related to browser permissions or network configuration:
- ✅ Ensure HTTPS in production (WebRTC requirement)
- ✅ Check browser microphone permissions
- ✅ Verify LiveKit configuration
- ✅ Test network connectivity
Events not tracking
Events not tracking
Verify automatic tracking is working:
- ✅ Verify
useInitializehas been called - ✅ Check browser console for event logs
- ✅ Use
embedEvent.addCallback()to monitor events - ✅ Ensure DOM elements have proper attributes
User context not persisting
User context not persisting
Check user data management:
- ✅ Check localStorage availability
- ✅ Verify USER_DATA event is sent first
- ✅ Ensure
app_user_idis provided - ✅ Check for browser storage restrictions
Network Debugging
Best Practices
Event Optimization:
- Debounce frequent events to avoid overwhelming the API
- Batch related data in single events
- Handle offline scenarios with retry logic
- Store events locally when network is unavailable
Initialization Strategy:
- Show loading states during SDK initialization
- Handle initialization errors gracefully
- Send USER_DATA as early as possible in the app lifecycle
- Only render EmbedButton after successful initialization
Performance & Security:
- Use lazy loading for large applications
- Keep API keys secure with environment variables
- Use HTTPS endpoints in production
- Test widget interactions thoroughly
- Monitor usage and performance metrics
Support
For additional help:- Email Support: contact@revrag.ai
Last Updated: June 2025