Skip to main content
The SiteGPT JavaScript SDK allows you to embed your AI chatbot on any website with a simple script tag.

Quick start

Add your chatbot to your website in under 60 seconds:
1

Get your chatbot ID

Find your chatbot ID in your dashboard under Installation.
2

Add the script

Copy and paste this code before the closing </body> tag:
3

Test

Reload your page and click the chat bubble to test your chatbot.

Installation

The simplest way to add your chatbot:
Replace YOUR_CHATBOT_ID with your actual chatbot ID from the Installation page.

Configuration via URL parameters

You can customize the chatbot behavior by adding URL parameters to the widget script:
  • hideBubble=true - Hide the default chat bubble
  • open=true - Open the chat widget automatically
  • mobile=false - Hide the chat widget on mobile devices
  • delay=2000 - Delay widget initialization (in milliseconds)
Example:

SDK methods reference

Control your chatbot programmatically using the $sitegpt JavaScript SDK. All commands use the push method: window.$sitegpt.push([command, ...args])
For a complete interactive reference with copy-paste examples, visit the SDK Methods page in your chatbot dashboard under Installation.

Control widget visibility

Open the chat widget

Programmatically opens the chat widget window.
Example: Open chat when user clicks a custom button

Close the chat widget

Programmatically closes the chat widget window.
Example: Close chat from another element

Toggle the chat widget

Opens the chat widget if it’s closed, and closes it if it’s open.
Example: Use a single button to open or close the chat

Open with fresh conversation

Opens the chat widget and resets the conversation in a single flicker-free step. If there is an existing conversation, it will be cleared and a new one will be started.
Example: Always start a fresh conversation when user clicks your custom button
Use ['open', { reset: true }] instead of calling ['open'] followed by ['do', 'conversation:reset'] separately. It avoids the visual flicker of the old conversation appearing briefly before the reset.

Send messages programmatically

Send a message immediately

Sends a message to the chatbot immediately. The chat widget will open automatically if it’s closed.
Example: Send message when user clicks a pricing button
Example: Complete flow - open chat and send message

Prefill the message input

Prefills the message input field with text. Users can edit the message before sending. The input field will be focused automatically.
Example: Prefill input when user clicks a help button
Example: Open chat and prefill input
Use ['do', 'message:send', ...] when you want to send a message automatically without user interaction. Use ['set', 'message:text', ...] when you want to suggest a message but let the user edit it before sending.

Manage conversations

Reset the current conversation

Resets the current conversation thread and returns to the widget home page. This clears the conversation history and allows the user to start over.
Example: Add a “Start new conversation” button
Example: Reset conversation after form submission
This command is useful when you want to give users a clean slate, such as after completing a transaction, switching topics, or when they explicitly request to start over. The user will be returned to the widget home page where they can see their conversation history.
If you want to reset and open the chat in a single flicker-free step, use window.$sitegpt.push(['open', { reset: true }]) instead. See Open with fresh conversation.

Enhance chatbot context

Give extra context

Provide additional information to your SiteGPT bot for more relevant and contextual conversations, such as the current page the user is on.
Example: Provide page-specific context

Manage user sessions

Automatically log the user in

Automatically log users into the chatbot without requiring email verification. This requires generating a secure signature on your backend.
Never generate signatures in your frontend. Always generate signatures on your backend to keep your API key secure.

Generating signatures (Node.js backend example)

Security notes:
  • Use HMAC-SHA256 algorithm only
  • Generate signatures on your backend server
  • Never expose your API key in frontend code
  • Each signature is unique to the email and your API key

Security of user verification

User verification uses the HMAC-SHA256 signature algorithm, a standard and secure method for authenticating data. When setting a user email via the $sitegpt object, you must provide the signature computed on your backend. This signature uses your secret API key, known only to you and SiteGPT. Because only you and SiteGPT can generate valid signatures for a given email, an attacker without your API key cannot impersonate users.
Never generate signatures directly in your front-end code. Doing so would expose your API key in the browser, allowing anyone to impersonate your users. Always generate signatures on your backend server and never leak your API key.

Customize widget appearance

Add custom CSS

Apply your own CSS to the chatbot widget and style it according to your branding.
Example: Changing the font family

Common use cases

Custom chat trigger

Hide the default bubble and use your own button:

Context-aware chatbot

Provide page-specific context:

Pre-filled messages

Suggest messages based on user actions:

Authenticated users

Auto-login authenticated users by fetching signature from your backend:
Backend API example (Node.js):

Styling

Custom CSS

Apply custom styles to the chat widget:

Available CSS variables

The widget supports these CSS variables:
  • --chat-color - Primary brand color (used for bubble, buttons, etc.)
  • --chat-text-color - Text color for elements using the brand color
  • --chat-font-size - Base font size for the chat interface
The widget uses Tailwind CSS internally. You can target specific elements with custom CSS, but the available CSS variables are limited to those listed above.

Best practices

Load asynchronously

The recommended installation method already loads the SDK asynchronously to avoid blocking page rendering:

Handle loading state

Check if the SDK is loaded before calling methods:

Provide context

Give your chatbot context about the current page:

Test thoroughly

Test your integration across:
  • Different browsers (Chrome, Firefox, Safari, Edge)
  • Mobile devices (iOS, Android)
  • Different screen sizes
  • With ad blockers enabled

Troubleshooting

If your chatbot doesn’t appear, try these solutions:
Check the script tag
Ensure the script is added before </body> and the chatbot ID is correct.
Check browser console
Look for JavaScript errors that might prevent loading.
Verify chatbot is published
Ensure your chatbot is published in the dashboard.
Test in incognito mode
Rule out browser extensions or cached files.
If SDK methods aren’t working, verify these items:
Wait for SDK to load
Ensure the SDK is fully loaded before calling methods.
Check syntax
Verify you’re using the correct method syntax.
Review console errors
Check for JavaScript errors in the browser console.
If custom styles aren’t applying, try these fixes:
Check CSS specificity
Your styles may need !important to override defaults.
Verify CSS syntax
Ensure your CSS is valid.
Clear cache
Clear browser cache and reload the page.

Next steps

Installation guide

Detailed installation instructions

Tracking events

Track chatbot activity in GTM, GA4, or custom analytics

Webhooks

Set up webhooks for real-time events

Appearance

Customize chatbot appearance

API reference

Explore the REST API