SPA Integration Guide
Learn how to integrate Fanfare into a single-page application (SPA) using React, Vue, or Angular.Overview
This guide walks you through integrating the Fanfare SDK into a client-side rendered single-page application. By the end, you’ll have a working queue experience that manages high-demand product access. What you’ll learn:- Installing and configuring the Fanfare SDK
- Setting up the React provider
- Managing authentication
- Implementing the experience journey flow
- Handling queue states and admission
Prerequisites
Before starting, ensure you have:- A Fanfare account with API credentials
- A React 18+ application (or Vue/Angular equivalent)
- Node.js 18+ installed
- Basic understanding of React hooks
Step 1: Install the SDK
Install the Fanfare React SDK and its peer dependencies:Step 2: Configure the Provider
Wrap your application with theFanfareProvider to make the SDK available throughout your component tree.
Provider Options
| Option | Type | Default | Description |
|---|---|---|---|
organizationId | string | Required | Your Fanfare organization ID |
publishableKey | string | Required | Your publishable API key |
environment | "production" | "staging" | "development" | "production" | API environment |
autoRestore | boolean | true | Restore session on mount |
autoResume | boolean | true | Resume operations after restore |
loadingComponent | ReactNode | null | Component shown while initializing |
locale | string | "en" | Locale for translations |
Step 3: Authenticate the Consumer
Before a consumer can participate in an experience, they need to authenticate. Fanfare supports both anonymous (guest) and identified authentication.Using the Auth Hook
Step 4: Create the Experience Journey
Use theuseExperienceJourney hook to manage the complete flow from entering an experience to admission.
Step 5: Handle Journey States
The journey progresses through several states. Handle each appropriately:Step 6: Implement Journey Actions
Allow consumers to interact with the journey based on available actions:Step 7: Display Queue Position
When participating in a queue, show the consumer their position:Step 8: Handle Admission
When a consumer is admitted, redirect them to checkout or show purchase options:Complete Example
Here’s a complete, minimal implementation:Testing Your Integration
- Local testing: Use
environment="development"to connect to localhost:4802 - Check authentication: Verify the consumer session is created
- Test queue flow: Enter the queue and verify position updates
- Verify admission: Confirm admission tokens are generated correctly
Troubleshooting
SDK doesn’t initialize
- Check that
organizationIdandpublishableKeyare correct - Ensure the provider wraps your component tree
- Check browser console for error messages
Authentication fails
- Verify API credentials in the Fanfare dashboard
- Check network requests for error responses
- Ensure cookies are enabled for session storage
Queue position doesn’t update
- Verify polling is started with
startPolling() - Check that the queue ID matches
- Ensure event listeners are subscribed
Admission token issues
- Tokens expire after 10 minutes by default
- Verify the token hasn’t been used already
- Check device fingerprint matches
What’s Next
- Anonymous Consumers - Guest authentication patterns
- Checkout Integration - Connect to checkout
- Product Launch - Full product launch example
- Real-time Updates - Live UI patterns