Initialize the SDK
Configure the Onboarding component with safe fallbacks, IDs, keys, callbacks, and lifecycle behavior.
Define a fallback flow#
fallbackFlow is required. It should be a valid local flow that can render if there is no network connection or a published flow cannot be fetched. It is also the initial render while the remote request is in progress.
Editing the fallback does not change what people see. Whenever the app can reach OnboardingYak, it shows the published flow (or its cached copy). To change copy, screens, or translations, edit and publish the flow in Studio or with the MCP tools (get_draft, save_draft, publish_flow), then copy it into the fallback so the backup matches. Development builds log which flow is on screen. The SDK package includes AGENTS.md with these rules for AI coding agents.
import type { OnboardingFlow } from '@onboarding-yak/react-native';
export const fallbackFlow: OnboardingFlow = {
schemaVersion: 1,
id: 'YOUR_APP_ID',
version: 0,
updatedAt: new Date().toISOString(),
screens: [
{
id: 'welcome',
kind: 'Welcome',
title: 'Welcome',
subtitle: 'Your fallback appears if the network is unavailable.',
button: 'Continue',
accent: '#EEF0FF',
action: 'complete',
},
],
};Render Onboarding#
Use the app ID and publishable key from App settings → SDK connection. A publishable key is scoped to reading that app’s live flow and sending anonymous analytics events; it is designed to be included in the client app.
import { Onboarding } from '@onboarding-yak/react-native';
import { fallbackFlow } from './fallback-flow';
export function OnboardingScreen() {
return (
<Onboarding
flowId="YOUR_APP_ID"
apiKey="oy_pub_YOUR_PUBLISHABLE_KEY"
baseUrl="https://onboardingyak.com"
fallbackFlow={fallbackFlow}
onComplete={(answers, { variables }) => {
// Continue into your app and save any answers you need.
}}
/>
);
}Core properties#
| Property | Required | Purpose |
|---|---|---|
flowId | Yes | The OnboardingYak app ID whose published flow should load. |
apiKey | Yes | The app-specific publishable key (oy_pub_…). |
baseUrl | Yes | The studio origin, without a trailing API path. |
fallbackFlow | Yes | A valid local OnboardingFlow shown while loading or offline. |
onComplete | No | Called with answers, typed variables, and selected photo details when the flow ends. |
onAction | No | Handles app-owned actions such as permissions, paywalls, or sign-up. |
onPhotoRequest | Photo steps | Opens the host app's camera or library picker and may upload the selected image. |
onPhotoAnalyze | Optional | Runs the host app's AI analysis only when the person requests it. |
variables | No | Values the app calculates for {tokens} in copy and choice options, such as calories. Pass an object, or a function of the answers so far (SDK 0.15.0+). |
analyticsEnvironment | No | Labels events as development, testing, or production. |
appearance, locale, resume, renderVideo | No | Override appearance/language, disable saved progress, or render video media. |
Offline and saved progress#
The SDK caches the last valid remote flow in AsyncStorage and uses it when it cannot fetch an update. It also saves a person’s current screen, answers, and navigation history so the flow can resume after they leave the app. Progress is cleared when the flow finishes, and is ignored if the published version or saved screen position no longer matches.
Set resume= when the flow should always start from the first screen.