Events

The callbacks the widget fires, and what to do with each.

Browser Embed key dev · https://api.dev.oprag.ai
CallbackPayloadFires when
onReadyThe widget is mounted and its configuration has loaded.
onOpenThe panel opens, whether by launcher or by open().
onCloseThe 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.
TypeScript
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