Skip to Content
📧 Join the Teacharium waitlist to get access. 

SDK Reference

SDK Options

The embedLesson() function accepts the following options:

OptionTypeRequiredDescription
containerHTMLElement | stringYesContainer element or CSS selector
tokenstringYesJWT token from sign-token endpoint (lessonId and versionId are automatically extracted)
baseUrlstringNoBase URL of your Teacharium instance (default: “https://www.teacharium.io ”)
widthstringNoIframe width (default: “100%“)
heightstringNoIframe height (default: “600px”)
classNamestringNoAdditional CSS classes for iframe
autoStartbooleanNoSkip the start button and begin the lesson immediately (default: false)
resumebooleanNoResume from where the learner left off (default: true). Set to false to always start fresh
onLoadfunctionNoCallback when lesson iframe loads
onCompletefunctionNoCallback when lesson completes
onProgressfunctionNoCallback for progress updates
onErrorfunctionNoCallback for errors
onEventfunctionNoCallback for all lesson events (recommended)

Event Handling

The onEvent callback receives every event from the lesson’s internal event system. This is the most flexible way to track lesson activity:

onEvent: (type, payload) => { console.log(`Event: ${type}`, payload); // Handle specific events if (type === "lesson_completed") { trackCompletion(payload); } };

Common event types include:

Event TypeDescription
playUser clicked the start button
lesson_startedLesson playback began
section_startedEntered a new section
step_startedEntered a new step
lesson_completedUser completed the lesson
variable_changedA lesson variable was updated

All events include a type field and a timestamp (ISO string).

Convenience Callbacks

The SDK also provides specific callbacks for common events:

onLoad

Fired when the lesson iframe has finished loading:

onLoad: () => { console.log("Lesson is ready to play"); // Hide loading indicator, etc. };

onComplete

Fired when the user completes the entire lesson:

onComplete: (data) => { console.log("Lesson completed!"); console.log("Lesson ID:", data.lessonId); console.log("Completed at:", data.completedAt); console.log("Total steps:", data.totalSteps); // Track completion in your system trackCompletion(data); };

onProgress

Fired when the user progresses through the lesson:

onProgress: (data) => { const percent = (data.currentStep / data.totalSteps) * 100; console.log(`Progress: ${percent.toFixed(1)}%`); // Update progress bar updateProgressBar(percent); };

onError

Fired when an error occurs:

onError: (error) => { console.error("Lesson error:", error.message); // Show error message to user showErrorNotification(error.message); };

API Reference

For detailed API documentation, see: