Web widget
The web widget puts a NuacemOne chat window, a voice call button, or both, on any website. It is one script tag. For setting it up in the console (publishing, designing the window, allowed websites), see Web widget. This page is the developer reference: attributes, the page API and events.
Add the script
Section titled “Add the script”<script src="https://studio.nuacem.dev/widget/nuacemone-widget.js" defer data-key="vcx_pk_xxxxxxxx" data-agent="agt_xxxx" data-gateway="https://api.nuacem.dev/voice-gw"></script>To reach a use case, use data-use-case="uc_xxxx" instead of data-agent. Copy the ready-made tag from the agent’s or use case’s Deploy section in the console.
Requirements:
- A publishable key whose allowed websites include your page’s origin. Never put a secret key in a page.
- The agent is published with Web chat and/or Web calls switched on. The widget shows chat, calls or both to match.
The window’s look comes from the chat window design you publish in the console. A new design reaches your site when you publish it, with no change to the tag.
Attributes
Section titled “Attributes”Required:
| Attribute | Value |
|---|---|
data-key |
Your publishable key. |
data-agent or data-use-case |
The agent or use case id. |
data-gateway |
https://api.nuacem.dev/voice-gw |
Optional, to override the published design on one page:
| Attribute | Value |
|---|---|
data-title |
The window’s title. |
data-color |
The main colour, as #RRGGBB. |
data-theme |
light or dark. |
data-position |
left or right. |
data-placeholder |
The message box hint. |
data-launcher-label |
Text beside the launcher button. |
data-teaser |
A short message beside the launcher. |
data-attachments |
false hides the file button, whatever the agent’s file setting. |
data-layout |
page makes the chat fill the page, with no launcher. |
data-open |
true opens the window when the page loads. |
data-language |
The chat’s language, for example hi. |
data-languages |
A language picker, for example en,hi,te. The first is the default. |
data-prechat |
A short form before the chat, for example name,email. Answers are stored with the chat. |
data-prechat-required |
Which form fields are required, for example name. |
data-prechat-intro |
The line above the form. |
data-user-id, data-user-hash |
Signed identify for a signed-in user. Compute the hash on your server; see Signed users. |
data-side-panel |
true shows the dock button that switches to a side panel; false hides the switch. |
data-view |
panel or popup: how the window first opens. A visitor’s own later choice wins in their browser. |
data-push-page |
true narrows the page to make room for the side panel. |
data-platform |
app inside a mobile app’s WebView. Shows the design’s Call us phone option, which websites never show. |
Control the widget from your page
Section titled “Control the widget from your page”The widget sets the global NuacemOneWidget. It is separate from the NuacemOne SDK global, so both can be on one page.
NuacemOneWidget.open();NuacemOneWidget.close();NuacemOneWidget.toggle();NuacemOneWidget.dock(); // side panelNuacemOneWidget.undock(); // pop-up windowNuacemOneWidget.setView('panel'); // or 'popup'NuacemOneWidget.getView(); // the current viewFor example, open the chat from your own button:
<button onclick="NuacemOneWidget.open()">Chat with us</button>Events
Section titled “Events”NuacemOneWidget.on('message', (m) => analytics.track('chat_message', { from: m.from }));| Event | Data |
|---|---|
open |
None. The window opened. |
close |
None. The window closed. |
message |
{ from, text }, where from is visitor or assistant. Sent when the visitor sends a message and when a reply is complete. |
call |
{ state: 'started' } when a voice call connects; { state: 'ended', reason } when it ends. |
view |
{ view } when the window switches between pop-up and side panel. |
Do not send message text to third-party analytics unless your privacy notice allows it.
Behaviour notes
Section titled “Behaviour notes”- The widget keeps the conversation in the visitor’s browser between pages, unless the design turns that off.
- The file button follows the agent’s file sharing setting (always, never, or only after the agent asks for a file).
- A voice call needs the visitor’s microphone. It ends when the visitor hangs up or closes the page, at your organisation’s maximum call length, or after a stretch of silence.
- The widget draws everything inside a Shadow DOM, so your page’s styles do not leak in, and all text is inserted as text, never HTML.
To build your own chat window instead, use the JavaScript SDK.
Pages that still embed the older vcx-chat.js or vcx-voice.js keep working; see Older names.