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.

Host page
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 use durationSec from GET /sessions/summary (active minutes).
  • milestone — none, first_concept_complete, first_try_yourself_success, recap_reached.
  • ended_reason — "time_limit" when the max_duration_minutes cap ended the session; the host's reason (finished, minutes_exhausted, no_input, idle, paused) when your page ended it with evelyn:host_end; absent on a plain End/Pause.
  • end_intent — finish or discard when the student chose; absent on a plain End/Pause.

All events

Session lifecycle

EventFires whendata
evelyn:session_startedThe student starts the sessionsession_id, started_at_ms?
evelyn:progressEvery lesson-segment changesession_id, lesson_progress { lessonPlanId, segments[], currentSegmentId, completedSegmentIds[], currentSegmentLabel?, percent? }, practice?
evelyn:session_endedThe 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_blockedThe 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:clockEvery 15 s while a session is open, and on every pause/resumeactive_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:activityA real student turn (typed or spoken), at most once per 5 slast_student_input_at_ms (top-level, not under data)

Layout

EventFires whendata
evelyn:expandThe tutor asks the host for more room—
evelyn:collapseThe 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.

Host page
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 set

iServer-side webhooks

Outbound webhook delivery to your server (for example 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.