Skip to main content

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
Complexity: Beginner Time to complete: 30 minutes

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:
Or with other package managers:

Step 2: Configure the Provider

Wrap your application with the FanfareProvider to make the SDK available throughout your component tree.

Provider Options

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 the useExperienceJourney 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 the actions exposed by JourneyView:

Step 7: Display Queue Progress

When participating in a queue, the public journey view tells you the consumer is participating. If your UI needs live queue metrics such as position or wait estimates, read them from the participating sequence’s state$ display store rather than from the raw participation identity.

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

  1. Local testing: Use test credentials from the dashboard and keep SDK environment/API URL overrides unset
  2. Check authentication: Verify the consumer session is created
  3. Test queue flow: Enter the queue and verify position updates
  4. Verify admission: Confirm admission tokens are generated correctly

Troubleshooting

SDK doesn’t initialize

  • Check that organizationId and publishableKey are 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
  • Confirm the consumer is continuing from the active session

What’s Next