Add the Kommander.ai widget to any page where visitors should be able to chat with your assistant. The hosted script is the supported install path for websites, web apps, CMS templates, and storefront themes.

Before You Start

  • Copy your Kommander user ID or organization ID from the chatbot setup screen.
  • Replace YOUR_KOMMANDER_USER_ID or YOUR_ORGANIZATION_ID in the examples.
  • Add the widget once per page, usually in the root layout, app shell, footer template, or theme layout.
  • Use server-generated identity only for signed-in visitors. Anonymous visitors can initialize without identity.

Initialization Contract

type KommanderWidgetInitOptions = { userId?: string; organizationId?: string; containerId?: string; forceReset?: boolean; userData?: Record<string, unknown>; identity?: { id: string; email: string; userHash: string; }; timer?: boolean; timerEnabled?: boolean; language?: string; };

Use organizationId for team-owned assistants and userId for personal assistants. If both are available, prefer the ID shown in the embed snippet generated by Kommander.ai.

Framework Examples

Plain HTML

Authenticated Visitors

For signed-in visitors, generate identity on your server after your app authenticates the session, then pass the verified identity into the widget initialization. Never place the HMAC secret in browser code.

<div id="kommander-chatbot"></div> <script src="https://app.kommander.ai/chatbot.js"></script> <script> window.initKommanderChatbot({ userId: "YOUR_KOMMANDER_USER_ID", identity: { id: "user_123", email: "customer@example.com", userHash: "SERVER_GENERATED_HMAC" }, userData: { plan: "pro", locale: "en" } }); </script>

See Identity Verification for the HMAC signing flow and backend code samples.

Widget Lifecycle

The widget script loads React if it is not already available, injects chatbot.css, creates the target container if it does not exist, and mounts the chat UI into that container. It stores a per-page conversation ID and anonymous end-user ID in browser storage so returning visitors can continue the current thread.

Use forceReset: true only when you intentionally need to unmount and reinitialize the widget, for example after a single-page app changes from anonymous to signed-in state.

window.initKommanderChatbot({ userId: "YOUR_KOMMANDER_USER_ID", forceReset: true, identity: signedIdentity });

State Management

  • Initialize once in a stable layout, not in every route component.
  • Keep containerId stable across route changes.
  • Reinitialize with forceReset: true when the signed-in user changes.
  • Pass non-sensitive analytics attributes through userData.
  • Generate a fresh HMAC identity on the server when the page is rendered or when the session changes.

Verification Checklist

  • The page contains one widget container.
  • https://app.kommander.ai/chatbot.js loads without a console error.
  • window.initKommanderChatbot runs after the script loads.
  • The correct userId or organizationId is sent.
  • Signed-in visitors receive a server-generated identity.
  • The first test conversation appears in Conversations.