Installation
Add the Chatwoot widget script to your HTML:app/javascript/entrypoints/sdk.js:21-24
Configuration Options
Set configuration options viawindow.chatwootSettings before the SDK loads:
app/javascript/entrypoints/sdk.js:50-81
Widget Control Methods
toggle()
Open or close the chat widget.app/javascript/entrypoints/sdk.js:83-85
toggleBubbleVisibility()
Show or hide the chat bubble launcher.app/javascript/entrypoints/sdk.js:87-102
Use case: Hide the bubble on certain pages or show/hide based on user behavior.
popoutChatWindow()
Open the chat widget in a new popup window.app/javascript/entrypoints/sdk.js:104-110
Note: Requires showPopoutButton: true in widget settings.
reset()
Reset the widget session and clear all user data.app/javascript/entrypoints/sdk.js:195-210
Use case: Call this when a user logs out of your application.
User Management Methods
setUser()
Identify a user and set user properties.identifier(required): Unique user identifier (string or number)user(required): Object with at least one of:name,email, oravatar_url
app/javascript/entrypoints/sdk.js:112-137
Example with all properties:
setCustomAttributes()
Set custom attributes for the current contact.app/javascript/entrypoints/sdk.js:139-145
Requirements: Must have at least one key in the object.
deleteCustomAttribute()
Delete a specific custom attribute for the current contact.app/javascript/entrypoints/sdk.js:147-154
Conversation Management Methods
setConversationCustomAttributes()
Set custom attributes for the current conversation.app/javascript/entrypoints/sdk.js:157-165
deleteConversationCustomAttribute()
Delete a specific custom attribute from the current conversation.app/javascript/entrypoints/sdk.js:167-174
setLabel()
Add a label to the current conversation.app/javascript/entrypoints/sdk.js:177-179
removeLabel()
Remove a label from the current conversation.app/javascript/entrypoints/sdk.js:181-183
Appearance Methods
setLocale()
Change the widget language.app/javascript/entrypoints/sdk.js:185-187
Supported locales: en, es, fr, de, pt, pt_BR, ru, zh_CN, zh_TW, ja, ko, and many more.
setColorScheme()
Change the widget color scheme.app/javascript/entrypoints/sdk.js:189-193
Widget Events
Listen to widget events using standard DOM event listeners:app/javascript/widget/constants/sdkEvents.js
Event Types
chatwoot:ready- Widget has finished loadingchatwoot:opened- Widget was openedchatwoot:closed- Widget was closedchatwoot:on-message- New message receivedchatwoot:on-start-conversation- User started a new conversationchatwoot:error- An error occurredchatwoot:postback- Postback action from interactive message
Complete Integration Example
Advanced Use Cases
Dynamic User Context
Update user and conversation context as the user navigates:Conditional Widget Display
Label-based Routing
Multi-language Support
Turbo/SPA Support
The Chatwoot widget automatically persists across page navigations in Turbo, Turbolinks, and Astro applications. Source:app/javascript/entrypoints/sdk.js:27-48
Supported frameworks:
- Rails Turbo (with morphing and navigation)
- Turbolinks
- Astro
data-turbo-permanent to persist across page loads.
Browser Compatibility
The Chatwoot widget supports:- Chrome/Edge (last 2 versions)
- Firefox (last 2 versions)
- Safari (last 2 versions)
- Mobile browsers (iOS Safari, Chrome on Android)
Troubleshooting
Widget not loading
setUser() not working
Make sure to callsetUser() after the chatwoot:ready event:
Widget conflicts with z-index
The widget usesz-index: 2147483000. Adjust your page elements if needed.
Source: app/javascript/sdk/sdk.js:15
Related Resources
- Widget API Reference - Detailed API documentation
- Custom Attributes - Custom attribute management
- Webhooks - Receive widget events on your server

