Web reference
@cusuai/web-sdk exports one object, as the default export and as the global Cusu.
| Method | What it does |
|---|---|
initialize(config) | Mount the widget and boot it. |
identify(id, traits?) | Link the visitor to your customer id. |
open() / close() | Open or close the panel. |
isOpened() | true when the panel is open. |
showLauncher() / hideLauncher() | Show or hide the floating button. |
reset() | New anonymous visitor. Rotates cusu_vid, clears local history, and reboots if initialized. |
destroy() | Unmount the widget and clear runtime state. Does not rotate cusu_vid. |
onError(handler \| null) | Subscribe to recoverable errors, or pass null to clear. |
initialize
| Field | Required | Description |
|---|---|---|
group | yes | Group id, grp_… |
apiKey | yes | Public key, pk_… |
apiUrl | no | API base. Defaults to https://api.cusuai.com |
locale | no | Used when reply mode is automatic, or when boot has no language. The widget otherwise follows the group language. |
showLauncher | no | Floating button. Default true. |
A missing group, a missing key, an unknown group, or a rejected key is reported through onError when a handler is set. credits_exhausted means the widget stays hidden until the account has credit again.
identify
Cusu.identify("user_123", {
name: "Jane Doe",
email: "jane@shop.test",
gender: "female"
}); Traits and the signature are described in Identify. An empty id is ignored.
Your own button
Hide the floating button and open the panel from your control.
Cusu.initialize({
group: "grp_…",
apiKey: "pk_…",
showLauncher: false
});
document.querySelector("#help")?.addEventListener("click", () => Cusu.open()); Errors
Cusu.onError((error) => {
// error.code — credits_exhausted, unauthorized, not_found
// error.message — short explanation
});