Embedding the Chatbot on Your Website
How to add your Zervice chatbot to any website in 60 seconds—supporting the 1-line Global Workspace Embed with Routing Rules, Signed-In Only identity tokens, direct single-bot embeds, and inline mounting.
Opening the "Connect to Website" Guide
Because a single Zervice workspace can run multiple assistants across different pages and audiences, connecting to your website is managed at the workspace level rather than inside an individual bot:
- In your Chatbot Workspace Console, click Connect to Website in the left navigation menu (under Integration) or click Connect Website in the top header bar.
- Choose your embed mode at the top of the guide:
- Global Workspace Embed (Recommended —
data-workspace-key): Install one tag across your entire website or app. Zervice automatically shows the right assistant—or hides the widget on specific paths like/auth—based on your Routing Rules, with zero code changes needed when you update rules later. - Pin a Specific Bot (
data-workspace-key+data-bot-id): Authenticates your workspace viadata-workspace-keywhile pinning a page strictly to one specific assistant (data-bot-id) inside your workspace.
- Global Workspace Embed (Recommended —
- Switch between the platform tabs (HTML / Any Site, Next.js / React, WordPress / Shopify / Webflow, Inline Page Mount, or Signed-In Users) and click Copy Snippet.
Option 1: Global Workspace Embed & Routing Rules (Recommended)
Paste your copied <script> tag just before the closing </body> tag of your website’s root layout.
Click Routing Rules in your Workspace Console header to control which assistant appears on each page and audience:
- Ordered Rules (Top-to-Bottom): Drag rules to reorder priority. Each rule matches an Audience (
Everyone,Visitors Only, orSigned-In Only) and a Page / Host Condition (All pages,Path starts with,Exact path,Path regex, orHost / subdomain) to either Show Bot or Hide Widget. - Default Fallback: Any page that does not match an earlier rule uses your Default fallback action at the bottom of the list.
- Test Saved Rules: Use the built-in route tester at the bottom of the Routing Rules modal to test any URL path as a
VisitororSigned Inuser and confirm which bot is selected.
Passing Verified Identity & Enabling Conversational Memory (ZerviceChatbot.identify)
For anonymous website visitors, Zervice maintains conversation context within their active browser session (ChatSessionDO), and intentionally never shares cross-session memory from unverified browser fields (email or userId) so one visitor can never spoof or view another customer's saved details.
To unlock Signed-In Only assistants and Cross-Session Conversational Memory across devices and future visits, have your backend sign a short-lived HS256 JWT using your Workspace Identity Signing Secret (zk_sec_..., found in Connect to Website → Signed-In Users (JWT) or Profile & Account):
JWT Claims Contract
| Claim | Requirement | Purpose |
|---|---|---|
sub | Required | Your user's stable, immutable account ID (for example, "usr_8492"). Zervice keys long-term conversational memory strictly by (workspace, sub), so memory remains intact even if the user later updates their email address. Tokens without sub are rejected. |
exp | Required | Standard Unix expiration timestamp (in seconds). Mint short-lived tokens (for example, 30m–1h). |
email | Optional | Verified email address—exposed as verified_user_email and pre-seeded into historical autofill hints. |
name | Optional | Verified display name—exposed as verified_user_name and pre-seeded into historical autofill hints. |
role | Optional | Exposed as verified_user_role for Condition steps in Dialog Flows. |
passthrough | Optional | Opaque credential forwarded transiently to authorized Business System Integrations (never logged or sent to AI prompts). |
Backend + Frontend Example
// 1. Backend: mint an HS256 JWT with your Workspace Signing Secret (never expose zk_sec_... in the browser)
import jwt from 'jsonwebtoken';
const token = jwt.sign(
{
sub: String(currentUser.id), // REQUIRED: stable user ID for Cross-Session Memory
email: currentUser.email,
name: currentUser.name,
role: currentUser.role
},
process.env.ZERVICE_SIGNING_SECRET,
{ algorithm: 'HS256', expiresIn: '30m' }
);
// 2. Frontend: identify the signed-in user (and clear on sign-out)
window.ZerviceChatbot.identify({ token });
// On sign-out:
window.ZerviceChatbot.logout();
What Signed-In Identity Unlocks Automatically
- Audience Routing & Access Guard: Routes authenticated users to Signed-In Only assistants and blocks unauthenticated API calls.
- Cross-Session Conversational Memory & 1-Click Autofill: Confirmed fields collected in prior sessions (such as name, work email, company, or team size) are remembered securely under
sub. When a Dialog Flow asks for one of those fields in a future session, the widget displays a non-blocking Saved value ([Use]) hint bar right above the message box—clicking Use confirms and advances in one click, while typing anything immediately dismisses the hint.
Option 2: Hiding a Single-Bot Bubble on Specific Pages
If you are using the This Bot Only (data-bot-id) snippet and do not want the floating chat bubble to appear on certain pages (such as checkout, login, or admin screens), add the data-exclude-paths attribute to your <script> tag with a comma-separated list of paths:
- Example:
data-exclude-paths="/checkout,/login,/admin/*"
Pages matching those paths will not render the floating launcher.
Option 3: Inline Page Embed
If you prefer the chat assistant to appear directly inside a Help Center page, support portal, or dashboard panel rather than as a floating corner bubble, Zervice supports inline mounting into a dedicated container on your page. Your web developer can call window.ZerviceChatbot.mount('#your-container', { workspaceKey: 'zk_pub_...', botId: 'default', inline: true }) to render the assistant inline while keeping the lookup strictly scoped to your workspace.
Quick Notes for Popular Website Platforms
- WordPress: Paste the snippet into your theme footer (
footer.php) or use a header/footer code-snippets plugin (such as WPCode) set to load in the footer. - Shopify: Open Online Store → Themes → Edit Code, open
theme.liquid, and paste the snippet right before</body>. - Webflow / Squarespace / Wix: Open Site Settings → Custom Code (Footer Code section), paste the snippet, and publish.
- Next.js / React: Add the script in your root layout using
next/scriptwithstrategy="lazyOnload".
Multi-Language & Locale Support
You only need to author your Knowledge Base, Dialog Flows, Hot Questions, and greetings once in a single canonical language. Zervice automatically detects each visitor’s language and adapts the widget interface, greetings, Quick Services, Dialog Flow prompts, quick replies, and AI answers seamlessly:
Automatic Detection (Zero Configuration)
By default, the widget resolves the active BCP-47 locale automatically in this order:
- Explicit site override (
setLocale(...),mount(..., { locale }), ordata-locale="..."). - Your website’s
<html lang="...">attribute (live-observed so Single-Page App language switches update the widget automatically). - The visitor’s browser language (
navigator.language). - Fallback to
'en', plus automatic detection if a visitor types in a non-Latin script such as Chinese, Japanese, or Korean.
Option A: Pin a Default Locale via Script Attribute (data-locale)
Add data-locale to the embed tag if a localized domain or sub-path always serves one language:
<script
src="https://chat.zervice.us/widget.js"
data-workspace-key="zk_pub_..."
data-locale="zh-CN"
async
></script>
Option B: Connect Your Website’s Language Switcher (ZerviceChatbot.setLocale)
When a user picks a language in your header menu or UI framework (such as i18next, Next.js i18n, or Vue I18n), sync the chatbot live:
// Switch the chatbot widget & upcoming turns dynamically to Simplified Chinese
window.ZerviceChatbot?.setLocale('zh-CN');
// Clear an explicit override to return to automatic <html lang> / browser detection
window.ZerviceChatbot?.setLocale('');
For inline mounts, you can also pass { locale: 'ja' } inside ZerviceChatbot.mount('#container', { ... }).
Verifying Allowed Website Domains
Before going live, open Bot & Widget Settings and confirm that your live website domain (for example, https://www.yourcompany.com) is listed in Allowed Website Domains (or leave the field blank during initial testing). Remember to include both www and non-www versions if visitors can access your site on both.