Celebrate the moment a milestone is earned
A learner finishes lesson five. “Five lessons completed” confirms what they earned. A quick victory hand from their character gives that moment a little personality.
Read the guideStart from the awarded event
Trigger a celebration after your application confirms the award. Opening an achievements screen, refreshing the page and scrolling an earned badge into view can all happen many times after that moment.
Give each award occurrence an event ID. Two milestones may use the same gesture, and two people may earn the same milestone. A unique event ID lets the presentation ignore a duplicate notification while still celebrating each new award.
Show the result before playing the gesture
The web example takes a mounted Clayfaces player and a visible status element. Create the callback once for the active view and pass newly awarded events to it. Use a status element with role="status" so the milestone text can also be announced. The text appears even when the user prefers reduced motion or a performance file is unavailable.
function celebrationHandler(avatar, status) {
const shown = new Set();
const reduced = matchMedia("(prefers-reduced-motion: reduce)");
return ({ eventID, label }) => {
if (shown.has(eventID)) return;
shown.add(eventID);
status.textContent = label;
if (!reduced.matches) avatar.play("victory_hand").catch(console.warn);
};
}
const celebrate = celebrationHandler(avatar, document.querySelector("#milestone"));
// Call from your app's successful award handler.
celebrate({ eventID: "lesson-five:maya:1", label: "Five lessons completed" });Decide what replay means
The set above covers duplicate deliveries for this mounted view. If your app delivers old events after a relaunch, use its persisted event cursor or recorded award IDs to identify newly earned milestones. Render earlier awards directly as history.
Try the same event ID twice, then a different ID. Only the two distinct awards should trigger a celebration. With reduced motion enabled, both results should still update their text. A separate Replay celebration button can call play again without awarding points a second time.