Basic Example

This guide demonstrates a complete, production-ready tour implementation.

Full Application Example

Project Structure

app/
├── layout.tsx          # Root layout with TourProvider
├── page.tsx            # Home page with tour triggers
├── dashboard/
│   └── page.tsx        # Dashboard page (multi-page tour)
└── components/
    ├── TourSetup.tsx  # Tour initialization and setup
    └── TourButtons.tsx # Tour control buttons

1. Tour Configuration

// app/components/tour-config.ts
import { TourConfig } from 'Tourista';

export const appTours: TourConfig[] = [
  {
    id: 'onboarding',
    steps: [
      {
        id: 'welcome',
        page: '/',
        targetElement: '#logo',
        title: 'Welcome to Our App',
        content: "Let's take a quick tour to get you started.",
        canSkip: true,
      },
      {
        id: 'navigation',
        page: '/',
        targetElement: '#main-nav',
        title: 'Navigation Menu',
        content: 'Access all features from here.',
        canPrev: true,
        canSkip: true,
      },
      {
        id: 'dashboard-redirect',
        page: '/',
        title: 'Going to Dashboard',
        content: "Let's check out your dashboard...",
        autoAdvance: 2000, // Auto-advance after 2 seconds
      },
      {
        id: 'dashboard-overview',
        page: '/dashboard',
        targetElement: '#stats-widget',
        title: 'Your Statistics',
        content: 'Track your progress and metrics here.',
        canPrev: false, // Disable back button for this step
      },
      {
        id: 'complete',
        page: '/dashboard',
        title: 'Tour Complete!',
        content: "You're all set. Enjoy using the app!",
        targetElement: '#user-profile',
      },
    ],
  },
  {
    id: 'feature-tour',
    steps: [
      {
        id: 'new-feature',
        page: '/dashboard',
        targetElement: '#new-feature',
        title: 'New Feature Alert!',
        content: 'Check out our latest addition.',
      },
    ],
  },
];

2. Tour Provider Setup

3. Root Layout Setup

4. Auto-Start Tour Logic (Optional)

If you want to automatically start the tour for new users, create a component:

5. Home Page Implementation

6. Dashboard Page

Hook Usage

useTourContext vs useTour

The library provides two hooks with different purposes:

useTourContext() - For managing tours:

  • Start a tour: startTour(tourId)

  • End the current tour: endTour()

  • Check if any tour is active: isActive

  • Get current tour config: tourConfig

useTour(tourId) - For controlling a specific active tour:

  • Requires a tourId parameter

  • Returns detailed state and controls for that specific tour

  • Access to step navigation: nextStep(), prevStep()

  • Send custom events: sendEvent()

  • Get current step data and progress

Advanced Patterns

Custom Tour Card

Async Step Example

Best Practices

  1. Check First-Time Users: Use localStorage or a database flag to determine if a user needs onboarding

  2. Provide Skip Options: Always allow users to exit tours

  3. Keep Steps Concise: Each step should focus on one feature or action

  4. Use Step Options: Configure canPrev and canSkip per step for fine control

  5. Test Element Selectors: Ensure target elements exist before tour activation

  6. Handle Page Transitions: For multi-page tours, ensure smooth transitions

  7. Visual Progress: Show progress indicators to help users understand tour length

Next Steps

Last updated