Quick Start Guide
Seamlessly integrate interactive Stories into your web and mobile applications in minutes. Choose your platform and launch engaging content with full analytics, targeting, and personalization.
Authentication & Token
Every SDK (Web, React, iOS) authenticates requests to Storyfyd using a dedicated application token that identifies your project and account.
Getting your application token
- Log in to the Storyfyd dashboard (storyfyd.io).
- Navigate to: Settings → SDK.
- Copy your application token and pass it to your init() or configure() method.
Security best practices
Never hardcode your application token directly in client-side bundles. Fetch it securely from your own backend at runtime.
User & Targeting (Audiences)
The user object passed on SDK initialization identifies the viewer and powers two key features: content targeting via tags (labels) and dynamic in-story personalization (custom).
Passing user data from the SDK
The id field is sent via the X-User-Id header. The remaining attributes (name, email, labels, custom) are JSON-serialized into a single X-User header. The exact same format applies across Web, React, and iOS SDKs.
Targeting with labels in the dashboard
- In the Storyfyd dashboard, go to Audiences and create a new Audience of type "Labels".
- Name it exactly as the label value sent in the SDK's labels array (e.g. label "vip" requires an Audience named "vip") — the match is exact.
- In Story Group settings, add an include or exclude rule referencing that Audience to show or hide content for viewers matching that label.
Example use case: language-targeted content (PL / EN)
Labels provide an effortless way to display different Story Groups based on user language or customer segment — without touching SDK code, configured entirely in the dashboard.
- On SDK init, pass labels based on the user's selected language, e.g. labels: ['lang_pl'] or labels: ['lang_en'].
- In Audiences, create two Labels-type Audiences: "lang_pl" and "lang_en".
- Create dedicated Story Groups for each language and assign the matching Audience as an include rule — Polish customers see Polish Stories, and English-speaking users see English Stories.
Custom properties & content personalization
Fields passed under custom (e.g. { plan: 'pro' }) do not affect Audience targeting — they are stored on the viewer's profile and used exclusively for resolving personalization tokens ({{plan}}) inside the story creator.
Where user data comes from
Storyfyd does not manage your end-user sessions — your own application knows who is currently logged in. Fetch their id, email, labels, and custom attributes from your auth/database layer and pass them to the SDK on initialization.
Web Component (Vanilla JS / HTML)
Embed interactive Stories into any website in 3 simple steps. Include the Storyfyd script, add the <storyfyd-web> component, and initialize with your token.
Full list of init() parameters
| Prop | Type | Required | Description |
|---|---|---|---|
| token | string | ✅ | Your Storyfyd API token. |
| user | object | ❌ | User object with id (required if provided) and optional custom attributes. |
| testMode | boolean | ❌ | Enables test mode, sending the X-Test-Mode: true header (default: false). |
| layout | object | ❌ | Widget layout and visual presentation configuration. |
| container | string | Element | ❌ | CSS selector or DOM element where the widget should render. |
| onReady | function | ❌ | Triggered when the widget is fully loaded and ready. |
| onStoryOpen | function | ❌ | Triggered when a story opens (receives story payload). |
| onStoryClosed | function | ❌ | Triggered when the fullscreen story viewer closes. |
| onStoryChanged | function | ❌ | Triggered when the currently displayed story slide or group changes. |
| onInteraction | function | ❌ | Triggered on element interaction (CTA clicks, poll answers, emoji reactions). |
| onError | function | ❌ | Triggered when an error occurs. |
| onNoStories | function | ❌ | Triggered when no active stories are available for this user. |
React SDK
First-class React component with full TypeScript definitions, custom hooks, and seamless integration into your React tree.
$npm install @storyfyd/sdk-reactComponent props for <StoryfydWidget />
| Prop | Type | Required | Description |
|---|---|---|---|
| token | string | ✅ | Your Storyfyd API token. |
| user | object | ❌ | User data object (requires id field). |
| layout | object | ❌ | Widget appearance and layout configuration. |
| className | string | ❌ | Additional CSS class names for styling. |
| style | object | ❌ | Inline CSS styles applied to the widget container. |
| onReady | function | ❌ | Callback triggered when the widget is ready. |
| onStoryOpen | function | ❌ | Callback triggered when a story opens. |
| onStoryClosed | function | ❌ | Callback triggered when the story viewer closes. |
| onStoryChanged | function | ❌ | Callback triggered when the story slide changes. |
| onInteraction | function | ❌ | Callback triggered on user interaction (reactions, polls, quizzes, CTA). |
| onError | function | ❌ | Callback triggered on error. |
useStoryfyd() hook — programmatic control
| Property | Type | Description |
|---|---|---|
| ref | RefObject | React ref to pass to the <storyfyd-web> element. |
| play | function | Resumes playing the current story. |
| pause | function | Pauses playback of the current story. |
| close | function | Programmatically closes the story viewer. |
| navigate | function | Navigates directly to a specific story: navigate(groupIndex, storyIndex). |
| destroy | function | Destroys and cleans up the widget instance. |
| isInitialized | boolean | Indicates whether the widget has already been initialized. |
iOS (Swift) SDK
Native SwiftUI library for iOS 17+, with full support for UIKit applications. Zero external dependencies — built strictly with Apple native APIs.
configure() parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| token | String | — | Application token generated in the Storyfyd dashboard. |
| testMode | Bool | false | Sends the X-Test-Mode: true header with requests for staging/testing. |
StoryfydConfiguration — visual styling
| Parameter | Type | Description |
|---|---|---|
| layout.view | .classic | .modern | .minimal | Visual layout style for story preview circles. |
| layout.width / height | CGFloat | Diameter of the story preview circle in points. |
| layout.titleColor | Color | Title text color below the circle. |
| layout.titleLineLimit | Int | Maximum number of lines for group titles. |
| showTitles | Bool | Whether to display group titles below preview circles. |
| unseenBorderColors | [Color] | Gradient border colors for unread stories. |
| seenBorderColor | Color | Border color for already-viewed stories. |
| storyDuration | TimeInterval | Default display duration for photo stories (seconds). |
| autoAdvance | Bool | Whether to automatically advance to the next slide. |
| pauseGesture | .hold | .tap | Gesture that pauses story playback (hold or tap). |
StoryfydDelegate methods
| Method | Description |
|---|---|
| storyfydDidOpenStoryGroup(_:) | Invoked when a story group opens. |
| storyfydDidCloseViewer() | Invoked when the full-screen stories viewer closes. |
| storyfydDidChangeStory(groupId:storyId:) | Invoked when the current story slide changes. |
| storyfydDidInteract(elementId:interaction:) | Invoked when the user interacts with an interactive widget. |
| storyfydShouldHandleURL(_:) | Determines whether your app (true) or the SDK (false) handles a tapped CTA link. |
In-app navigation (Deep Links)
Buttons, SwipeUp gestures, and clickable images can navigate directly inside your app (e.g. to a specific product screen). Set the appUrl field in the Storyfyd creator. When tapped, the SDK invokes storyfydShouldHandleURL(_:) on your delegate before falling back to opening an external browser.
- Register your app's custom URL scheme in the dashboard: Settings → SDK → App URL Scheme.
- Use this scheme in the appUrl field in the story creator (e.g. yourscheme://product?id=42).
- Return true from storyfydShouldHandleURL to handle navigation yourself — the viewer closes automatically, and you perform navigation inside storyfydDidCloseViewer().
Integration with UIKit applications
StoryfydDelegate is a standard Swift protocol — it works identically in UIKit projects. Embed the stories view by wrapping it in a UIHostingController, and handle deep links exactly as you would in SwiftUI.
Deep link execution flow
- User taps a CTA element configured with appUrl: "yourscheme://product?id=42".
- The SDK calls storyfydShouldHandleURL(_:) → your delegate returns true.
- The story viewer smoothly closes.
- storyfydDidCloseViewer() is called.
- Your app transitions to the destination screen (e.g. product details or checkout).
Troubleshooting (FAQ)
Common scenarios encountered when integrating the SDK and how to resolve them quickly.
Stories are not loading
Common causes: missing or invalid API token, wrong API host, or CORS restrictions. Inspect the browser console and Network tab for HTTP 401/403 errors or blocked cross-origin requests.
Widget does not render in React
Make sure the web script is loaded before the React component mounts, your token is valid, and no CORS errors appear in the console.
Background video does not autoplay
Modern browsers permit video autoplay only when muted — the SDK sets this automatically. Also verify that your video uses MP4 (H.264) or WebM format and that CORS headers on your asset server permit streaming.
Props do not update dynamically in React
The widget initializes once on mount. To force re-initialization when the token or user changes, pass a dynamic key prop: <StoryfydWidget key={token} />.