window.$sitegpt command queue. The install snippet creates it. Use it to control the chat widget from JavaScript on your own page.
The SDK is part of the widget. There is nothing extra to install. To add the widget to your site, see Add SiteGPT to your website.
This page is about the chat widget in the browser. To manage chatbots, content, or conversations from a server, use API v2 or the TypeScript SDK.
How commands work
Every command is an array that you push onto the queue:- The first item is the command name. The other items are its arguments.
- Push commands after the install snippet. The snippet sets
window.$sitegptto a new, empty queue, so commands pushed before it are lost. - After the widget script runs,
open,close,toggle,on,off,message:send, andmessage:textrun at once. Other commands wait until the chat window first loads. By default, that happens when the visitor first opens the chat. window.$sitegptis shared by every SiteGPT chatbot on the page. Each chatbot also has its own queue,window.$sitegpt_widget['YOUR_CHATBOT_ID'], which takes the same commands.
Command list
The SDK has no other commands. There is no
init, identify, or boot command, and no $sitegpt.open() function.
Open, close, and toggle
open options:
reset: truestarts a new conversation as the window opens. Use it instead of['open']followed by['do', 'conversation:reset']. The visitor does not see the old conversation first.focus: trueputs the keyboard cursor in the message box.
['close'], the widget remembers this in the browser. Auto-open does not run again until the chat is opened again. ['open'] still works.
On pages listed under Settings > General > Excluded Pages, ['open'] does not open the chat. The browser console shows a message that the page is excluded. This does not apply when you load the widget with hideBubble=true or hideButton=true. See Control where the chat appears.
Send or prefill a message
['open'] first.
Start a new conversation
['open', { reset: true }].
Reload the widget
Add page or visitor context
Useset context to give the chatbot facts about the current page or the signed-in visitor. For example, the product the visitor is looking at, or the visitor’s plan in your app.
- The value is an array of two strings. SiteGPT adds the first string before your chatbot instructions. It adds the second string after the content it found for the question. Use an empty string (
'') for the part you do not need. - The context applies to the visitor’s next messages on this page load. SiteGPT does not save it. Push it again on each page load.
- In a single-page app, push new context when the visitor moves to another page. The new values replace the old ones.
- Do not put secrets in the context. It runs in the visitor’s browser.
Identity verification
Identity verification signs in a visitor that your own site already knows. The widget then treats the visitor as that email address, without an email code. You need:- The Growth plan or above. See Plans and limits.
- Your legacy API key. It is on the Billing page, in the line “Your API Key is …”. This is not an
sgpt_token from the Agents page. See Authentication. - A backend where you can keep the key secret.
- Sign the exact email string that you send. A different spelling or letter case gives a different signature.
- If the signature does not match, the visitor stays anonymous. The widget shows no error.
- For the hosted chat link or the iframe embed, add the same values as the
user_emailanduser_email_signatureURL parameters. - The legacy API key does not change on its own. If your key ever changes, old signatures stop working. Make new signatures with the new key.
Add CSS
For most visual changes, use the Appearance page instead. See Change the widget appearance.
Events
Useon and off to run your own code when something happens in the widget:
chat_opened, chat_closed, conversation_started, message_sent, lead_submitted, human_handover, and booking_link_clicked. Tracking events lists the payloads and shows how to send them to Google Tag Manager or GA4.
Troubleshooting
Commands do nothing
Commands do nothing
- Make sure the install snippet is on the page. It creates
window.$sitegpt. - Check the command spelling. Unknown commands show a
SiteGPT: Unknown commandwarning in the browser console. - Check the browser console for a message that the page is listed under Excluded Pages, or that the domain is not in Allowed Domains.
The chat does not appear at all
The chat does not appear at all
- The widget does not load when the chatbot is disabled, or when the account owner’s subscription or trial has ended.
- If you set Allowed Domains in Settings > General, the current domain must be in the list.
- See Add SiteGPT to your website for install checks.
The visitor is not signed in after set user:email
The visitor is not signed in after set user:email
- Make the signature with the legacy API key from the Billing page, not an
sgpt_token. - Sign exactly the same email string that you push.
- Check that the signature is a hex string, not Base64.
My CSS does not apply
My CSS does not apply
- Check that the CSS is valid.
- Use a more specific selector, or
!important, to override the widget’s own styles.