Callbacks & Events
onSuccess
Fired when a booking completes. The payload shape depends on the system type.
onSuccess fires once per successful booking. It's your hook for
redirects, analytics events, CRM syncing, and confirmation messages beyond
what the widget shows.
Signature
onSuccess?: (data?: any) => void;The payload shape depends on the booking system type — see below.
Payload shape by system type
SCHEDULED / SCHEDULED_WITH_PACKAGES
{
appointmentId: number;
}QMS
{
tokenNumber: string;
queuePosition: number;
estimatedWaitTime: number; // minutes
patientName: string;
appointmentDate: string; // YYYY-MM-DD
appointmentTime?: string; // HH:MM (approximate, if provided)
doctorName?: string;
locationName?: string;
bookingType: "TODAY" | "FUTURE";
}Modal auto-close
In modal mode, the widget auto-closes 3 seconds after onSuccess fires
so the patient sees the confirmation screen briefly. onClose fires after
the auto-close, exactly as if the user had dismissed it.
Common patterns
Redirect on success
MedosBooking.init({
apiKey: "mk_...",
onSuccess: (data) => {
window.location.href = `/booked?id=${data.appointmentId}`;
},
});Track a conversion event
MedosBooking.init({
apiKey: "mk_...",
onSuccess: (data) => {
window.dataLayer?.push({
event: "medos_booking_success",
appointmentId: data.appointmentId,
});
},
});See Analytics recipes for GA4, GTM, and Mixpanel patterns.
Handle both scheduled and QMS
MedosBooking.init({
apiKey: "mk_...",
onSuccess: (data) => {
if (data.tokenNumber) {
// QMS
alert(`Your token: ${data.tokenNumber}`);
} else {
// scheduled
alert(`Appointment booked: #${data.appointmentId}`);
}
},
});