Skip to main content
This guide is for the developer embedding the Switchbord chat widget on a website. The install is a single async script tag; everything else on this page is optional depth — SPA recipes, the JavaScript SDK, signed identity for logged-in users, and troubleshooting.

Prerequisites

From the workspace operator (or Settings → Integrations → Channels → Website widget if that’s you):
  • The install snippet (or just the widget slug and API base URL).
  • Confirmation that your site’s origin is in the widget’s allowed origins list — the exact scheme + host, e.g. https://www.example.com. www and apex are different origins; add both if both serve the site.
The hosted API base is https://api.switchbord.ai. Self-hosted instances substitute their own API domain everywhere it appears below.

The snippet

Paste this before the closing </body> tag on every page that should show the widget:
That’s the entire install. The script injects a launcher bubble and an isolated iframe; appearance, copy, and AI behavior are all controlled from Switchbord Settings and publish without snippet changes.
If you want to call the SDK before the script has loaded (for example setVisitor in inline code), add the command-queue stub first — calls made before load are queued and replayed:

Framework recipes

Paste the snippet before </body> in your base layout/template so it appears on every page. Done.
Use next/script in the root layout so the widget loads once per navigation session, client-side only:
Do not render the script inside pages that remount on navigation — the loader is idempotent (it won’t create a second iframe), but loading it once in the layout is cleaner.
Load once in a top-level effect:
Create a Custom HTML tag containing the snippet, trigger it on All Pages (or a page-path trigger if you only want it on some pages), and publish. Remember GTM fires from your site’s origin, so the origin allowlist requirement is unchanged.
Either paste the snippet into your theme’s footer.php before </body>, or use any “insert headers and footers” plugin and place it in the footer section. Site-builder platforms (Webflow, Squarespace, Shopify) all have an equivalent “custom code before </body>” setting.

Content-Security-Policy

If your site ships a CSP, allow the Switchbord API origin in these directives:
The widget UI runs inside an iframe served from the API origin, so your page only needs to load the loader script and embed the frame — no inline-script or style allowances are required from your site.

JavaScript SDK

The loader exposes window.SwitchbordWidget: Events for on(event, fn):

Signed identity (Secure Mode)

If your site has logged-in users, mint a short-lived HS256 JWT on your server and pass it to login() so Switchbord verifiably knows who the visitor is. Verified visitors resume their conversation across devices, and operators see verified contact details instead of anonymous sessions. Setup:
  1. In Switchbord, generate the Widget identity signing secret under Settings → Integrations → Provider secrets (widget-identity-secret). It is stored in the workspace Vault; the browser never sees it.
  2. Set the widget’s identity mode in the widget settings (and optionally Require identity to block messaging until login).
  3. Mint tokens server-side with these claims:
Then, in the page for logged-in users:
The signing secret must never reach the browser. Mint tokens in a server endpoint or inject them into the page server-side. Any standard JWT library (jsonwebtoken, firebase/php-jwt, PyJWT) also works — the hand-rolled examples above just avoid a dependency.

Verify the install

  1. Open your site — the launcher bubble appears bottom-right (or bottom-left per theme) within a second or two.
  2. curl https://api.switchbord.ai/api/v1/widgets/YOUR_WIDGET_SLUG/config returns 200 with the widget config JSON.
  3. Send a test message from the widget — it appears in the Switchbord inbox in real time.
  4. Reply from the inbox — the visitor sees it (with the operator’s name) within a few seconds; if the panel is closed, an unread badge appears on the launcher.
  5. If AI mode is draft or auto-send, the test message produces a GBCA draft (or autonomous reply) after a short debounce.

Troubleshooting

Install prompt for AI coding agents

Give this to Cursor, Claude Code, Copilot, or any coding agent working on your website. Replace the two placeholders, paste, and let it run.
Localhost testing: add http://localhost:3000 (or your dev port) to the widget’s allowed origins while developing, and remove it before go-live. An empty allowlist allows all origins — fine for a first smoke test, not for production.