The Chatim Widget SDK allows you to embed and programmatically control the Chatim chat widget on your website.
Add the following code to your website, just before the closing </body> tag:
<script>
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: "YOUR_PROJECT_ID" };
</script>
<script src="https://widget.chatim.app/widget.js" async></script>Replace YOUR_PROJECT_ID with your actual project ID from the Chatim dashboard.
Configure the widget by setting properties on window.chatim.settings:
window.chatim.settings = {
projectId: "YOUR_PROJECT_ID", // Required
params: { // Optional: Custom parameters
userId: "user-123",
utm_source: "google",
utm_campaign: "summer_sale"
}
};window.chatim.widget.open();window.chatim.widget.close();window.chatim.widget.setConfig(config);Updates the widget configuration dynamically at runtime.
const config = window.chatim.widget.getConfig();Returns the current configuration object, or null if the widget is not yet initialized.
window.chatim.widget.setParams({
lastPage: "/checkout",
cartValue: 99.99,
isPremium: true
});Updates custom parameters after the widget has initialized. Parameters are merged with existing values (not replaced).
window.chatim.widget.restartChat();Clears all stored chat data and history, closes the widget, and re-initializes with a fresh session. Useful when a user logs out or you want to reset the conversation.
| Property | Type | Required | Description |
|---|---|---|---|
projectId | String | Yes | Your Chatim project ID |
params | Object | No | Custom parameters (key-value pairs) |
| Method | Returns | Description |
|---|---|---|
open() | void | Opens the chat widget |
close() | void | Closes the chat widget |
setConfig(config) | void | Updates widget configuration |
getConfig() | Object | null | Returns current configuration |
setParams(params) | void | Updates custom parameters (merged) |
restartChat() | void | Clears chat history and restarts session |
Custom parameters allow you to send additional data about your visitors to Chatim. This data is stored with chat sessions and displayed in the admin dashboard Visitor panel.
window.chatim.settings = {
projectId: "YOUR_PROJECT_ID",
params: {
userId: "user-123",
email: "[email protected]",
utm_source: "google",
planType: "premium",
isPremium: true
}
};// Update params when user logs in
window.chatim.widget.setParams({
userId: user.id,
email: user.email,
planType: user.subscription
});
// Track page-specific data
window.chatim.widget.setParams({
lastPage: window.location.pathname,
productViewed: "SKU-12345"
});| Type | Example | Notes |
|---|---|---|
| String | "user-123" | Max 500 characters |
| Number | 99.99 | Integers and decimals |
| Boolean | true | true/false values |
| Null | null | Explicitly set empty |
Not supported: Objects, arrays, functions, undefined
projectId, demo, __proto__, constructor, prototype| Limit | Value |
|---|---|
| Max parameters | 20 |
| Max name length | 50 characters |
| Max value length | 500 characters |
Custom parameters appear in the Chatim dashboard under Visitors — click on a visitor to see their Custom Parameters section.
The widget can automatically capture URL parameters from visitor pages without any code changes. Configure this in Widget Settings > URL Parameters.
window.chatim.settings.params (overrides URL params)window.chatim.widget.setParams() (highest priority)The SDK includes a command queue that allows you to call widget methods before the widget has fully loaded. Commands are automatically executed once the widget is ready.
window.chatim.cmd.push(function() {
window.chatim.widget.close();
});
window.chatim.cmd.push(() => {
window.chatim.widget.open();
console.log('Widget opened!');
});<script>
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: "YOUR_PROJECT_ID" };
// Queue a function to run when widget is ready
window.chatim.cmd.push(() => {
console.log('Widget is ready!');
window.chatim.widget.close();
});
</script>
<script src="https://widget.chatim.app/widget.js" async></script><button onclick="window.chatim.widget.open()">
Chat with us
</button>window.addEventListener('scroll', function() {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
window.chatim.widget.open();
}
});function onUserLogout() {
window.chatim.widget.restartChat();
}setTimeout(function() {
window.chatim.widget.open();
}, 5000);import { useEffect } from 'react';
function App() {
useEffect(() => {
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = {
projectId: 'YOUR_PROJECT_ID',
params: { userId: getCurrentUserId() }
};
const script = document.createElement('script');
script.src = 'https://widget.chatim.app/widget.js';
script.async = true;
document.body.appendChild(script);
return () => document.body.removeChild(script);
}, []);
return <button onClick={() => window.chatim.widget.open()}>Open Chat</button>;
}'use client';
import { useEffect } from 'react';
import Script from 'next/script';
export default function ChatWidget() {
useEffect(() => {
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: 'YOUR_PROJECT_ID' };
}, []);
return (
<Script
src="https://widget.chatim.app/widget.js"
strategy="lazyOnload"
/>
);
}export default {
mounted() {
window.chatim = window.chatim || {};
window.chatim.cmd = window.chatim.cmd || [];
window.chatim.settings = { projectId: 'YOUR_PROJECT_ID' };
const script = document.createElement('script');
script.src = 'https://widget.chatim.app/widget.js';
script.async = true;
document.body.appendChild(script);
},
methods: {
openChat() {
window.chatim.widget.open();
}
}
}// On page load
window.chatim.settings = {
projectId: "YOUR_PROJECT_ID",
params: {
userId: getUserId(),
userType: isLoggedIn() ? "registered" : "guest",
utm_source: getUrlParam("utm_source")
}
};
// On product view
function trackProductView(product) {
window.chatim.widget.setParams({
lastProductViewed: product.name,
lastProductPrice: product.price
});
}
// On add to cart
function trackAddToCart(cart) {
window.chatim.widget.setParams({
cartValue: cart.total,
cartItems: cart.items.length
});
}For backwards compatibility, these legacy APIs are still supported:
// Legacy settings (still works)
window.chatimSettings = { projectId: "YOUR_PROJECT_ID" };
// Legacy widget methods (still works)
window.chatimWidget.open();
window.chatimWidget.close();We recommend using the new window.chatim namespace for all new implementations.
projectId is correctwindow.chatim and window.chatim.cmd are initialized before calling methodsgetConfig() returns null before the widget is fully initialized. Use a polling approach:
const checkWidget = setInterval(() => {
const config = window.chatim.widget.getConfig();
if (config) {
clearInterval(checkWidget);
console.log('Widget config:', config);
}
}, 100);If you need help with the SDK integration, contact [email protected].
Get started