Embed Events API

When embedding Supademo demos in your application via iframe, you can listen for events to track user progress and trigger actions in your parent application.

Overview

Supademo emits postMessage events to the parent window, allowing you to:

  • Detect when a demo starts, progresses, or completes

  • Track which slide the user is viewing

  • Close modals or trigger navigation when a demo finishes

  • Build custom progress indicators

Quick Start

Add this listener to your parent page:

window.addEventListener('message', (event) => {
  // Only handle Supademo events
  if (event.data?.source !== 'Supademo') return;

  console.log('Supademo event:', event.data.type, event.data.payload);
});

Available Events

Supademo:load

Fired when the demo initially loads in the iframe.

Payload:

Field
Type
Description

demoId

string

Unique demo identifier

title

string

Demo title

totalSlides

number

Total number of slides

Example:


Supademo:started

Fired when the user first interacts with the demo (clicks, navigates, etc.).

Payload:

Field
Type
Description

demoId

string

Unique demo identifier

title

string

Demo title

Example:


Supademo:slideChange

Fired whenever the user navigates to a different slide.

Payload:

Field
Type
Description

demoId

string

Unique demo identifier

currentSlide

number

Current slide number (1-indexed)

totalSlides

number

Total number of slides

isFirstSlide

boolean

true if on the first slide

isLastSlide

boolean

true if on the last slide

Example:


Supademo:progress

Fired alongside slideChange with a percentage value for building progress bars.

Payload:

Field
Type
Description

demoId

string

Unique demo identifier

percentage

number

Completion percentage (0-100)

currentSlide

number

Current slide number (1-indexed)

totalSlides

number

Total number of slides

Example:


Supademo:completed

Fired when the user reaches the final slide of the demo.

Payload:

Field
Type
Description

demoId

string

Unique demo identifier

title

string

Demo title

completedAt

string

ISO 8601 timestamp

Example:


Supademo:close

Fired when the user presses the ESC key while viewing the demo.

Payload: None

Example:

Common Use Cases

Close Modal on Demo Completion

Close Modal on ESC Key

Build a Custom Progress Bar

Track Demo Engagement

Show Slide Counter

Notes

  • Events are only emitted when the demo is embedded in an iframe

  • The percentage in Supademo:progress represents slides viewed (e.g., slide 3 of 5 = 60%)

  • Events are non-blocking and won't affect demo performance

Last updated

Was this helpful?