<script> tag and control it programmatically using the $cgpt object.
Quick start
Replace
YOUR_CHATBOT_ID with your actual chatbot ID from the Installation page. The Installation page provides this snippet pre-filled with your ID.Embed modes
The widget supports two modes controlled bydata-* attributes on the script tag.
- Floating widget (Default)
- Embedded widget (Container mode)
A chat bubble appears fixed in the bottom-right corner of the page. Clicking it opens the chat window.Add this once in your site-wide layout or footer template — it will appear on every page automatically.
Script tag attributes
| Attribute | Required | Description |
|---|---|---|
data-chatbot-id | Yes | Your unique chatbot ID |
data-mode | No | Set to "embedded" to use container mode. Omit for floating (default). |
data-container | When data-mode="embedded" | CSS selector for the container element (e.g. "#my-chat-container") |
data-instance | No | A name for this widget instance. Required when loading multiple widgets on the same page (e.g. "floating", "sidebar"). |
URL parameters
Append these to theloader.js URL to modify widget behavior:
| Parameter | Description |
|---|---|
?hideButton=true | Hides the floating bubble — widget is created but only openable via $cgpt commands |
?hideWidget=true | Skips creating the floating widget entirely — use when you only want embedded containers |
?instance=name | Required when loading two script tags from the same source on the same page (e.g. ?instance=sidebar) |
SDK methods reference
Control the widget programmatically using the$cgpt object. All commands use the push method:
For a complete interactive reference with live testing, visit the SDK Methods page in your chatbot dashboard under Installation → SDK Advanced.
Widget visibility
Open the chat
Open with a fresh conversation
Opens the chat and resets the current conversation in a single flicker-free step.Close the chat
Toggle the chat
Opens if closed, closes if open.Send messages
Send a message immediately
Sends a message on the user’s behalf. The widget opens automatically if it’s closed.Prefill the message input
Fills the input field with text. The user can edit before sending. Widget opens automatically.Manage conversations
Reset the conversation
Clears the conversation history and returns to the widget home page.Reload the widget
Completely tears down and reinitializes the widget. Useful after SPA route changes or when embedded containers appear dynamically.Chatbot context
Inject extra context around every message for more relevant, page-aware responses.- prefix — injected before the user’s message (custom persona, role)
- suffix — injected after the user’s message (current page, URL)
Context is injected transparently — users only see their original message in the chat UI.
User sessions
Automatically log users in using their verified email address. Requires a secure HMAC-SHA256 signature generated on your backend.Custom CSS
Inject CSS into the widget’s shadow DOM to match your branding. The--cgpt-primary CSS variable is reactive and controls the bubble color, header, and user message bubbles.
Targeting multiple widgets
When you have more than one widget instance on the same page, use the targeting API to send commands to a specific instance.| Target | Syntax | Scope |
|---|---|---|
$cgpt.push | window.$cgpt.push([...]) | Broadcasts to all widgets on the page |
$cgpt['instanceName'] | window.$cgpt['floating'].push([...]) | One specific widget by its data-instance name |
$cgpt_widget['chatbotId'] | window.$cgpt_widget['uuid'].push([...]) | All instances sharing that chatbot ID |
$cgpt_widget['chatbotId']['instanceName'] | window.$cgpt_widget['uuid']['floating'].push([...]) | One specific instance within a chatbot ID group |
Common use cases
Custom chat trigger (hide the bubble)
Page-aware context
Pre-filled message on button click
Authenticated users (auto-login)
Troubleshooting
Chatbot not appearing
Chatbot not appearing
Check the script tag
Ensure
Open DevTools (F12) and look for JavaScript errors.Verify the chatbot has training data
A chatbot with no content will not appear.Test in incognito mode
Rules out browser extensions or cached files causing the issue.
Ensure
data-chatbot-id is correct and the script is present in the page source (View → Page Source).Check browser consoleOpen DevTools (F12) and look for JavaScript errors.Verify the chatbot has training data
A chatbot with no content will not appear.Test in incognito mode
Rules out browser extensions or cached files causing the issue.
SDK commands not working
SDK commands not working
Commands are buffered automatically
You don’t need to wait for the script to load — push commands at any time and they replay once the widget is ready.Check the object name
The SDK uses
All commands use the array form:
Look for any JavaScript errors that may prevent the widget from initializing.
You don’t need to wait for the script to load — push commands at any time and they replay once the widget is ready.Check the object name
The SDK uses
window.$cgpt, not window.$ContextGPT.Check the syntaxAll commands use the array form:
window.$cgpt.push(['command', ...args]).Check browser consoleLook for any JavaScript errors that may prevent the widget from initializing.
Embedded widget not filling the container
Embedded widget not filling the container
Set an explicit height on the container
The widget fills 100% of its container’s dimensions. If the container has no height (e.g.
This prevents the widget’s internal scroll from escaping to the page.Check the selector
Ensure
The widget fills 100% of its container’s dimensions. If the container has no height (e.g.
height: auto), the widget will collapse. Set a fixed height: style="height: 600px".Set overflow: hidden on the containerThis prevents the widget’s internal scroll from escaping to the page.Check the selector
Ensure
data-container matches your container’s id or class exactly (e.g. "#my-chat-container").Two widgets interfering with each other
Two widgets interfering with each other
Add
Give each widget a unique instance name (e.g.
Without the query string, the browser deduplicates module scripts with the same URL and only runs one.Use
If you only want embedded containers and no floating bubble, add
data-instance to each script tagGive each widget a unique instance name (e.g.
data-instance="floating" and data-instance="sidebar").Add ?instance=name to each script URLWithout the query string, the browser deduplicates module scripts with the same URL and only runs one.Use
?hideWidget=true on the floating scriptIf you only want embedded containers and no floating bubble, add
?hideWidget=true to the floating script URL.Custom CSS not applying
Custom CSS not applying
The widget uses a shadow DOM
Standard page CSS cannot reach inside the widget. Use
Set
There is no merge — each
Standard page CSS cannot reach inside the widget. Use
$cgpt.push(['set', 'css', '...']) to inject styles.Use :host for top-level variablesSet
--cgpt-primary on :host { } to change the primary color reactively.Calling the command again replaces previous stylesThere is no merge — each
set css call fully replaces the previous custom stylesheet.Next steps
Installation guide
Platform-specific installation instructions
SDK Advanced
Full SDK method reference with live testing
Webhooks
Receive real-time chatbot events
API reference
Manage chatbots via the REST API