Events
The callbacks the widget fires, and what to do with each.
| Callback | Payload | Fires when |
|---|---|---|
onReady | — | The widget is mounted and its configuration has loaded. |
onOpen | — | The panel opens, whether by launcher or by open(). |
onClose | — | The panel closes. |
onLead | { leadId, projectId } | A visitor submits the lead form. |
onEscalate | { conversationId, projectId } | A visitor asks for a human and a ticket is created. |
onError | { status?, message, code? } | A request fails. code is derived from the status client-side. |
await mountWidget({
projectId: "proj_abc123",
embedKey: import.meta.env.PUBLIC_OPRAG_EMBED_KEY,
apiUrl: "https://api.dev.oprag.ai",
onReady: () => analytics.track("oprag_ready"),
onOpen: () => analytics.track("oprag_opened"),
onLead: ({ leadId }) => analytics.track("oprag_lead", { leadId }),
onEscalate: ({ conversationId }) => analytics.track("oprag_escalated", { conversationId }),
onError: ({ status, code, message }) => {
if (code === "rate_limit") return showBusyNotice();
reportError(new Error(message), { status, code });
},
}); Ready to ship?
Get started free