π Complete Integration Guide - @revrag-ai/embed-react
π¦ Installation
β οΈ Important: CSS Import (REQUIRED)
The CSS file MUST be imported for the widget to display correctly. Without it, the widget will appear unstyled.Option 1: Global Import (Recommended)
React/Vite:Option 2: Component-Level Import
Option 3: CSS File Import
π― Basic Usage
Fixed Positioning (Default)
Embedded Positioning
π¨ 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
sideprop - Narrow parent (β€ 400px): Widget auto-centers with equal padding
π§ API Reference
EmbedButton Props
useInitialize Hook
π‘ 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: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 embed API
Theembed 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
- 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
- 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:- 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:
- β CSS Import: Imported at the top of the file
- β
SDK Initialization: Using
useInitializehook with loading/error states - β User Data: Sent first before rendering the widget
- β Event Listeners: Set up to monitor agent connection status
- β Custom Events: Tracked when user performs actions
- β Widget Rendering: Only rendered after successful initialization
β‘ Framework-Specific Notes
React + Vite
β Works perfectly with no additional configurationNext.js
β Fully compatible with both App Router and Pages Router β οΈ Import CSS in root layout or _app fileCreate React App
β Works out of the box β οΈ Import CSS in index.tsxTailwind CSS Projects
β No conflicts! The library uses customembed-* 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: EnsureuseInitialize has completed:
Widget overlaps with bottom navigation
Solution: Use thebottomOffset 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 withapp_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: OnlyUSER_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
-
isInitializedis 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
- 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)
- 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
- π§ Issues: GitHub Issues
- π Docs: GitHub README
- π¬ Discussions: GitHub Discussions
π 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