Listen to chat events on your website
Subscribe to ready, open, close, message, reply, handoff, lead and error events from the Askocto embed with on() and off().
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
The embed script raises events as the chat is used. Listen to them to send analytics, show your own banner after a handoff or pass a captured lead to another script on the page. Use on to subscribe and off to stop.
Subscribe and unsubscribe
function onReply(event) {
console.log("Agent answered:", event.text)
}
window.askocto.on("reply", onReply)
// Later, when you no longer need it
window.askocto.off("reply", onReply)
Pass the same function to off that you passed to on. An anonymous function cannot be removed, so keep a reference when you plan to unsubscribe.
Events
| Event | Fires when | Payload |
|---|---|---|
ready |
The script has loaded and the agent is available. | None. |
open |
The chat window opens. | None. |
close |
The chat window closes. | None. |
message |
The visitor sends a message. | { id, text } |
reply |
The agent finishes an answer. | { id, text, sources } |
handoff |
The conversation passes to your team. | { conversationId } |
lead |
The agent captures a lead. | { conversationId, fields } |
error |
Something fails, such as a rejected identity. | { code, message } |
sources is a list of objects with an id and a title. fields holds the values the visitor gave, keyed by field name. The error codes are the same as in API error handling.
Examples
Send an analytics event when the chat opens and when a lead arrives:
const track = (name, data) => window.dataLayer?.push({ event: name, ...data })
window.askocto.on("open", () => track("support_chat_open"))
window.askocto.on("lead", (e) => track("support_lead", { conversationId: e.conversationId }))
Tell the visitor what happens after a handoff:
window.askocto.on("handoff", () => {
document.querySelector("#support-note").textContent =
"A teammate will reply here and by email."
})
You should see the handler run the next time the matching thing happens in the chat. Test it with the Playground for answers, and on your own page for events.
Note: Events describe what the visitor sees in the browser. For server-side processing, use webhooks, which send
conversation.handoffandlead.capturedto your backend.
Related pages
- Chat interface control covers the methods that change the window.
- Website integration overview lists every embed option.