Accessing the API
Once the widget SDK is loaded, interact with it viawindow.$supportUnicorn:
Methods
Open/Close Widget
Identify User
Identify the current user to provide context:Set Custom Attributes
Add custom attributes for better context:Show/Hide Bubble
Control bubble visibility:Change Locale
Update the widget language:Change Theme Color
Update the primary color:Reset Widget
Clear all cookies and reload widget:Open in Popup Window
Open chat in a popup window:Example: User Identification Flow
Example: Conditional Display
Example: Dynamic Theming
Framework Compatibility
The SDK automatically handles navigation in:- Rails Turbo - Preserves widget across page navigations
- Turbolinks - Legacy Turbolinks support
- Astro - Astro framework support
- Standard SPAs - Works with any single-page app
Events (Future)
Future versions may support event listeners:Troubleshooting
API not available
- Ensure SDK script is loaded:
window.$supportUnicornshould exist - Check browser console for errors
- Verify widget token is valid
Methods not working
- Check widget is fully loaded before calling methods
- Wrap calls in a check:
if (window.$supportUnicorn) { ... }
Next Steps
Widget Overview
Learn more about widget architecture