Events & persistence
Every moment of a tour is published as an event, including how long each step was on screen. Subscribe to
IBonboardingService.EventRaised for something quick, or register an IBonboardingObserver
in DI to forward the stream to your analytics provider.
Live event stream
Run the tour and watch the log. Each step's StepShown is followed by a StepLeft that says how
long it was on screen, and the first step carries Metadata - your own analytics dimensions, which ride
along on every event about it. Finish the tour, close it, skip it or press Escape, and compare the event it ends with.
Run it again after leaving it part way, and it starts with TourResumed. Preview it runs the
same tour with BonboardingStartOptions.Preview: every event is marked preview, and the saved
record below does not change.
What each event means
| Kind | When |
|---|---|
TourStarted |
A session started. |
TourResumed |
It resumed from saved progress rather than starting fresh. |
TourQueued |
A start found another tour running and waits for it; TourStarted follows when it really starts. |
StepShown |
A step is on screen. |
StepLeft |
A step that was on screen was left; Duration says for how long. Steps skipped before they were shown do not raise it. |
StepSkipped |
A step was skipped because its target was missing. |
TargetMissing |
A target could not be found, or disappeared mid-step. |
TargetResolved |
A target was found, including after a wait. |
ActionInvoked |
A custom footer action was pressed; Action says which. |
AdvanceBlocked |
CanAdvance held the user on the step. |
TourPaused |
PauseAsync was called. |
TourCompleted |
The tour ran to the end. |
TourSkipped |
The user skipped the rest. |
TourDismissed |
The user closed it. |
TourSnoozed |
The user asked to be reminded later; progress kept. |
TourCancelled |
Interrupted by the application, or replaced by another tour; progress kept. Also a queued start withdrawn before it ran. |
TourFailed |
A hook threw, or a Fail strategy fired; Error says why. |
Each event carries its Kind, the Session and its Tour, the Step and
StepIndex when it is about one, Duration on StepLeft (time on the step) and on
the tour's last event (time the whole tour took), ChangeReason on StepShown (how the user got
there: Start, Next, Previous, Jump...), TargetIssue on
TargetMissing (NotFound, Hidden or InvalidSelector), the
Action on ActionInvoked, the Reason on a tour's last event, the Error on
TourFailed, IsPreview for a preview's events, and a Timestamp from the registered
TimeProvider.
Worth measuring:
- Completion rate per tour:
TourCompletedoverTourStarted, ignoringTourCancelled. - Drop-off by step: the last
StepShownbefore aTourDismissedorTourSkipped- the step not worth the interruption. - Time per step, from
StepLeft.Duration: a step left in under a second was not read. - Time to complete, from
TourCompleted.Duration, and time to drop off fromTourDismissed.Duration. - How people move, from
StepShown.ChangeReason: manyPreviouson a step means the one before it was unclear. TargetMissingcounts: a step whose target keeps going missing points at something that has moved or been renamed.AdvanceBlockedcounts: a step that holds people back a lot has instructions they find hard to follow.
Persistence
Progress is written to the registered IBonboardingStore after every step, and again when the tour ends.
That record is what makes "show this once", "resume where I left off" and "replay from the help menu" work. The
default store uses localStorage with an in-memory mirror, so reads still work while prerendering and in
private browsing, and corrupt data is treated as "never seen". Run the tour above, then read what the store kept of it.
Run the tour above, then read what the store kept of it.
Completion is sticky: Completed says the user ran the tour to the end at some point, so
replaying a finished tour does not un-finish it, however the replay ends. How a run ends decides what happens next:
| Ending | Completed | Dismissed | Offered again by StartOnceAsync |
|---|---|---|---|
CompleteAsync (the Done button) | yes | no | no |
SkipAsync (the Skip button) | no | yes | no |
DismissAsync (close, Escape) | no | yes | no |
CancelAsync (interrupted) | no | no | yes |
SnoozeAsync (remind me later) | no | no | after the snooze |
| Failed | no | no | yes |
A finished or dismissed tour that is started again on purpose starts from the top; anything else resumes at its saved step id (or index, if the step is gone). The lifecycle page drives each ending live.
Wiring it up
An observer receives every event of every tour, and is registered once in DI; any number can be. An observer that
throws is logged and the tour carries on - analytics being down is never a reason for onboarding to break. For
something local, such as the log on this page, subscribe to IBonboardingService.EventRaised; for logic
that belongs to one tour, use its own callbacks (OnStarted, OnStepChanged,
OnEnded), shown on the lifecycle page.
public sealed class TourAnalytics(IAnalyticsClient client) : IBonboardingObserver
{
public ValueTask OnEventAsync(BonboardingEvent e, CancellationToken ct = default)
{
return e.Kind switch
{
BonboardingEventKind.StepShown =>
client.TrackAsync("tour_step_shown", new
{
tour = e.Tour.Id,
step = e.Step?.Id,
position = e.StepIndex,
}),
BonboardingEventKind.StepLeft =>
client.TrackAsync("tour_step_left", new
{
step = e.Step?.Id,
ms = e.Duration?.TotalMilliseconds,
}),
BonboardingEventKind.TourCompleted or BonboardingEventKind.TourSkipped =>
client.TrackAsync("tour_ended", new { tour = e.Tour.Id, reason = e.Reason }),
_ => ValueTask.CompletedTask,
};
}
}
builder.Services.AddBitBonboardingObserver<TourAnalytics>();Where progress lives
- Two tabs: the default store listens to the browser's
storageevent, so what one tab writes, the others pick up - a checklist ticks off in every tab, a tour list updates, and a tour completed or dismissed in one tab stops in the others. Open the guidance page in two tabs to see it. - Several people on one device:
StorageScopesays whose progress it is, so every key carries the signed-in user and one person's finished tours never hide them from the next. - One visit only:
StorageLocation = Sessionkeeps progress insessionStorage, soStartOnceAsyncmeans once per visit.AddBitBonboardingInMemoryStore()keeps it in memory. - Nowhere:
Persist = falseon a tour, as this site's playgrounds do, or globally. - On the server: an
IBonboardingStoreof your own follows the user across devices; one that also implementsIBonboardingStoreEventscan push changes made elsewhere. - After an edit: bump the tour's
Versionand a record written by the old one is discarded, soStartOnceAsyncoffers the new tour again - or give itMigrateRecordto keep the old progress, mapping renamed step ids.
builder.Services.AddBitBonboardingServices(options =>
{
options.StorageKeyPrefix = "acme:onboarding:"; // default "bit-bonboarding:"
options.StorageLocation = BonboardingStorageLocation.Session; // default Local
options.StorageScope = async (services, ct) => // whose progress it is; null for the device
(await services.GetRequiredService<AuthenticationStateProvider>().GetAuthenticationStateAsync())
.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
options.Persist = false; // or nowhere at all
});
// A version bump discards old progress - unless it is migrated:
new BonboardingTourDefinition
{
Id = "welcome",
Version = 3,
MigrateRecord = record => record.Version == 2
? record with { CurrentStepId = record.CurrentStepId == "plans" ? "pricing" : record.CurrentStepId }
: null, // null discards it after all
}
await BonboardingService.IsCompletedAsync("welcome"); // ran to the end at some point
await BonboardingService.IsClosedAsync("welcome"); // completed, skipped or dismissed
await BonboardingService.ResetAsync("welcome"); // forget one tour
await BonboardingService.ResetAllAsync(); // forget every tour and every checklistA custom store
Progress can live wherever your users' other data does - a profile, a table, a document. The store is resolved as a
scoped service, so injecting the current user is fine; a store that throws is logged rather than allowed to break the
tour, and a checklist's progress is a record in the same store, under checklist:{id}.
public sealed class ProfileOnboardingStore(IUserProfiles profiles) : IBonboardingStore
{
public ValueTask<BonboardingRecord?> GetAsync(string tourId, CancellationToken ct = default)
=> profiles.GetOnboardingAsync(tourId, ct);
public ValueTask SetAsync(BonboardingRecord record, CancellationToken ct = default)
=> profiles.SaveOnboardingAsync(record, ct);
public ValueTask RemoveAsync(string tourId, CancellationToken ct = default)
=> profiles.DeleteOnboardingAsync(tourId, ct);
public ValueTask ClearAsync(CancellationToken ct = default)
=> profiles.DeleteAllOnboardingAsync(ct);
}
builder.Services.AddBitBonboardingServices();
builder.Services.AddBitBonboardingStore<ProfileOnboardingStore>();