Skip to content
Back to Documentation

Website Widget Integration

Put your AI agent on any website with one snippet

Quick Start

The dashboard generates a ready-to-paste snippet that already contains your widget API key and the correct server URL. You never need to edit it by hand.

Get your embed code

  1. 1Open Dashboard → Agents and select your agent
  2. 2Make sure the status badge in the header says Active (the widget refuses to load for inactive agents)
  3. 3Go to the Embed Code tab, copy the snippet and paste it just before </body> on every page where the chat should appear
  4. 4Load your site once. The Embed Code tab switches from "Not detected yet" to Installed on your-domain.com on the first visit, so you know it worked without opening the browser console.

The embed snippet

Embed Code (example)

<!-- AgentPro Chat Widget -->
<script>
  window.AgentProConfig = {
    apiKey: "cbp_YOUR_WIDGET_API_KEY",
    apiUrl: "https://agentpro.chat"
  };
</script>
<script src="https://agentpro.chat/widget.js" async></script>

How it works

The snippet sets window.AgentProConfig and loads widget.js from https://agentpro.chat. The widget authenticates every request with the apiKey (it starts with cbp_). If you regenerate the key in the dashboard, update the snippet on your site. The snippet is identical for every page and every platform; the sections below show where to paste it.

WordPress, Shopify, Wix and more

Where do I paste this?

  1. Open the HTML file (or layout template) of every page that should show the chat.
  2. Paste the snippet just before the closing </body> tag.
  3. Save, upload and reload the page in a private window.

Testing on your computer

The widget works on http://localhost too. If you set an allowed-domains list, add localhost while testing. with the snippet already inside.

If your site uses a Content-Security-Policy

Allow the widget with script-src https://agentpro.chat, connect-src https://agentpro.chat and style-src 'unsafe-inline' (the widget injects its styles inside a Shadow DOM).

Configuration

Only a handful of options live in the snippet. Everything else (welcome message, pre-chat form, widget size, business hours, themes, allowed domains) is managed in the dashboard and fetched by the widget at load time.

window.AgentProConfig

window.AgentProConfig = {
  apiKey: "cbp_YOUR_WIDGET_API_KEY", // required
  apiUrl: "https://agentpro.chat", // optional: defaults to the origin widget.js was loaded from
  position: "bottom-right",   // optional override: bottom-right | bottom-left | top-right | top-left
  primaryColor: "#283389",    // optional override: 6-digit hex (an active theme still wins)
  language: "en",             // optional override for the widget's UI language
  strings: { placeholder: "Ask us anything…" }, // optional: override any UI text
  requireConsent: false       // true = store nothing and send nothing until AgentProWidget.grantConsent()
};

Options

OptionTypeDefaultDescription
apiKeystringrequiredThe agent's widget API key (cbp_...). Shown in the Embed Code tab.
apiUrlstringorigin of widget.jsBase URL of the AgentPro API (https://agentpro.chat). Needed inside tag managers, otherwise the widget infers it from where widget.js was loaded.
positionstringagent settingbottom-right, bottom-left, top-right or top-left.
primaryColorstringagent setting6-digit hex colour for the launcher, header and buttons. An active widget theme can override the rest of the palette.
stringsobjectbuilt-inOverride any UI text (placeholder, start, before, handoff, offline, …). The widget ships translations for the 13 languages offered in the agent settings.
requireConsentbooleanfalseGDPR mode: nothing is stored in the browser and no request is made until your cookie banner calls AgentProWidget.grantConsent().
languagestringagent settingBCP-47 tag. Sets the widget's UI language (placeholder, buttons, system messages) and the lang attribute for screen readers.

JavaScript API

After the script loads it exposes window.AgentProWidget so you can wire the chat to your own buttons and identify logged-in users.

window.AgentProWidget

// Available once widget.js has loaded (listen for the "agentpro:ready" event)
document.addEventListener('agentpro:ready', function () {
  // Open, close or toggle the chat window
  AgentProWidget.open();
  AgentProWidget.close();
  AgentProWidget.toggle();

  // Send a message on the visitor's behalf (opens the window first)
  AgentProWidget.sendMessage('I would like to know more about pricing');

  // Identify the visitor (skips the pre-chat form, shown in the inbox)
  AgentProWidget.setVisitor({
    name: 'Jane Doe',
    email: 'jane@example.com',
    phone: '+1 555 0100'
  });

  // When your user signs out: forget the conversation and the visitor in this browser,
  // so the next person at the same computer starts clean. (shutdown() is an alias.)
  AgentProWidget.reset();

  // Which build of the widget is running (useful when contacting support)
  console.log(AgentProWidget.version);
});

// With requireConsent: true, call this from your cookie banner's "Accept" handler.
// Until then the widget stores nothing in the browser and sends nothing to AgentPro.
AgentProWidget.grantConsent();

// window.ChatBotProWidget is an alias of window.AgentProWidget

Conversation memory and shared computers

The widget remembers its conversation in the visitor's browser, so they pick up where they left off as they move between pages. History is only ever served back to the browser that holds the conversation's secret; nobody can read it from another device.

  • A conversation ends once your team resolves it, or after the quiet period set under Settings → Widget → Remember the conversation for (24 hours by default). The next message starts a new conversation with the visitor's details carried over, and the old one stays in your inbox.
  • Visitors can start over at any time from the icon in the widget header.
  • Call AgentProWidget.reset() when a user signs out of your site. Passing a different userId or email to setVisitor() also starts a fresh conversation, so two people sharing a browser never see each other's chat.

Allowed domains

Because the API key is visible in your page source, restrict where it can be used. In the agent's Settings → Widget Appearance → Allowed domains enter a comma-separated list such asexample.com, app.example.com.

  • Leave the list empty to allow every website (useful while testing).
  • An entry matches itself and all of its subdomains: example.com also allows www.example.com. Protocols, ports, paths and *. prefixes are ignored.
  • Requests from any other origin receive HTTP 403 and the launcher button is hidden on that site.
  • Add localhost if you need to test on a local dev server.

What you get

Appearance

  • Widget themes: colours, fonts, radius, logo, company name, custom CSS
  • Small, medium or large window; full-screen on phones
  • Rendered in a Shadow DOM so your site's CSS never clashes
  • Optional "Powered by AgentPro" footer

Behaviour

  • Conversations persist across page loads for the same visitor
  • Human handoff: agent replies from the Inbox appear in the widget
  • Pre-chat form for name, email and phone (configurable)
  • Business hours with an offline greeting, knowledge-base source links, keyboard accessible
  • Offline banner and automatic back-off when the visitor loses connectivity
  • Optional privacy-policy link under the pre-chat form and consent-gated mode

Troubleshooting

Launcher button not appearing?

  • • The agent must be Active. Inactive agents return 403 and the widget hides itself.
  • • Check the domain allow-list: the page's hostname must match an entry (or the list must be empty).
  • • Open the browser console: the widget logs a single [AgentPro] warning with the reason.
  • • Verify apiUrl is https://agentpro.chat and that /widget.js loads (HTTP 200).
  • • Still "Not detected yet" in the dashboard after loading your site? A caching plugin or CDN may be serving the old page; purge it and reload in a private window.
  • • Sites with a strict Content-Security-Policy need the script-src, connect-src and style-src entries listed in the platform section above.
  • • The snippet must be present only once per page; a second copy is ignored.

Chat opens but replies fail?

  • • "Too quickly" errors mean the per-agent rate limit (Settings → messages per minute) or the per-visitor limit was hit; the widget shows a Retry button.
  • • Make sure an AI model is configured and the organization has remaining usage.
  • • If an agent replied from the Inbox, AI answers pause for that conversation until the agent re-enables them.
  • • When the AI provider fails, visitors see the agent's fallback message with a quiet "Try again" link; the message is stored once, not duplicated.
  • • If your plan's conversation limit is reached, visitors see the offline message (never billing wording) and owners get a dashboard notification.

Next Steps