Callbacks
Tourista provides callback functions that allow you to hook into tour lifecycle events and track user interactions. These callbacks are useful for analytics, logging, and triggering side effects based on tour progress.
Available Callbacks
The TourMachine component accepts the following callback props:
onStart
Triggered when a tour begins.
<TourMachine
onStart={(tourId) => {
console.log(`Tour ${tourId} started`);
}}
/>Parameters:
tourId: string- The ID of the tour that started
Use cases:
Track tour engagement in analytics
Initialize tour-specific resources
Update UI state
onStepChange
Called whenever the tour progresses to a different step.
Parameters:
stepIndex: number- The index of the current step (0-based)stepId: string- The ID of the current steptourId: string- The ID of the active tour
Important notes:
Only triggered when the step index actually changes
Not called for async sub-state transitions (pending โ processing โ success)
Not called during navigation states
onComplete
Fired when a tour completes successfully.
Parameters:
tourId: string- The ID of the completed tour
Use cases:
Mark user as onboarded
Unlock features
Send completion analytics
onSkip
Called when a user skips or exits the tour.
Parameters:
stepIndex: number- The step index where the tour was skippedstepId: string- The ID of the step where skipping occurredtourId: string- The ID of the skipped tour
Triggers:
User clicks skip button
User presses Escape key
User clicks outside the tour (if
closeOnClickOutsideis true)Browser back button is pressed
Complete Example
Here's how to use all callbacks together:
Analytics Integration
A common pattern is to integrate callbacks with your analytics service:
Conditional Logic
Use callbacks to implement conditional behavior:
Debugging
Use callbacks for debugging during development:
Important Notes
Callback execution order: Callbacks are called after the state change has occurred
Performance: Keep callbacks lightweight to avoid impacting tour performance
Step changes only:
onStepChangeonly fires when moving between different steps, not for async sub-states
Last updated