Skip to content

Configuration

Full reference for all SDK initialisation options. Pass these as an object to Spotlight.init().

Initialisation

js
await Spotlight.init({
  apiKey: 'sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  // ... other options
});

If you load the SDK via a <script> tag with data-api-key, the apiKey is read automatically and init() is called for you with default settings. To customise options, call init() explicitly instead.

Options Reference

OptionTypeDefaultDescription
apiKeystringnullRequired. API key identifying your tenant. Read from the data-api-key script attribute if not provided.
baseUrlstring'https://api.example.com'Base URL of the Spotlight API. The hosted production endpoint is https://api.spotlight.help; override for self-hosted deployments. Trailing slashes are stripped.
tokenSource'cookie' | 'localStorage''cookie'Where to read the user's JWT auth token.
tokenKeystring'auth_token'Name of the cookie or localStorage key containing the JWT.
debugbooleanfalseEnable verbose console logging for content loading, events, and navigation.
autoStartbooleantrueAutomatically load and display content for the current page on init. Set to false to control content loading manually.
zIndexnumber999999Base z-index for the SDK's Shadow DOM host element.
overlaybooleantrueShow a backdrop overlay with cutout around the target element during tours.
allowKeyboardNavbooleantrueEnable keyboard navigation in tours (arrow keys, Enter, Escape).
closeOnOverlayClickbooleantrueDismiss the current tour or content when the user clicks the backdrop overlay.
closeOnEscapebooleantrueDismiss the current tour when the user presses the Escape key.
scrollBehavior'smooth' | 'auto' | 'instant''smooth'Scroll behaviour when bringing a target element into view.
paddingnumber8Padding (in pixels) around the target element's cutout in the overlay.
demoMode'admin' | 'user' | nullnullEnable demo mode for local development. Sends X-Spotlight-Demo-Mode header. The backend must have ALLOW_DEMO_AUTH=true set.
userIdstring | nullnullOverride user identification for demo or testing purposes. Sends X-Spotlight-Demo-User header.
tokensobject{}Personalisation tokens for content rendering (e.g. { user_name: 'Jane' }). Used by the backend's token renderer to substitute in tour content.

Minimal Configuration

The only required option is apiKey. Everything else has sensible defaults:

js
await Spotlight.init({
  apiKey: 'sk_live_xxxx',
});

Common Configurations

SPA with localStorage Auth

js
await Spotlight.init({
  apiKey: 'sk_live_xxxx',
  tokenSource: 'localStorage',
  tokenKey: 'access_token',
});

Self-Hosted with Debug

js
await Spotlight.init({
  apiKey: 'sk_live_xxxx',
  baseUrl: 'https://spotlight.yourcompany.com/api',
  debug: true,
});

Manual Content Loading

Disable auto-start and load content yourself when the page is ready:

js
await Spotlight.init({
  apiKey: 'sk_live_xxxx',
  autoStart: false,
});

// Later, when your page is ready:
await Spotlight.start('tour_onboarding_v1');

Personalisation Tokens

Pass user-specific tokens that are substituted into tour content at render time:

js
await Spotlight.init({
  apiKey: 'sk_live_xxxx',
  tokens: {
    user_name: 'Jane',
    company_name: 'Acme Corp',
    plan: 'Pro',
  },
});

In tour content, use and the backend renders it as Jane.

Development Demo Mode

For local development without a real JWT:

js
await Spotlight.init({
  apiKey: 'sk_live_xxxx',
  baseUrl: 'http://localhost:8000',
  demoMode: 'admin', // 'admin' or 'user'
  userId: 'dev-user-1',
  debug: true,
});

Demo mode is for development only

The backend only honours X-Spotlight-Demo-Mode when the ALLOW_DEMO_AUTH environment variable is set. This is never enabled in production.

Public API Methods

After initialisation, the SDK exposes these methods on the Spotlight global (or the default export if using ESM):

init(config)

Initialise the SDK. Can only be called once. Call destroy() first to re-initialise.

js
await Spotlight.init({ apiKey: 'sk_live_xxxx' });

start(tourId)

Start a specific tour by ID. Fetches content from the API and renders the tour if found:

js
await Spotlight.start('tour_onboarding_v1');

stop()

Stop the currently active tour without destroying the SDK. Content and hotspots remain available:

js
Spotlight.stop();

destroy()

Tear down the SDK completely. Removes all UI, cleans up event listeners, and flushes pending analytics:

js
Spotlight.destroy();

on(event, handler)

Subscribe to SDK lifecycle and analytics events. Returns an unsubscribe function:

js
const unsubscribe = Spotlight.on('tour:complete', (data) => {
  console.log('Tour completed:', data.tourId);
});

// Later:
unsubscribe();

Events

The SDK emits these events via the on() method:

EventPayloadDescription
sdk:init{ config }SDK successfully initialised
sdk:navigate{ path }SPA navigation detected
sdk:stop--Tour stopped via stop()
sdk:destroy--SDK destroyed
tour:complete{ tourId }User finished all steps in a tour
tour:dismiss{ tourId }User dismissed a tour before completion
content:dismiss{ contentId }User dismissed standalone content (tooltip, modal, banner)
analytics:event{ type, contentId, data }Any analytics event was tracked

Keyboard Shortcuts

When allowKeyboardNav is true and a tour is active:

KeyAction
ArrowRight / EnterAdvance to the next step
ArrowLeftGo back to the previous step
EscapeDismiss the tour (when closeOnEscape is true)

Theme Variables

The SDK's appearance is controlled by CSS custom properties set on the Shadow DOM host. These are configured per-tenant in the backend and applied at runtime. The full list of variables is documented in the Theming guide.

Key variables include:

VariableDefaultDescription
--spot-primary#4f46e5Primary brand colour
--spot-primary-hover#4338caHover state for primary colour
--spot-primary-text#ffffffText colour on primary backgrounds
--spot-bg#ffffffBackground colour for tooltips and modals
--spot-text#111827Main text colour
--spot-text-secondary#6b7280Secondary text colour
--spot-border#e5e7ebBorder colour
--spot-radius8pxBorder radius for components
--spot-font-familysystem-ui, -apple-system, sans-serifFont stack
--spot-overlay-bgrgba(0, 0, 0, 0.5)Backdrop overlay colour
--spot-hotspot-color#4f46e5Pulsing hotspot indicator colour
--spot-z-index999999Z-index for SDK elements

Spotlight