BridgeDocsOpen Bridge

JavaScript API

Everything is on window.Bridge once the widget script has loaded. Before that, queue calls with push.

Methods

identify(data)Tell Bridge who the visitor is: email, name, phone, company, plus any custom attribute. See Identify your visitors.
send(text)Post a message into the chat as the visitor (for example the content of your own contact form).
open() / close() / toggle()Open or close the chat window.
show() / hide()Show or hide the whole widget on the current page.
setOffset({ bottom, side })Move the chat button away from the bottom and side edges, in pixels. { bottom: 0 } restores the default.
setConsent(boolean)false stops recording pages and clicks for this visitor. The chat keeps working.
reset()Forget the visitor (on sign-out). The next visit starts as a new anonymous visitor.
on(event, callback) / off(event, callback)Listen to widget events (below).
push([method, ...args])Queue a call before the script has loaded: window.Bridge = window.Bridge || []; Bridge.push(["identify", {...}]).

Properties

isOpentrue while the chat window is open.
contact{ id, email, name } for the current visitor, or null until the widget has loaded.

Events

readyThe widget has loaded.
open / closeThe visitor opened or closed the chat.
message:sentThe visitor sent a message. Data: { id, text, from, at, via }, where via is "widget" (typed in the chat) or "api" (Bridge.send).
message:receivedA reply or automated message arrived while the page was open. Data: { id, text, from, at }, where from is "operator" or "automation".

Example: count chats in your analytics, only for messages typed by visitors.

js
window.Bridge = window.Bridge || [];
window.Bridge.push(["on", "message:sent", (message) => {
  if (message.via === "widget") analytics.track("chat_message_sent");
}]);

Script attributes and URL parameters

data-bridge-keyOn the script tag: your website key (required).
data-bridge-trackOn any button or link: the name Bridge records for clicks on it.
?bridge_open=1In a page URL: opens the chat on load.
?bridge_preview=IDIn a page URL: shows an automation's message right away, to preview it (nothing is recorded).