Widget

A chat bubble on your website.

The Widget adds a chat bubble to your website. Customers click it to open a conversation with your AI Agent. Texts, design, availability and display conditions come from your Configuration. You can override some of them in code and control the Widget with a JavaScript API.

Before you start

  1. Save your Conversation SDK configuration.
  2. In Automate → Channels, turn on Widget on the Conversation SDK card.

If the Widget is turned off on the card, the snippet loads nothing.

Install the Widget

JavaScript snippet

  1. On the Conversation SDK card, click Snippet next to Widget.
  2. Copy the code and paste it before the closing </body> tag on every page where the Widget should appear.

The snippet looks like this. Always copy yours from the card, because the script address depends on your account:

<script type="text/javascript">
  (function(cb) {
    var js = document.createElement("script");
    if (js.readyState) {js.onreadystatechange = function() {if (js.readyState === "loaded" || js.readyState === "complete") {js.onreadystatechange = null; cb();}};
    } else {js.onload = function(){cb();};}
    js.type = "module";
    js.defer = true;
    js.src = "https://<your-chat-host>/zowie-widget-entry.js";
    document.body.appendChild(js);
  })(function() {
    ZowieWidget.init("<your-instance-id>", {});
  });
</script>

Google Tag Manager

  1. In Google Tag Manager, create a new tag of type Custom HTML.
  2. Paste the snippet from the card.
  3. Set the trigger to All Pages, or to the pages where the Widget should appear.
  4. Save the tag and publish the container.

Customize the Widget in code

The second argument of ZowieWidget.init is a configuration object. Values you pass there take priority over the values from your configuration in Zowie.

ZowieWidget.init("<your-instance-id>", {
  primaryColor: "#2563EB",
  theme: "system",
  metadata: {
    firstName: "Ada",
    email: "[email protected]",
  },
  onStartChat: (conversationId) => {
    console.log("Conversation started", conversationId);
  },
});

Call init once per page. Later calls are ignored.

Init options

Behavior

OptionTypeDefaultDescription
showOnLoadbooleantrueShow the Widget when the page loads. Set to false to keep it hidden until you call show().
positionPositionOffsetsFrom configurationDistance of the chat button from the edge of the screen, separately for desktop and mobile.
resetSessionbooleanfalseDiscard the stored conversation and start a new one.
versionType"PRODUCTION" | "STAGING""PRODUCTION"Run conversations against the published or the staging version of your AI Agent. Use "STAGING" to test changes before you publish them. Never use it on your live website.
contextstringNoneID of a context set up by your TAM. It routes the conversation to the AI Agent assigned to that context.

Customer data and authentication

OptionTypeDescription
metadataMetadataCustomer details: name, email, phone number, locale and your own attributes. See Customer data.
externalAccessTokenstringJWT that identifies a logged-in customer. See Authentication.

Branding

OptionTypeDescription
titlestringTitle in the chat header.
logoUrlstringURL of the logo in the chat header.
primaryColorstringPrimary color, used in both light and dark theme.
ctaColorstringColor of the chat button, used in both light and dark theme.
fontColor"white" | "black"Text color on top of the primary color.
userMessageBackgroundColorstringBackground color of the customer's messages.
userMessageFontColor"white" | "black"Text color of the customer's messages.
theme"system" | "light" | "dark"Color theme. "system" follows the customer's device settings.
fontUrls{ regular?: string, medium?: string }URLs of font files to use instead of the default font. regular is used for normal text, medium for emphasized text.
avatarImageUrls{ aiAgent?: string, humanAgent?: string }URLs of avatar images shown next to messages from the AI Agent and from human agents.
ctaImageUrls{ open?: string, close?: string }URLs of custom images for the chat button. open is shown on the button that opens the chat, close on the button that closes it.

Hello (voice)

OptionTypeDefaultDescription
voiceExperienceEnabledbooleanFrom configurationTurn Hello on or off on this website. Hello must first be enabled for your account. Consult your TAM before you turn it on.
voiceBlobColorstringFrom configurationColor of the voice animation.
chatButtonsOrder"text-voice" | "voice-text""text-voice"Order of the text and voice buttons when Hello is on.

Callbacks

Pass these functions in the configuration object to react to what happens in the Widget.

CallbackArgumentsCalled when
onLoadedNoneThe Widget has loaded.
onShowNoneThe Widget became visible.
onHideNoneThe Widget was hidden.
onOpenNoneThe chat window was opened.
onCloseNoneThe chat window was closed.
onStartChatconversationId: stringA conversation started.
onEndChatNoneThe conversation ended.
onSessionExpiredNoneThe conversation session expired.
onMessageSentmessage: stringThe customer sent a message.
onMessageReceivedmessage: objectA message arrived in the conversation.
onLinkClickedurl: stringThe customer clicked a link in the conversation. When you set this callback, the Widget doesn't open links itself. Your function decides what to do with the URL.
onAiSessionNoticeMoreClickheader: string, message: stringThe customer clicked More in the AI session notice. When you set this callback, it replaces the default behavior.
onCtaDisabledreferral: stringThe customer closed the call-to-action prompt.
onProactiveChatSeenreferral: stringA proactive chat was shown.
onProactiveChatClickedreferral: stringThe customer clicked a proactive chat.

Options, callbacks and methods for online stores are described in E-commerce.

Control the Widget

After the Widget has loaded, you can control it through the global ZowieWidget object. Calls made before the Widget has loaded are ignored, so call these methods from onLoaded or later. The exception is on(), which you can call at any time.

ZowieWidget.init("<your-instance-id>", {
  onLoaded: () => {
    document.querySelector("#help-button").addEventListener("click", () => {
      ZowieWidget.startChat();
    });
  },
});
MethodDescription
startChat(referral?, initialUserMessage?, options?)Start a conversation and open the chat. referral starts a specific scenario, initialUserMessage is sent as the customer's first message. Pass { conversationMode: "voice" } in options to start in Hello when it is on. Does nothing when the Widget isn't available, and doesn't open the chat when a conversation is already in progress.
open()Open the chat window. Starts a conversation if there isn't one yet.
close()Close the chat window. The chat button stays visible.
show()Show the Widget, including the chat button.
hide()Hide the Widget, including the chat button.
endChat()End the conversation and clear the stored session. Use it when the customer logs out.
isAvailable()Return true when your availability schedule and display conditions allow the Widget on this page.
getConversationId()Return the ID of the current conversation, or undefined when there is none.
sendMessage(message)Send a message as the customer.
sendReferral(referralId)Send a referral to the conversation to trigger a specific scenario.
updateMetadata(metadata)Update the customer details. See Customer data.
setExternalAccessTokenCallback(callback)Provide the JWT on demand, when the customer starts a conversation. See Authentication.
updatePosition(offsets?)Move the chat button. Pass PositionOffsets; values you leave out keep their current setting. Call it without arguments to go back to the position from your configuration.
showCTA(config)Show your own call-to-action prompt next to the chat button. See ShowCTAConfig.
hideCTA()Hide the prompt shown with showCTA().
getCta()Return the call-to-action prompts currently set for desktop and mobile, or undefined when there are none.
showCSAT(options?)Show the satisfaction survey in the current conversation. options.onCompleted is called when the customer submits or closes it. Does nothing when no conversation has started.
on(eventName, handler)Listen for a custom event sent by your processes. See Custom events.

Types

PositionOffsets

All values are in pixels.

FieldTypeDescription
desktopBottomOffsetPxnumberDistance from the bottom edge on desktop.
desktopHorizontalOffsetPxnumberDistance from the side edge on desktop.
mobileBottomOffsetPxnumberDistance from the bottom edge on mobile.
mobileHorizontalOffsetPxnumberDistance from the side edge on mobile.

ShowCTAConfig

FieldTypeDescription
desktop.headerstringPrompt header on desktop.
desktop.textstringPrompt text on desktop.
desktop.displayMode"always" | "hover"Show the prompt all the time, or only when the customer hovers over the chat button.
mobile.linesstring[]Prompt lines on mobile.
mobile.position"top" | "bottom"Where the prompt appears on mobile.

Both desktop and mobile are optional. Pass only the one you need.


Did this page help you?