Events
The embed posts events to your page as the session progresses. Your backend then pulls the authoritative facts from the API.
How events arrive
Every event is a window.parent.postMessage({ type, data }) from the iframe. Always check event.origin before trusting a message.
window.addEventListener('message', (event) => {
if (event.origin !== 'https://tutor.evelynlearning.com') return;
const msg = event.data;
if (!msg || typeof msg.type !== 'string' || !msg.type.startsWith('evelyn:')) return;
switch (msg.type) {
case 'evelyn:session_started': /* { session_id, started_at_ms? } */ break;
case 'evelyn:progress': /* { session_id, lesson_progress, practice? } */ break;
case 'evelyn:activity': /* msg.last_student_input_at_ms (top-level; ≤ 1 per 5 s) */ break;
case 'evelyn:session_ended':
fetch('/api/tutor-session-ended', { // your endpoint
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(msg.data),
});
break;
}
});Payload: session_ended
{
"type": "evelyn:session_ended",
"data": {
"session_id": "sess-9012",
"duration": 1847,
"message_count": 24,
"whiteboard_items": 8,
"milestone": "recap_reached",
"lesson_progress": {
"lessonPlanId": "plan_8f3a…",
"currentSegmentId": "seg-recap",
"completedSegmentIds": ["seg-hook", "seg-concept-1", "seg-example-1", "seg-try-1"],
"currentSegmentLabel": "Recap",
"percent": 100
},
"end_intent": "finish"
}
}duration— total active seconds across the session, including earlier sittings of a resumed session. For billing usedurationSecfromGET /sessions/summary(active minutes).milestone—none,first_concept_complete,first_try_yourself_success,recap_reached.ended_reason—"time_limit"when themax_duration_minutescap ended the session; the host's reason (finished,minutes_exhausted,no_input,idle,paused) when your page ended it withevelyn:host_end; absent on a plain End/Pause.end_intent—finishordiscardwhen the student chose; absent on a plain End/Pause.
All events
Session lifecycle
| Event | Fires when | data |
|---|---|---|
evelyn:session_started | The student starts the session | session_id, started_at_ms? |
evelyn:progress | Every lesson-segment change | session_id, lesson_progress { lessonPlanId, segments[], currentSegmentId, completedSegmentIds[], currentSegmentLabel?, percent? }, practice? |
evelyn:session_ended | The student ends the session, the time cap ends it, or the host asks it to end (evelyn:host_end) | session_id, duration (total active seconds across the session, including earlier sittings of a resumed session), message_count, whiteboard_items, milestone, lesson_progress?, ended_reason? ("time_limit" | "finished" | "minutes_exhausted" | "no_input" | "idle" | "paused"), end_intent? ("finish" | "discard") |
evelyn:start_blocked | The start could not happen: the browser blocked audio autoplay, the token had expired, or the partner's tutoring minute pool is used up (show your "minutes used up" state and hide the start button) | reason ("autoplay" | "token_expired" | "minutes_exhausted") |
evelyn:clock | Every 15 s while a session is open, and on every pause/resume | active_seconds, running, max_seconds? (the effective cap for this session: the token's max_duration_minutes, or the partner pool's per-session cap, whichever is lower), pool_remaining_seconds? (partner-wide minutes left in the pool, refreshed every 30 s; absent when no pool applies) |
evelyn:activity | A real student turn (typed or spoken), at most once per 5 s | last_student_input_at_ms (top-level, not under data) |
Layout
| Event | Fires when | data |
|---|---|---|
evelyn:expand | The tutor asks the host for more room | — |
evelyn:collapse | The tutor releases the extra room | — |
Ending a session from your page
To end a session yourself (your own finish button, a usage ceiling, an inactivity timeout), post evelyn:host_end into the iframe rather than removing it. The tutor says a short goodbye, saves the session's progress, then posts evelyn:session_ended with ended_reason set to your reason. Wait a few seconds for it before unmounting. Only the first message counts, and it is ignored once the student has already ended the session.
iframe.contentWindow.postMessage(
{ type: 'evelyn:host_end', reason: 'finished' }, // 'finished' | 'minutes_exhausted' | 'no_input' | 'idle' | 'paused'
'https://tutor.evelynlearning.com',
);Then pull the facts
Events are signals, not the record. After session_ended your backend should call the signed API:
GET /api/portal/v1/sessions/summary?ids=sess-9012 # active minutes, turns, board items
GET /api/portal/v1/gaps?studentId=stu_abc123 # learning gaps
GET /api/portal/v1/mastery?studentId=stu_abc123 # mastery per objective
POST /api/portal/v1/assigned-practice # homework the tutor setiServer-side webhooks
session.ended pushed to a URL you register) is on the roadmap. Today the browser event plus an API pull is the supported pattern, and it is what our own platforms use.