noboarding 0.1.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +515 -0
- package/REVENUECAT_SETUP.md +756 -0
- package/SETUP_GUIDE.md +873 -0
- package/cusomte_screens.md +1964 -0
- package/lib/OnboardingFlow.d.ts +3 -0
- package/lib/OnboardingFlow.js +235 -0
- package/lib/analytics.d.ts +25 -0
- package/lib/analytics.js +72 -0
- package/lib/api.d.ts +31 -0
- package/lib/api.js +149 -0
- package/lib/components/ElementRenderer.d.ts +13 -0
- package/lib/components/ElementRenderer.js +521 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +18 -0
- package/lib/types.d.ts +185 -0
- package/lib/types.js +2 -0
- package/lib/variableUtils.d.ts +17 -0
- package/lib/variableUtils.js +118 -0
- package/logic.md +2095 -0
- package/package.json +44 -0
- package/src/OnboardingFlow.tsx +276 -0
- package/src/analytics.ts +84 -0
- package/src/api.ts +173 -0
- package/src/components/ElementRenderer.tsx +627 -0
- package/src/index.ts +32 -0
- package/src/types.ts +242 -0
- package/src/variableUtils.ts +133 -0
- package/tsconfig.json +20 -0
package/logic.md
ADDED
|
@@ -0,0 +1,2095 @@
|
|
|
1
|
+
# Logic System - Building Intelligent, Personalized Onboarding
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Logic System transforms your onboarding platform from static screens into an intelligent, adaptive experience. Build conditional flows, personalized content, and AI-powered recommendations that respond to each user's unique answers.
|
|
6
|
+
|
|
7
|
+
**What you can build:**
|
|
8
|
+
- Show different content based on user selections
|
|
9
|
+
- Skip screens intelligently based on user profile
|
|
10
|
+
- Generate personalized AI recommendations
|
|
11
|
+
- Create dynamic text that adapts to each user
|
|
12
|
+
- Build complex decision trees without code
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
1. [Core Concepts](#core-concepts)
|
|
19
|
+
2. [Variables System](#variables-system)
|
|
20
|
+
3. [Conditional Display](#conditional-display)
|
|
21
|
+
4. [Conditional Navigation](#conditional-navigation)
|
|
22
|
+
5. [Dynamic Text & Templates](#dynamic-text--templates)
|
|
23
|
+
6. [Computed Variables](#computed-variables)
|
|
24
|
+
7. [AI-Generated Content](#ai-generated-content)
|
|
25
|
+
8. [Actions System](#actions-system)
|
|
26
|
+
9. [Logic Operators](#logic-operators)
|
|
27
|
+
10. [Dashboard: Visual Logic Builder](#dashboard-visual-logic-builder)
|
|
28
|
+
11. [Examples & Use Cases](#examples--use-cases)
|
|
29
|
+
12. [Best Practices](#best-practices)
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Core Concepts
|
|
34
|
+
|
|
35
|
+
### How It Works
|
|
36
|
+
|
|
37
|
+
**Traditional onboarding (static):**
|
|
38
|
+
```
|
|
39
|
+
Screen 1 → Screen 2 → Screen 3 → Screen 4
|
|
40
|
+
(same flow for everyone)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Logic-powered onboarding (dynamic):**
|
|
44
|
+
```
|
|
45
|
+
Screen 1: User picks "workout 3x/week"
|
|
46
|
+
↓
|
|
47
|
+
Screen 2: User picks "poor sleep"
|
|
48
|
+
↓
|
|
49
|
+
Screen 3: User picks "male"
|
|
50
|
+
↓
|
|
51
|
+
Screen 4: Shows personalized content based on ALL previous answers
|
|
52
|
+
"As a male working out 3x/week with poor sleep,
|
|
53
|
+
you need 8-9 hours of sleep for muscle recovery"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Every user sees a different Screen 4 based on their unique combination of answers.**
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### The Four Building Blocks
|
|
61
|
+
|
|
62
|
+
#### 1. Variables
|
|
63
|
+
Store user data as they progress through onboarding.
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"workout_frequency": "3-4",
|
|
67
|
+
"sleep_quality": "poor",
|
|
68
|
+
"gender": "male",
|
|
69
|
+
"age": 28
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 2. Conditions
|
|
74
|
+
Show/hide content based on variable values.
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"show_if": {
|
|
78
|
+
"variable": "workout_frequency",
|
|
79
|
+
"equals": "3-4"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### 3. Actions
|
|
85
|
+
Do something when user interacts (set variables, navigate, track events).
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"onTap": {
|
|
89
|
+
"action": "set_variable",
|
|
90
|
+
"variable": "workout_frequency",
|
|
91
|
+
"value": "3-4"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### 4. Templates
|
|
97
|
+
Inject variables into text dynamically.
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"content": "Welcome, {user.name}! You selected {workout_frequency} workouts."
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Variables System
|
|
107
|
+
|
|
108
|
+
### What Are Variables?
|
|
109
|
+
|
|
110
|
+
Variables store data collected during onboarding. Think of them as containers that hold user information.
|
|
111
|
+
|
|
112
|
+
**Types of variables:**
|
|
113
|
+
- **User Input**: Data collected from user selections/inputs
|
|
114
|
+
- **Computed**: Calculated from other variables
|
|
115
|
+
- **System**: Built-in variables (user.name, device.platform, etc.)
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### Creating Variables
|
|
120
|
+
|
|
121
|
+
Variables are created automatically when you add input elements or explicitly define them.
|
|
122
|
+
|
|
123
|
+
#### Automatic Creation (Recommended)
|
|
124
|
+
|
|
125
|
+
**When user taps an option:**
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"type": "hstack",
|
|
129
|
+
"onTap": {
|
|
130
|
+
"action": "set_variable",
|
|
131
|
+
"variable": "workout_frequency",
|
|
132
|
+
"value": "3-4"
|
|
133
|
+
},
|
|
134
|
+
"elements": [
|
|
135
|
+
{"type": "text", "content": "3-4 times per week"}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**This creates a variable called `workout_frequency` with value `"3-4"`.**
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
#### Explicit Definition
|
|
145
|
+
|
|
146
|
+
**Define variables upfront in screen config:**
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"variables": {
|
|
150
|
+
"workout_frequency": {
|
|
151
|
+
"type": "string",
|
|
152
|
+
"default": null,
|
|
153
|
+
"possible_values": ["1-2", "3-4", "5+"]
|
|
154
|
+
},
|
|
155
|
+
"age": {
|
|
156
|
+
"type": "number",
|
|
157
|
+
"default": 0,
|
|
158
|
+
"min": 13,
|
|
159
|
+
"max": 120
|
|
160
|
+
},
|
|
161
|
+
"fitness_goals": {
|
|
162
|
+
"type": "array",
|
|
163
|
+
"default": [],
|
|
164
|
+
"possible_values": ["lose_weight", "build_muscle", "endurance", "flexibility"]
|
|
165
|
+
},
|
|
166
|
+
"has_wearable": {
|
|
167
|
+
"type": "boolean",
|
|
168
|
+
"default": false
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### Variable Types
|
|
177
|
+
|
|
178
|
+
| Type | Description | Example Values |
|
|
179
|
+
|------|-------------|----------------|
|
|
180
|
+
| **string** | Text value | "3-4", "male", "beginner" |
|
|
181
|
+
| **number** | Numeric value | 28, 180, 75.5 |
|
|
182
|
+
| **boolean** | True/false | true, false |
|
|
183
|
+
| **array** | List of values | ["muscle", "cardio"], [1, 2, 3] |
|
|
184
|
+
| **object** | Nested data | {"name": "John", "age": 28} |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### System Variables
|
|
189
|
+
|
|
190
|
+
**Built-in variables available everywhere:**
|
|
191
|
+
|
|
192
|
+
| Variable | Description | Example |
|
|
193
|
+
|----------|-------------|---------|
|
|
194
|
+
| `user.name` | User's name (if collected) | "John Smith" |
|
|
195
|
+
| `user.email` | User's email | "john@example.com" |
|
|
196
|
+
| `user.id` | Unique user ID | "user_abc123" |
|
|
197
|
+
| `device.platform` | iOS or Android | "iOS" |
|
|
198
|
+
| `device.version` | OS version | "17.2" |
|
|
199
|
+
| `app.version` | Your app version | "1.2.0" |
|
|
200
|
+
| `app.name` | Your app name | "BodyMax" |
|
|
201
|
+
| `current_screen` | Current screen ID | "screen_3" |
|
|
202
|
+
| `total_screens` | Total screens in flow | 5 |
|
|
203
|
+
| `screen_index` | Current position (0-based) | 2 |
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### Variable Scope
|
|
208
|
+
|
|
209
|
+
**Variables persist throughout the entire onboarding flow:**
|
|
210
|
+
```
|
|
211
|
+
Screen 1: Set workout_frequency = "3-4"
|
|
212
|
+
↓
|
|
213
|
+
Screen 2: workout_frequency still = "3-4"
|
|
214
|
+
↓
|
|
215
|
+
Screen 3: workout_frequency still = "3-4"
|
|
216
|
+
↓
|
|
217
|
+
Screen 4: Use workout_frequency in logic
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Variables are passed to `onComplete` callback:**
|
|
221
|
+
```typescript
|
|
222
|
+
<OnboardingFlow
|
|
223
|
+
onComplete={(data) => {
|
|
224
|
+
// data contains ALL collected variables:
|
|
225
|
+
// {
|
|
226
|
+
// workout_frequency: "3-4",
|
|
227
|
+
// sleep_quality: "poor",
|
|
228
|
+
// gender: "male",
|
|
229
|
+
// age: 28
|
|
230
|
+
// }
|
|
231
|
+
}}
|
|
232
|
+
/>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Conditional Display
|
|
238
|
+
|
|
239
|
+
### Show/Hide Elements Based on Conditions
|
|
240
|
+
|
|
241
|
+
Make elements appear only when certain conditions are met.
|
|
242
|
+
|
|
243
|
+
### Basic Example
|
|
244
|
+
|
|
245
|
+
**Show text only for users who selected "5+" workouts:**
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"type": "text",
|
|
249
|
+
"content": "You're a dedicated athlete! Here's an advanced plan.",
|
|
250
|
+
"conditions": {
|
|
251
|
+
"show_if": {
|
|
252
|
+
"variable": "workout_frequency",
|
|
253
|
+
"equals": "5+"
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Result:**
|
|
260
|
+
- User selected "5+" → Text shows
|
|
261
|
+
- User selected "3-4" or "1-2" → Text hidden
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### Multiple Conditions (AND Logic)
|
|
266
|
+
|
|
267
|
+
**Show only if ALL conditions are true:**
|
|
268
|
+
```json
|
|
269
|
+
{
|
|
270
|
+
"type": "text",
|
|
271
|
+
"content": "As a male working out 5+ times per week, consider these supplements...",
|
|
272
|
+
"conditions": {
|
|
273
|
+
"show_if": {
|
|
274
|
+
"all": [
|
|
275
|
+
{"variable": "workout_frequency", "equals": "5+"},
|
|
276
|
+
{"variable": "gender", "equals": "male"}
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Result:** Only shows if BOTH conditions are true.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
### Any Condition (OR Logic)
|
|
288
|
+
|
|
289
|
+
**Show if ANY condition is true:**
|
|
290
|
+
```json
|
|
291
|
+
{
|
|
292
|
+
"type": "text",
|
|
293
|
+
"content": "You might benefit from recovery supplements.",
|
|
294
|
+
"conditions": {
|
|
295
|
+
"show_if": {
|
|
296
|
+
"any": [
|
|
297
|
+
{"variable": "workout_frequency", "equals": "5+"},
|
|
298
|
+
{"variable": "sleep_quality", "equals": "poor"},
|
|
299
|
+
{"variable": "age", "greater_than": 40}
|
|
300
|
+
]
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**Result:** Shows if user works out 5+ times OR has poor sleep OR is over 40.
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
### Negation (NOT Logic)
|
|
311
|
+
|
|
312
|
+
**Show if condition is NOT true:**
|
|
313
|
+
```json
|
|
314
|
+
{
|
|
315
|
+
"type": "text",
|
|
316
|
+
"content": "Consider getting a fitness tracker to optimize your training.",
|
|
317
|
+
"conditions": {
|
|
318
|
+
"show_if": {
|
|
319
|
+
"not": {
|
|
320
|
+
"variable": "has_wearable",
|
|
321
|
+
"equals": true
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Result:** Only shows if user does NOT have a wearable.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
### Complex Nested Logic
|
|
333
|
+
|
|
334
|
+
**Combine all logic types:**
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"type": "text",
|
|
338
|
+
"content": "High-intensity recovery plan recommended",
|
|
339
|
+
"conditions": {
|
|
340
|
+
"show_if": {
|
|
341
|
+
"all": [
|
|
342
|
+
{
|
|
343
|
+
"any": [
|
|
344
|
+
{"variable": "workout_frequency", "equals": "5+"},
|
|
345
|
+
{"variable": "fitness_level", "equals": "advanced"}
|
|
346
|
+
]
|
|
347
|
+
},
|
|
348
|
+
{"variable": "sleep_quality", "equals": "poor"},
|
|
349
|
+
{
|
|
350
|
+
"not": {
|
|
351
|
+
"variable": "has_injury",
|
|
352
|
+
"equals": true
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Translation:**
|
|
362
|
+
```
|
|
363
|
+
Show if:
|
|
364
|
+
(workout_frequency is "5+" OR fitness_level is "advanced")
|
|
365
|
+
AND sleep_quality is "poor"
|
|
366
|
+
AND user does NOT have an injury
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
### Hiding Entire Sections
|
|
372
|
+
|
|
373
|
+
**Conditional VStack (hide entire groups):**
|
|
374
|
+
```json
|
|
375
|
+
{
|
|
376
|
+
"type": "vstack",
|
|
377
|
+
"conditions": {
|
|
378
|
+
"show_if": {
|
|
379
|
+
"variable": "has_wearable",
|
|
380
|
+
"equals": true
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
"elements": [
|
|
384
|
+
{"type": "text", "content": "Wearable Settings"},
|
|
385
|
+
{"type": "text", "content": "Sync your device..."},
|
|
386
|
+
{"type": "button", "text": "Connect Wearable"}
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Result:** Entire section hidden if user doesn't have wearable.
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## Conditional Navigation
|
|
396
|
+
|
|
397
|
+
### Skip Screens Based on Logic
|
|
398
|
+
|
|
399
|
+
Send users to different screens based on their answers.
|
|
400
|
+
|
|
401
|
+
### Basic Conditional Navigation
|
|
402
|
+
|
|
403
|
+
**Skip to different screens based on one variable:**
|
|
404
|
+
```json
|
|
405
|
+
{
|
|
406
|
+
"type": "button",
|
|
407
|
+
"text": "Continue",
|
|
408
|
+
"onTap": {
|
|
409
|
+
"action": "navigate",
|
|
410
|
+
"next_screen": {
|
|
411
|
+
"if": {
|
|
412
|
+
"variable": "has_wearable",
|
|
413
|
+
"equals": true
|
|
414
|
+
},
|
|
415
|
+
"then": "wearable_sync_screen",
|
|
416
|
+
"else": "goal_selection_screen"
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**Flow:**
|
|
423
|
+
```
|
|
424
|
+
User has wearable: → wearable_sync_screen
|
|
425
|
+
User no wearable: → goal_selection_screen
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
### Multi-Condition Navigation
|
|
431
|
+
|
|
432
|
+
**Route based on multiple conditions:**
|
|
433
|
+
```json
|
|
434
|
+
{
|
|
435
|
+
"type": "button",
|
|
436
|
+
"text": "Continue",
|
|
437
|
+
"onTap": {
|
|
438
|
+
"action": "navigate",
|
|
439
|
+
"next_screen": {
|
|
440
|
+
"if": {
|
|
441
|
+
"all": [
|
|
442
|
+
{"variable": "age", "less_than": 18},
|
|
443
|
+
{"variable": "has_parent_consent", "equals": false}
|
|
444
|
+
]
|
|
445
|
+
},
|
|
446
|
+
"then": "parent_consent_screen",
|
|
447
|
+
"else": "main_onboarding"
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
### Complex Routing (Multiple Paths)
|
|
456
|
+
|
|
457
|
+
**Route to different screens based on multiple conditions:**
|
|
458
|
+
```json
|
|
459
|
+
{
|
|
460
|
+
"type": "button",
|
|
461
|
+
"text": "Continue",
|
|
462
|
+
"onTap": {
|
|
463
|
+
"action": "navigate_conditional",
|
|
464
|
+
"routes": [
|
|
465
|
+
{
|
|
466
|
+
"if": {
|
|
467
|
+
"all": [
|
|
468
|
+
{"variable": "fitness_level", "equals": "beginner"},
|
|
469
|
+
{"variable": "has_injury", "equals": true}
|
|
470
|
+
]
|
|
471
|
+
},
|
|
472
|
+
"then": "beginner_injury_plan"
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
"if": {
|
|
476
|
+
"variable": "fitness_level",
|
|
477
|
+
"equals": "beginner"
|
|
478
|
+
},
|
|
479
|
+
"then": "beginner_plan"
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
"if": {
|
|
483
|
+
"variable": "fitness_level",
|
|
484
|
+
"equals": "advanced"
|
|
485
|
+
},
|
|
486
|
+
"then": "advanced_plan"
|
|
487
|
+
}
|
|
488
|
+
],
|
|
489
|
+
"default": "intermediate_plan"
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
**Logic:**
|
|
495
|
+
```
|
|
496
|
+
1. Check: beginner + injury → beginner_injury_plan
|
|
497
|
+
2. Else check: beginner → beginner_plan
|
|
498
|
+
3. Else check: advanced → advanced_plan
|
|
499
|
+
4. Else (default): intermediate_plan
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
### Skip Multiple Screens
|
|
505
|
+
|
|
506
|
+
**Jump ahead based on user profile:**
|
|
507
|
+
```json
|
|
508
|
+
{
|
|
509
|
+
"type": "button",
|
|
510
|
+
"text": "Continue",
|
|
511
|
+
"onTap": {
|
|
512
|
+
"action": "navigate",
|
|
513
|
+
"next_screen": {
|
|
514
|
+
"if": {
|
|
515
|
+
"variable": "is_returning_user",
|
|
516
|
+
"equals": true
|
|
517
|
+
},
|
|
518
|
+
"then": "welcome_back_screen",
|
|
519
|
+
"else": "tutorial_screen_1"
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
**Result:**
|
|
526
|
+
- New users: See all 5 tutorial screens
|
|
527
|
+
- Returning users: Skip tutorials, go straight to welcome back
|
|
528
|
+
|
|
529
|
+
---
|
|
530
|
+
|
|
531
|
+
## Dynamic Text & Templates
|
|
532
|
+
|
|
533
|
+
### Inject Variables into Text
|
|
534
|
+
|
|
535
|
+
Make text personalize based on user data.
|
|
536
|
+
|
|
537
|
+
### Basic Template Variables
|
|
538
|
+
|
|
539
|
+
**Syntax:** `{variable_name}`
|
|
540
|
+
```json
|
|
541
|
+
{
|
|
542
|
+
"type": "text",
|
|
543
|
+
"content": "Welcome, {user.name}!"
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
**Result:**
|
|
548
|
+
- If user.name = "John" → "Welcome, John!"
|
|
549
|
+
- If user.name = "Sarah" → "Welcome, Sarah!"
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
### Multiple Variables in One String
|
|
554
|
+
```json
|
|
555
|
+
{
|
|
556
|
+
"type": "text",
|
|
557
|
+
"content": "Based on working out {workout_frequency} times per week and {sleep_quality} sleep, we recommend..."
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
**Result:**
|
|
562
|
+
```
|
|
563
|
+
"Based on working out 3-4 times per week and poor sleep, we recommend..."
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
### System Variables
|
|
569
|
+
```json
|
|
570
|
+
{
|
|
571
|
+
"type": "text",
|
|
572
|
+
"content": "You're on screen {screen_index} of {total_screens}"
|
|
573
|
+
}
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
**Result:**
|
|
577
|
+
```
|
|
578
|
+
"You're on screen 2 of 5"
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
---
|
|
582
|
+
|
|
583
|
+
### Conditional Text (Ternary)
|
|
584
|
+
|
|
585
|
+
**Show different text based on condition:**
|
|
586
|
+
```json
|
|
587
|
+
{
|
|
588
|
+
"type": "text",
|
|
589
|
+
"content": "{workout_frequency == '5+' ? 'You're an athlete!' : 'You're building a habit!'}"
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
**Result:**
|
|
594
|
+
- If workout_frequency is "5+" → "You're an athlete!"
|
|
595
|
+
- Otherwise → "You're building a habit!"
|
|
596
|
+
|
|
597
|
+
---
|
|
598
|
+
|
|
599
|
+
### Computed Text
|
|
600
|
+
|
|
601
|
+
**Calculate values in templates:**
|
|
602
|
+
```json
|
|
603
|
+
{
|
|
604
|
+
"type": "text",
|
|
605
|
+
"content": "Your BMI is {weight_kg / (height_m * height_m)}"
|
|
606
|
+
}
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
## Computed Variables
|
|
612
|
+
|
|
613
|
+
### Variables That Calculate Automatically
|
|
614
|
+
|
|
615
|
+
Computed variables derive their value from other variables.
|
|
616
|
+
|
|
617
|
+
### Simple Formula
|
|
618
|
+
|
|
619
|
+
**Define in screen config:**
|
|
620
|
+
```json
|
|
621
|
+
{
|
|
622
|
+
"computed_variables": {
|
|
623
|
+
"bmi": {
|
|
624
|
+
"type": "formula",
|
|
625
|
+
"formula": "weight_kg / (height_m * height_m)"
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
**Use anywhere:**
|
|
632
|
+
```json
|
|
633
|
+
{
|
|
634
|
+
"type": "text",
|
|
635
|
+
"content": "Your BMI: {bmi}"
|
|
636
|
+
}
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
**Auto-updates when weight_kg or height_m changes.**
|
|
640
|
+
|
|
641
|
+
---
|
|
642
|
+
|
|
643
|
+
### Conditional Formula (IF/THEN)
|
|
644
|
+
```json
|
|
645
|
+
{
|
|
646
|
+
"computed_variables": {
|
|
647
|
+
"sleep_recommendation": {
|
|
648
|
+
"type": "formula",
|
|
649
|
+
"formula": "workout_frequency == '5+' ? 9 : (workout_frequency == '3-4' ? 8 : 7)"
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
**Logic:**
|
|
656
|
+
```
|
|
657
|
+
If workout 5+ times: recommend 9 hours
|
|
658
|
+
Else if workout 3-4 times: recommend 8 hours
|
|
659
|
+
Else: recommend 7 hours
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
---
|
|
663
|
+
|
|
664
|
+
### Lookup Tables
|
|
665
|
+
|
|
666
|
+
**Map combinations to values:**
|
|
667
|
+
```json
|
|
668
|
+
{
|
|
669
|
+
"computed_variables": {
|
|
670
|
+
"fitness_level": {
|
|
671
|
+
"type": "lookup",
|
|
672
|
+
"inputs": ["workout_frequency", "sleep_quality"],
|
|
673
|
+
"lookup_table": {
|
|
674
|
+
"5+_good": "Advanced",
|
|
675
|
+
"5+_poor": "Intermediate",
|
|
676
|
+
"3-4_good": "Intermediate",
|
|
677
|
+
"3-4_poor": "Beginner",
|
|
678
|
+
"1-2_good": "Beginner",
|
|
679
|
+
"1-2_poor": "Beginner"
|
|
680
|
+
},
|
|
681
|
+
"default": "Beginner"
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
**How it works:**
|
|
688
|
+
```
|
|
689
|
+
User: workout_frequency = "5+", sleep_quality = "good"
|
|
690
|
+
Lookup key: "5+_good"
|
|
691
|
+
Result: fitness_level = "Advanced"
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
---
|
|
695
|
+
|
|
696
|
+
### Array Operations
|
|
697
|
+
|
|
698
|
+
**Count, filter, map arrays:**
|
|
699
|
+
```json
|
|
700
|
+
{
|
|
701
|
+
"computed_variables": {
|
|
702
|
+
"goals_count": {
|
|
703
|
+
"type": "formula",
|
|
704
|
+
"formula": "fitness_goals.length"
|
|
705
|
+
},
|
|
706
|
+
"is_focused": {
|
|
707
|
+
"type": "formula",
|
|
708
|
+
"formula": "fitness_goals.length <= 2"
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
---
|
|
715
|
+
|
|
716
|
+
### String Operations
|
|
717
|
+
```json
|
|
718
|
+
{
|
|
719
|
+
"computed_variables": {
|
|
720
|
+
"first_name": {
|
|
721
|
+
"type": "formula",
|
|
722
|
+
"formula": "user.name.split(' ')[0]"
|
|
723
|
+
},
|
|
724
|
+
"name_uppercase": {
|
|
725
|
+
"type": "formula",
|
|
726
|
+
"formula": "user.name.toUpperCase()"
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
---
|
|
733
|
+
|
|
734
|
+
## AI-Generated Content
|
|
735
|
+
|
|
736
|
+
### Personalized Content Powered by AI
|
|
737
|
+
|
|
738
|
+
Generate unique, personalized text for each user based on their answers.
|
|
739
|
+
|
|
740
|
+
### Basic AI Text Element
|
|
741
|
+
```json
|
|
742
|
+
{
|
|
743
|
+
"type": "ai_generated_text",
|
|
744
|
+
"prompt": "Generate a personalized fitness recommendation for someone who works out {workout_frequency} times per week, has {sleep_quality} sleep quality, and wants to {fitness_goal}. Keep it under 100 words and actionable.",
|
|
745
|
+
"model": "gpt-4-turbo",
|
|
746
|
+
"cache": true,
|
|
747
|
+
"loading_text": "Creating your personalized plan...",
|
|
748
|
+
"fallback_text": "Based on your goals, we recommend starting with a balanced routine."
|
|
749
|
+
}
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
---
|
|
753
|
+
|
|
754
|
+
### How It Works
|
|
755
|
+
|
|
756
|
+
**When user reaches this screen:**
|
|
757
|
+
|
|
758
|
+
1. **SDK detects** `ai_generated_text` element
|
|
759
|
+
2. **Replaces variables** in prompt with actual values
|
|
760
|
+
3. **Checks cache**: Has this exact prompt been generated before?
|
|
761
|
+
4. **If cached**: Return instantly (no API call)
|
|
762
|
+
5. **If not cached**:
|
|
763
|
+
- Send to your backend
|
|
764
|
+
- Backend calls OpenAI/Claude API
|
|
765
|
+
- Cache result for 7 days
|
|
766
|
+
- Return to user
|
|
767
|
+
6. **Shows result** to user
|
|
768
|
+
|
|
769
|
+
---
|
|
770
|
+
|
|
771
|
+
### Example Workflow
|
|
772
|
+
|
|
773
|
+
**User answers:**
|
|
774
|
+
```
|
|
775
|
+
workout_frequency: "3-4"
|
|
776
|
+
sleep_quality: "poor"
|
|
777
|
+
fitness_goal: "build muscle"
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
**Prompt sent to AI:**
|
|
781
|
+
```
|
|
782
|
+
"Generate a personalized fitness recommendation for someone who
|
|
783
|
+
works out 3-4 times per week, has poor sleep quality, and wants
|
|
784
|
+
to build muscle. Keep it under 100 words and actionable."
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
**AI generates:**
|
|
788
|
+
```
|
|
789
|
+
"As someone training 3-4 times per week with poor sleep, your
|
|
790
|
+
muscle recovery is compromised. Prioritize 8-9 hours of sleep
|
|
791
|
+
nightly—this is when muscle repair happens. Consider a magnesium
|
|
792
|
+
supplement 30 minutes before bed. Reduce your training intensity
|
|
793
|
+
by 20% until sleep improves to avoid overtraining. Track your
|
|
794
|
+
recovery: if you're consistently sore for 48+ hours, you need
|
|
795
|
+
more rest. Once sleep stabilizes, gradually increase volume."
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
**User sees personalized recommendation instantly.**
|
|
799
|
+
|
|
800
|
+
---
|
|
801
|
+
|
|
802
|
+
### AI Element Configuration
|
|
803
|
+
```json
|
|
804
|
+
{
|
|
805
|
+
"type": "ai_generated_text",
|
|
806
|
+
"prompt": "Your prompt template with {variables}",
|
|
807
|
+
"model": "gpt-4-turbo", // or "claude-3-sonnet", "gpt-3.5-turbo"
|
|
808
|
+
"max_length": 100, // words
|
|
809
|
+
"cache": true, // Cache results to save API costs
|
|
810
|
+
"cache_duration": 7, // days
|
|
811
|
+
"temperature": 0.7, // Creativity (0-1)
|
|
812
|
+
"loading_text": "Generating...",
|
|
813
|
+
"fallback_text": "Generic recommendation if API fails",
|
|
814
|
+
"style": "friendly", // Optional: friendly, professional, casual
|
|
815
|
+
"tone": "motivational" // Optional: motivational, informative, empathetic
|
|
816
|
+
}
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
---
|
|
820
|
+
|
|
821
|
+
### Multi-Variable AI Generation
|
|
822
|
+
|
|
823
|
+
**Use multiple variables in prompt:**
|
|
824
|
+
```json
|
|
825
|
+
{
|
|
826
|
+
"type": "ai_generated_text",
|
|
827
|
+
"prompt": "Create a {workout_type} workout plan for a {age}-year-old {gender} who is {fitness_level} level, works out {workout_frequency} times per week, has {equipment_available} equipment, and wants to {fitness_goal}. Include specific exercises and rep ranges. Keep under 150 words.",
|
|
828
|
+
"model": "gpt-4-turbo"
|
|
829
|
+
}
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
**Extremely personalized output for every user combination.**
|
|
833
|
+
|
|
834
|
+
---
|
|
835
|
+
|
|
836
|
+
### Caching Strategy
|
|
837
|
+
|
|
838
|
+
**Why caching matters:**
|
|
839
|
+
|
|
840
|
+
Without caching:
|
|
841
|
+
```
|
|
842
|
+
1,000 users × $0.008 per generation = $8.00/day
|
|
843
|
+
30 days = $240/month cost
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
With caching (7-day cache):
|
|
847
|
+
```
|
|
848
|
+
Unique combinations: ~50-100
|
|
849
|
+
Cost: 100 × $0.008 = $0.80 one-time
|
|
850
|
+
Serves all 1,000 users for 7 days
|
|
851
|
+
Monthly cost: ~$3-5
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
**Caching saves 98%+ on AI costs.**
|
|
855
|
+
|
|
856
|
+
---
|
|
857
|
+
|
|
858
|
+
### AI for Different Use Cases
|
|
859
|
+
|
|
860
|
+
**Fitness App:**
|
|
861
|
+
```json
|
|
862
|
+
{
|
|
863
|
+
"prompt": "Create a {workout_duration}-minute {workout_type} workout..."
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
**Finance App:**
|
|
868
|
+
```json
|
|
869
|
+
{
|
|
870
|
+
"prompt": "Recommend an investment strategy for someone with {risk_tolerance} risk tolerance, ${income} annual income, and {investment_goal} as their goal..."
|
|
871
|
+
}
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
**Health App:**
|
|
875
|
+
```json
|
|
876
|
+
{
|
|
877
|
+
"prompt": "Provide health recommendations for someone experiencing {symptoms}, aged {age}, with {medical_conditions}. Recommend when to see a doctor if necessary..."
|
|
878
|
+
}
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
**Dating App:**
|
|
882
|
+
```json
|
|
883
|
+
{
|
|
884
|
+
"prompt": "Generate profile tips for someone interested in {interests}, looking for {relationship_type}, with personality type {personality}..."
|
|
885
|
+
}
|
|
886
|
+
```
|
|
887
|
+
|
|
888
|
+
---
|
|
889
|
+
|
|
890
|
+
## Actions System
|
|
891
|
+
|
|
892
|
+
### Do Things When Users Interact
|
|
893
|
+
|
|
894
|
+
Actions trigger when users tap, swipe, or interact with elements.
|
|
895
|
+
|
|
896
|
+
### Action Types
|
|
897
|
+
|
|
898
|
+
#### 1. Set Variable
|
|
899
|
+
|
|
900
|
+
**Set a single variable:**
|
|
901
|
+
```json
|
|
902
|
+
{
|
|
903
|
+
"onTap": {
|
|
904
|
+
"action": "set_variable",
|
|
905
|
+
"variable": "workout_frequency",
|
|
906
|
+
"value": "3-4"
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
---
|
|
912
|
+
|
|
913
|
+
#### 2. Set Multiple Variables
|
|
914
|
+
|
|
915
|
+
**Set several variables at once:**
|
|
916
|
+
```json
|
|
917
|
+
{
|
|
918
|
+
"onTap": {
|
|
919
|
+
"action": "set_variables",
|
|
920
|
+
"variables": {
|
|
921
|
+
"workout_frequency": "3-4",
|
|
922
|
+
"fitness_level": "intermediate",
|
|
923
|
+
"needs_guidance": true
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
---
|
|
930
|
+
|
|
931
|
+
#### 3. Navigate
|
|
932
|
+
|
|
933
|
+
**Go to specific screen:**
|
|
934
|
+
```json
|
|
935
|
+
{
|
|
936
|
+
"onTap": {
|
|
937
|
+
"action": "navigate",
|
|
938
|
+
"next_screen": "screen_5"
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
---
|
|
944
|
+
|
|
945
|
+
#### 4. Navigate Conditionally
|
|
946
|
+
|
|
947
|
+
**Go to different screens based on logic:**
|
|
948
|
+
```json
|
|
949
|
+
{
|
|
950
|
+
"onTap": {
|
|
951
|
+
"action": "navigate",
|
|
952
|
+
"next_screen": {
|
|
953
|
+
"if": {"variable": "has_wearable", "equals": true},
|
|
954
|
+
"then": "wearable_sync_screen",
|
|
955
|
+
"else": "goals_screen"
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
---
|
|
962
|
+
|
|
963
|
+
#### 5. Increment/Decrement
|
|
964
|
+
|
|
965
|
+
**Increase or decrease number:**
|
|
966
|
+
```json
|
|
967
|
+
{
|
|
968
|
+
"onTap": {
|
|
969
|
+
"action": "increment",
|
|
970
|
+
"variable": "screens_completed",
|
|
971
|
+
"amount": 1
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
```
|
|
975
|
+
```json
|
|
976
|
+
{
|
|
977
|
+
"onTap": {
|
|
978
|
+
"action": "decrement",
|
|
979
|
+
"variable": "days_remaining",
|
|
980
|
+
"amount": 1
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
---
|
|
986
|
+
|
|
987
|
+
#### 6. Toggle Boolean
|
|
988
|
+
|
|
989
|
+
**Flip true/false:**
|
|
990
|
+
```json
|
|
991
|
+
{
|
|
992
|
+
"onTap": {
|
|
993
|
+
"action": "toggle",
|
|
994
|
+
"variable": "show_advanced_options"
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
---
|
|
1000
|
+
|
|
1001
|
+
#### 7. Append to Array
|
|
1002
|
+
|
|
1003
|
+
**Add item to array:**
|
|
1004
|
+
```json
|
|
1005
|
+
{
|
|
1006
|
+
"onTap": {
|
|
1007
|
+
"action": "append",
|
|
1008
|
+
"variable": "fitness_goals",
|
|
1009
|
+
"value": "build_muscle"
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
---
|
|
1015
|
+
|
|
1016
|
+
#### 8. Remove from Array
|
|
1017
|
+
|
|
1018
|
+
**Remove item from array:**
|
|
1019
|
+
```json
|
|
1020
|
+
{
|
|
1021
|
+
"onTap": {
|
|
1022
|
+
"action": "remove",
|
|
1023
|
+
"variable": "fitness_goals",
|
|
1024
|
+
"value": "lose_weight"
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
---
|
|
1030
|
+
|
|
1031
|
+
#### 9. Track Event
|
|
1032
|
+
|
|
1033
|
+
**Send analytics event:**
|
|
1034
|
+
```json
|
|
1035
|
+
{
|
|
1036
|
+
"onTap": {
|
|
1037
|
+
"action": "track_event",
|
|
1038
|
+
"event_name": "selected_workout_frequency",
|
|
1039
|
+
"properties": {
|
|
1040
|
+
"frequency": "{workout_frequency}",
|
|
1041
|
+
"screen": "{current_screen}",
|
|
1042
|
+
"user_type": "{fitness_level}"
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
---
|
|
1049
|
+
|
|
1050
|
+
#### 10. Multiple Actions
|
|
1051
|
+
|
|
1052
|
+
**Execute several actions in sequence:**
|
|
1053
|
+
```json
|
|
1054
|
+
{
|
|
1055
|
+
"onTap": {
|
|
1056
|
+
"actions": [
|
|
1057
|
+
{
|
|
1058
|
+
"action": "set_variable",
|
|
1059
|
+
"variable": "workout_frequency",
|
|
1060
|
+
"value": "3-4"
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
"action": "track_event",
|
|
1064
|
+
"event_name": "workout_frequency_selected"
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
"action": "navigate",
|
|
1068
|
+
"next_screen": "sleep_quality_screen"
|
|
1069
|
+
}
|
|
1070
|
+
]
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
---
|
|
1076
|
+
|
|
1077
|
+
### Complete Example: Multi-Select with Actions
|
|
1078
|
+
```json
|
|
1079
|
+
{
|
|
1080
|
+
"type": "vstack",
|
|
1081
|
+
"spacing": 12,
|
|
1082
|
+
"elements": [
|
|
1083
|
+
{
|
|
1084
|
+
"type": "text",
|
|
1085
|
+
"content": "What are your fitness goals? (Select all that apply)"
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
"type": "hstack",
|
|
1089
|
+
"id": "goal_lose_weight",
|
|
1090
|
+
"background": "{fitness_goals.includes('lose_weight') ? '#FF6B6B' : '#F5F5F5'}",
|
|
1091
|
+
"padding": 16,
|
|
1092
|
+
"borderRadius": 8,
|
|
1093
|
+
"onTap": {
|
|
1094
|
+
"actions": [
|
|
1095
|
+
{
|
|
1096
|
+
"action": "conditional",
|
|
1097
|
+
"if": {
|
|
1098
|
+
"variable": "fitness_goals",
|
|
1099
|
+
"contains": "lose_weight"
|
|
1100
|
+
},
|
|
1101
|
+
"then": {
|
|
1102
|
+
"action": "remove",
|
|
1103
|
+
"variable": "fitness_goals",
|
|
1104
|
+
"value": "lose_weight"
|
|
1105
|
+
},
|
|
1106
|
+
"else": {
|
|
1107
|
+
"action": "append",
|
|
1108
|
+
"variable": "fitness_goals",
|
|
1109
|
+
"value": "lose_weight"
|
|
1110
|
+
}
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
"action": "track_event",
|
|
1114
|
+
"event_name": "goal_toggled",
|
|
1115
|
+
"properties": {
|
|
1116
|
+
"goal": "lose_weight"
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
]
|
|
1120
|
+
},
|
|
1121
|
+
"elements": [
|
|
1122
|
+
{"type": "text", "content": "Lose Weight"}
|
|
1123
|
+
]
|
|
1124
|
+
}
|
|
1125
|
+
]
|
|
1126
|
+
}
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
**How it works:**
|
|
1130
|
+
1. User taps "Lose Weight" option
|
|
1131
|
+
2. If already selected → Remove from array (deselect)
|
|
1132
|
+
3. If not selected → Add to array (select)
|
|
1133
|
+
4. Track analytics event
|
|
1134
|
+
5. Background color changes based on selection state
|
|
1135
|
+
|
|
1136
|
+
---
|
|
1137
|
+
|
|
1138
|
+
## Logic Operators
|
|
1139
|
+
|
|
1140
|
+
### All Available Operators
|
|
1141
|
+
|
|
1142
|
+
#### Comparison Operators
|
|
1143
|
+
```json
|
|
1144
|
+
// Equals
|
|
1145
|
+
{"variable": "age", "operator": "equals", "value": 25}
|
|
1146
|
+
{"variable": "age", "equals": 25} // Shorthand
|
|
1147
|
+
|
|
1148
|
+
// Not Equals
|
|
1149
|
+
{"variable": "gender", "not_equals": "other"}
|
|
1150
|
+
|
|
1151
|
+
// Greater Than
|
|
1152
|
+
{"variable": "age", "greater_than": 18}
|
|
1153
|
+
|
|
1154
|
+
// Less Than
|
|
1155
|
+
{"variable": "age", "less_than": 65}
|
|
1156
|
+
|
|
1157
|
+
// Greater Than or Equal
|
|
1158
|
+
{"variable": "workout_frequency_num", "greater_than_or_equal": 3}
|
|
1159
|
+
|
|
1160
|
+
// Less Than or Equal
|
|
1161
|
+
{"variable": "bmi", "less_than_or_equal": 25}
|
|
1162
|
+
```
|
|
1163
|
+
|
|
1164
|
+
---
|
|
1165
|
+
|
|
1166
|
+
#### String Operators
|
|
1167
|
+
```json
|
|
1168
|
+
// Contains (substring)
|
|
1169
|
+
{"variable": "name", "contains": "John"}
|
|
1170
|
+
|
|
1171
|
+
// Not Contains
|
|
1172
|
+
{"variable": "name", "not_contains": "Admin"}
|
|
1173
|
+
|
|
1174
|
+
// Starts With
|
|
1175
|
+
{"variable": "email", "starts_with": "admin@"}
|
|
1176
|
+
|
|
1177
|
+
// Ends With
|
|
1178
|
+
{"variable": "email", "ends_with": "@company.com"}
|
|
1179
|
+
|
|
1180
|
+
// Matches Regex
|
|
1181
|
+
{"variable": "phone", "matches": "^\\+1[0-9]{10}$"}
|
|
1182
|
+
```
|
|
1183
|
+
|
|
1184
|
+
---
|
|
1185
|
+
|
|
1186
|
+
#### Array Operators
|
|
1187
|
+
```json
|
|
1188
|
+
// In Array
|
|
1189
|
+
{"variable": "selected_goal", "in": ["lose_weight", "build_muscle"]}
|
|
1190
|
+
|
|
1191
|
+
// Not In Array
|
|
1192
|
+
{"variable": "country", "not_in": ["US", "CA", "UK"]}
|
|
1193
|
+
|
|
1194
|
+
// Array Contains (value in array variable)
|
|
1195
|
+
{"variable": "fitness_goals", "contains": "lose_weight"}
|
|
1196
|
+
|
|
1197
|
+
// Array Length
|
|
1198
|
+
{"variable": "fitness_goals", "length_equals": 2}
|
|
1199
|
+
{"variable": "fitness_goals", "length_greater_than": 0}
|
|
1200
|
+
```
|
|
1201
|
+
|
|
1202
|
+
---
|
|
1203
|
+
|
|
1204
|
+
#### Existence Operators
|
|
1205
|
+
```json
|
|
1206
|
+
// Is Empty (null, undefined, "", [], {})
|
|
1207
|
+
{"variable": "user_name", "is_empty": true}
|
|
1208
|
+
|
|
1209
|
+
// Is Not Empty
|
|
1210
|
+
{"variable": "user_name", "is_not_empty": true}
|
|
1211
|
+
|
|
1212
|
+
// Exists (variable is defined)
|
|
1213
|
+
{"variable": "custom_field", "exists": true}
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
---
|
|
1217
|
+
|
|
1218
|
+
#### Boolean Logic
|
|
1219
|
+
```json
|
|
1220
|
+
// AND - All conditions must be true
|
|
1221
|
+
{
|
|
1222
|
+
"all": [
|
|
1223
|
+
{"variable": "age", "greater_than": 18},
|
|
1224
|
+
{"variable": "country", "equals": "US"},
|
|
1225
|
+
{"variable": "accepted_terms", "equals": true}
|
|
1226
|
+
]
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// OR - Any condition must be true
|
|
1230
|
+
{
|
|
1231
|
+
"any": [
|
|
1232
|
+
{"variable": "is_premium", "equals": true},
|
|
1233
|
+
{"variable": "referral_code", "exists": true},
|
|
1234
|
+
{"variable": "beta_tester", "equals": true}
|
|
1235
|
+
]
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// NOT - Negate condition
|
|
1239
|
+
{
|
|
1240
|
+
"not": {
|
|
1241
|
+
"variable": "has_subscription",
|
|
1242
|
+
"equals": true
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// Nested Logic
|
|
1247
|
+
{
|
|
1248
|
+
"all": [
|
|
1249
|
+
{
|
|
1250
|
+
"any": [
|
|
1251
|
+
{"variable": "age", "greater_than": 21},
|
|
1252
|
+
{"variable": "parent_consent", "equals": true}
|
|
1253
|
+
]
|
|
1254
|
+
},
|
|
1255
|
+
{"variable": "country", "equals": "US"},
|
|
1256
|
+
{
|
|
1257
|
+
"not": {
|
|
1258
|
+
"variable": "banned",
|
|
1259
|
+
"equals": true
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
]
|
|
1263
|
+
}
|
|
1264
|
+
```
|
|
1265
|
+
|
|
1266
|
+
---
|
|
1267
|
+
|
|
1268
|
+
## Dashboard: Visual Logic Builder
|
|
1269
|
+
|
|
1270
|
+
### Variable Manager
|
|
1271
|
+
|
|
1272
|
+
**Access:** right sidebar → Variables tab, the images entry we made before can also be here.
|
|
1273
|
+
```
|
|
1274
|
+
┌────────────────────────────────┐
|
|
1275
|
+
│ VARIABLES │
|
|
1276
|
+
├────────────────────────────────┤
|
|
1277
|
+
│ 📊 User Input Variables │
|
|
1278
|
+
│ ├─ workout_frequency (string) │
|
|
1279
|
+
│ │ Values: "1-2", "3-4", "5+"│
|
|
1280
|
+
│ │ [Edit] [Delete] │
|
|
1281
|
+
│ │ │
|
|
1282
|
+
│ ├─ sleep_quality (string) │
|
|
1283
|
+
│ │ Values: "good", "poor" │
|
|
1284
|
+
│ │ [Edit] [Delete] │
|
|
1285
|
+
│ │ │
|
|
1286
|
+
│ ├─ age (number) │
|
|
1287
|
+
│ │ Range: 13-120 │
|
|
1288
|
+
│ │ [Edit] [Delete] │
|
|
1289
|
+
│ │ │
|
|
1290
|
+
│ └─ fitness_goals (array) │
|
|
1291
|
+
│ Values: ["lose_weight", │
|
|
1292
|
+
│ "build_muscle"] │
|
|
1293
|
+
│ [Edit] [Delete] │
|
|
1294
|
+
│ │
|
|
1295
|
+
│ 🧮 Computed Variables │
|
|
1296
|
+
│ ├─ bmi (number) │
|
|
1297
|
+
│ │ Formula: weight / height² │
|
|
1298
|
+
│ │ [Edit] [Delete] │
|
|
1299
|
+
│ │ │
|
|
1300
|
+
│ └─ sleep_recommendation (num) │
|
|
1301
|
+
│ Formula: IF(workout...) │
|
|
1302
|
+
│ [Edit] [Delete] │
|
|
1303
|
+
│ │
|
|
1304
|
+
│ [+ Add Variable] │
|
|
1305
|
+
│ │
|
|
1306
|
+
│ ℹ️ System Variables │
|
|
1307
|
+
│ • user.name │
|
|
1308
|
+
│ • user.email │
|
|
1309
|
+
│ • device.platform │
|
|
1310
|
+
│ • current_screen │
|
|
1311
|
+
│ • total_screens │
|
|
1312
|
+
└────────────────────────────────┘
|
|
1313
|
+
```
|
|
1314
|
+
|
|
1315
|
+
---
|
|
1316
|
+
|
|
1317
|
+
### Condition Builder
|
|
1318
|
+
|
|
1319
|
+
**When editing element, click "Add Condition":**
|
|
1320
|
+
```
|
|
1321
|
+
┌─────────────────────────────────────────────┐
|
|
1322
|
+
│ Element Visibility Conditions │
|
|
1323
|
+
├─────────────────────────────────────────────┤
|
|
1324
|
+
│ │
|
|
1325
|
+
│ Show this element when: │
|
|
1326
|
+
│ │
|
|
1327
|
+
│ ● Always show │
|
|
1328
|
+
│ ○ Only if conditions are met │
|
|
1329
|
+
│ │
|
|
1330
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1331
|
+
│ │ Match: ● ALL ○ ANY of these: │ │
|
|
1332
|
+
│ │ │ │
|
|
1333
|
+
│ │ Condition 1: │ │
|
|
1334
|
+
│ │ [workout_frequency ▼] │ │
|
|
1335
|
+
│ │ [equals ▼] │ │
|
|
1336
|
+
│ │ ["3-4"________________] │ │
|
|
1337
|
+
│ │ [× Remove] │ │
|
|
1338
|
+
│ │ │ │
|
|
1339
|
+
│ │ Condition 2: │ │
|
|
1340
|
+
│ │ [sleep_quality ▼] │ │
|
|
1341
|
+
│ │ [equals ▼] │ │
|
|
1342
|
+
│ │ ["poor"________________] │ │
|
|
1343
|
+
│ │ [× Remove] │ │
|
|
1344
|
+
│ │ │ │
|
|
1345
|
+
│ │ [+ Add Condition] │ │
|
|
1346
|
+
│ │ │ │
|
|
1347
|
+
│ │ [Advanced: Nested Logic] │ │
|
|
1348
|
+
│ └───────────────────────────────────────┘ │
|
|
1349
|
+
│ │
|
|
1350
|
+
│ Preview: │
|
|
1351
|
+
│ "This will show for users who selected │
|
|
1352
|
+
│ '3-4' workouts AND 'poor' sleep quality" │
|
|
1353
|
+
│ │
|
|
1354
|
+
│ Estimated reach: ~23% of users │
|
|
1355
|
+
│ │
|
|
1356
|
+
│ [Cancel] [Save Conditions] │
|
|
1357
|
+
└─────────────────────────────────────────────┘
|
|
1358
|
+
```
|
|
1359
|
+
|
|
1360
|
+
---
|
|
1361
|
+
|
|
1362
|
+
### Action Builder
|
|
1363
|
+
|
|
1364
|
+
**When editing button/tappable element:**
|
|
1365
|
+
```
|
|
1366
|
+
┌─────────────────────────────────────────────┐
|
|
1367
|
+
│ On Tap Actions │
|
|
1368
|
+
├─────────────────────────────────────────────┤
|
|
1369
|
+
│ │
|
|
1370
|
+
│ When user taps this element: │
|
|
1371
|
+
│ │
|
|
1372
|
+
│ Action 1: [Set Variable ▼] │
|
|
1373
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1374
|
+
│ │ Variable: [workout_frequency ▼] │ │
|
|
1375
|
+
│ │ Value: ["3-4"________________] │ │
|
|
1376
|
+
│ └───────────────────────────────────────┘ │
|
|
1377
|
+
│ [× Remove] [↑] [↓] │
|
|
1378
|
+
│ │
|
|
1379
|
+
│ Action 2: [Track Event ▼] │
|
|
1380
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1381
|
+
│ │ Event Name: [workout_selected______] │ │
|
|
1382
|
+
│ │ Properties: │ │
|
|
1383
|
+
│ │ frequency: {workout_frequency} │ │
|
|
1384
|
+
│ │ screen: {current_screen} │ │
|
|
1385
|
+
│ └───────────────────────────────────────┘ │
|
|
1386
|
+
│ [× Remove] [↑] [↓] │
|
|
1387
|
+
│ │
|
|
1388
|
+
│ Action 3: [Navigate ▼] │
|
|
1389
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1390
|
+
│ │ ○ Simple: Go to [screen_3 ▼] │ │
|
|
1391
|
+
│ │ ● Conditional Navigation │ │
|
|
1392
|
+
│ │ If: [has_wearable ▼] [= ▼] [true] │ │
|
|
1393
|
+
│ │ Then: [wearable_sync ▼] │ │
|
|
1394
|
+
│ │ Else: [goals_screen ▼] │ │
|
|
1395
|
+
│ └───────────────────────────────────────┘ │
|
|
1396
|
+
│ [× Remove] [↑] [↓] │
|
|
1397
|
+
│ │
|
|
1398
|
+
│ [+ Add Action] │
|
|
1399
|
+
│ │
|
|
1400
|
+
│ [Cancel] [Save Actions] │
|
|
1401
|
+
└─────────────────────────────────────────────┘
|
|
1402
|
+
```
|
|
1403
|
+
|
|
1404
|
+
---
|
|
1405
|
+
|
|
1406
|
+
### AI Content Builder
|
|
1407
|
+
|
|
1408
|
+
**Add AI-generated text element:**
|
|
1409
|
+
```
|
|
1410
|
+
┌─────────────────────────────────────────────┐
|
|
1411
|
+
│ AI-Generated Content │
|
|
1412
|
+
├─────────────────────────────────────────────┤
|
|
1413
|
+
│ │
|
|
1414
|
+
│ Prompt Template: │
|
|
1415
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1416
|
+
│ │ Generate a personalized fitness │ │
|
|
1417
|
+
│ │ recommendation for someone who: │ │
|
|
1418
|
+
│ │ │ │
|
|
1419
|
+
│ │ - Works out {workout_frequency} │ │
|
|
1420
|
+
│ │ times per week │ │
|
|
1421
|
+
│ │ - Has {sleep_quality} sleep quality │ │
|
|
1422
|
+
│ │ - Is {gender} │ │
|
|
1423
|
+
│ │ - Wants to {fitness_goal} │ │
|
|
1424
|
+
│ │ │ │
|
|
1425
|
+
│ │ Keep it under 100 words, actionable, │ │
|
|
1426
|
+
│ │ and motivational. │ │
|
|
1427
|
+
│ └───────────────────────────────────────┘ │
|
|
1428
|
+
│ │
|
|
1429
|
+
│ Insert Variable: [Select variable ▼] │
|
|
1430
|
+
│ │
|
|
1431
|
+
│ AI Model: [GPT-4 Turbo ▼] │
|
|
1432
|
+
│ ○ GPT-4 Turbo ($0.008/gen) │
|
|
1433
|
+
│ ○ Claude 3 Sonnet ($0.004/gen) │
|
|
1434
|
+
│ ○ GPT-3.5 Turbo ($0.001/gen) │
|
|
1435
|
+
│ │
|
|
1436
|
+
│ Settings: │
|
|
1437
|
+
│ Max Length: [100] words │
|
|
1438
|
+
│ Temperature: [0.7] (creativity) │
|
|
1439
|
+
│ Cache Results: ☑ Yes (save 98% cost) │
|
|
1440
|
+
│ Cache Duration: [7] days │
|
|
1441
|
+
│ │
|
|
1442
|
+
│ Loading State: │
|
|
1443
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1444
|
+
│ │ 💭 Creating your personalized plan... │ │
|
|
1445
|
+
│ └───────────────────────────────────────┘ │
|
|
1446
|
+
│ │
|
|
1447
|
+
│ Fallback (if API fails): │
|
|
1448
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1449
|
+
│ │ Based on your goals, we recommend │ │
|
|
1450
|
+
│ │ starting with a balanced routine. │ │
|
|
1451
|
+
│ └───────────────────────────────────────┘ │
|
|
1452
|
+
│ │
|
|
1453
|
+
│ [Preview with Test Data] │
|
|
1454
|
+
│ [Save] │
|
|
1455
|
+
└─────────────────────────────────────────────┘
|
|
1456
|
+
```
|
|
1457
|
+
|
|
1458
|
+
---
|
|
1459
|
+
|
|
1460
|
+
### Test Data Preview
|
|
1461
|
+
|
|
1462
|
+
**Click "Preview with Test Data":**
|
|
1463
|
+
```
|
|
1464
|
+
┌─────────────────────────────────────────────┐
|
|
1465
|
+
│ Test AI-Generated Content │
|
|
1466
|
+
├─────────────────────────────────────────────┤
|
|
1467
|
+
│ │
|
|
1468
|
+
│ Set test values for variables: │
|
|
1469
|
+
│ │
|
|
1470
|
+
│ workout_frequency: ["3-4" ▼] │
|
|
1471
|
+
│ sleep_quality: ["poor" ▼] │
|
|
1472
|
+
│ gender: ["male" ▼] │
|
|
1473
|
+
│ fitness_goal: [build muscle____________] │
|
|
1474
|
+
│ │
|
|
1475
|
+
│ [Generate Preview] (uses real AI API) │
|
|
1476
|
+
│ │
|
|
1477
|
+
│ ✨ Generated Result: │
|
|
1478
|
+
│ ┌───────────────────────────────────────┐ │
|
|
1479
|
+
│ │ As someone training 3-4 times per │ │
|
|
1480
|
+
│ │ week with poor sleep, your muscle │ │
|
|
1481
|
+
│ │ recovery is compromised. Prioritize │ │
|
|
1482
|
+
│ │ 8-9 hours of sleep nightly—this is │ │
|
|
1483
|
+
│ │ when muscle repair happens. Consider │ │
|
|
1484
|
+
│ │ a magnesium supplement 30 minutes │ │
|
|
1485
|
+
│ │ before bed. Reduce training intensity │ │
|
|
1486
|
+
│ │ by 20% until sleep improves to avoid │ │
|
|
1487
|
+
│ │ overtraining. Track your recovery: │ │
|
|
1488
|
+
│ │ if you're sore 48+ hours, you need │ │
|
|
1489
|
+
│ │ more rest. │ │
|
|
1490
|
+
│ └───────────────────────────────────────┘ │
|
|
1491
|
+
│ │
|
|
1492
|
+
│ Cost: $0.008 | Cached for 7 days │
|
|
1493
|
+
│ Estimated monthly cost (1,000 users): $5 │
|
|
1494
|
+
│ │
|
|
1495
|
+
│ [Try Different Values] [Use This Content] │
|
|
1496
|
+
└─────────────────────────────────────────────┘
|
|
1497
|
+
```
|
|
1498
|
+
|
|
1499
|
+
---
|
|
1500
|
+
|
|
1501
|
+
### Flow Debugger
|
|
1502
|
+
|
|
1503
|
+
**View variable values in real-time:**
|
|
1504
|
+
```
|
|
1505
|
+
┌─────────────────────────────────────────────┐
|
|
1506
|
+
│ Flow Debugger │
|
|
1507
|
+
├─────────────────────────────────────────────┤
|
|
1508
|
+
│ │
|
|
1509
|
+
│ Current Screen: screen_4 (Recommendations) │
|
|
1510
|
+
│ │
|
|
1511
|
+
│ 📊 Variable Values: │
|
|
1512
|
+
│ ├─ workout_frequency: "3-4" │
|
|
1513
|
+
│ ├─ sleep_quality: "poor" │
|
|
1514
|
+
│ ├─ gender: "male" │
|
|
1515
|
+
│ ├─ age: 28 │
|
|
1516
|
+
│ ├─ fitness_goals: ["build_muscle"] │
|
|
1517
|
+
│ ├─ has_wearable: false │
|
|
1518
|
+
│ └─ bmi: 24.2 (computed) │
|
|
1519
|
+
│ │
|
|
1520
|
+
│ 🎯 Active Conditions: │
|
|
1521
|
+
│ ├─ ✅ Showing: "Advanced recommendation" │
|
|
1522
|
+
│ │ Condition: workout_frequency = "3-4" │
|
|
1523
|
+
│ │ AND sleep_quality = "poor" │
|
|
1524
|
+
│ │ │
|
|
1525
|
+
│ ├─ ❌ Hidden: "Beginner recommendation" │
|
|
1526
|
+
│ │ Condition: workout_frequency = "1-2" │
|
|
1527
|
+
│ │ (not met) │
|
|
1528
|
+
│ │ │
|
|
1529
|
+
│ └─ ✅ Showing: AI-generated content │
|
|
1530
|
+
│ Cached result (generated 2 days ago) │
|
|
1531
|
+
│ │
|
|
1532
|
+
│ 🔄 Recent Actions: │
|
|
1533
|
+
│ 1. Set workout_frequency = "3-4" │
|
|
1534
|
+
│ 2. Tracked event: workout_selected │
|
|
1535
|
+
│ 3. Set sleep_quality = "poor" │
|
|
1536
|
+
│ 4. Navigated to screen_4 │
|
|
1537
|
+
│ │
|
|
1538
|
+
│ [Reset Variables] [Step Back] [Export Log] │
|
|
1539
|
+
└─────────────────────────────────────────────┘
|
|
1540
|
+
```
|
|
1541
|
+
|
|
1542
|
+
---
|
|
1543
|
+
|
|
1544
|
+
## Examples & Use Cases
|
|
1545
|
+
|
|
1546
|
+
### Example 1: Fitness App Onboarding
|
|
1547
|
+
|
|
1548
|
+
**Goal:** Personalized workout plan based on user profile
|
|
1549
|
+
|
|
1550
|
+
**Screen 1: Workout Frequency**
|
|
1551
|
+
```json
|
|
1552
|
+
{
|
|
1553
|
+
"type": "vstack",
|
|
1554
|
+
"spacing": 16,
|
|
1555
|
+
"elements": [
|
|
1556
|
+
{
|
|
1557
|
+
"type": "text",
|
|
1558
|
+
"content": "How often do you work out?",
|
|
1559
|
+
"fontSize": 24,
|
|
1560
|
+
"fontWeight": "bold"
|
|
1561
|
+
},
|
|
1562
|
+
{
|
|
1563
|
+
"type": "hstack",
|
|
1564
|
+
"background": "#F5F5F5",
|
|
1565
|
+
"padding": 16,
|
|
1566
|
+
"borderRadius": 8,
|
|
1567
|
+
"onTap": {
|
|
1568
|
+
"actions": [
|
|
1569
|
+
{"action": "set_variable", "variable": "workout_frequency", "value": "1-2"},
|
|
1570
|
+
{"action": "navigate", "next_screen": "sleep_screen"}
|
|
1571
|
+
]
|
|
1572
|
+
},
|
|
1573
|
+
"elements": [
|
|
1574
|
+
{"type": "text", "content": "1-2 times per week"}
|
|
1575
|
+
]
|
|
1576
|
+
},
|
|
1577
|
+
{
|
|
1578
|
+
"type": "hstack",
|
|
1579
|
+
"background": "#F5F5F5",
|
|
1580
|
+
"padding": 16,
|
|
1581
|
+
"borderRadius": 8,
|
|
1582
|
+
"onTap": {
|
|
1583
|
+
"actions": [
|
|
1584
|
+
{"action": "set_variable", "variable": "workout_frequency", "value": "3-4"},
|
|
1585
|
+
{"action": "navigate", "next_screen": "sleep_screen"}
|
|
1586
|
+
]
|
|
1587
|
+
},
|
|
1588
|
+
"elements": [
|
|
1589
|
+
{"type": "text", "content": "3-4 times per week"}
|
|
1590
|
+
]
|
|
1591
|
+
},
|
|
1592
|
+
{
|
|
1593
|
+
"type": "hstack",
|
|
1594
|
+
"background": "#F5F5F5",
|
|
1595
|
+
"padding": 16,
|
|
1596
|
+
"borderRadius": 8,
|
|
1597
|
+
"onTap": {
|
|
1598
|
+
"actions": [
|
|
1599
|
+
{"action": "set_variable", "variable": "workout_frequency", "value": "5+"},
|
|
1600
|
+
{"action": "navigate", "next_screen": "sleep_screen"}
|
|
1601
|
+
]
|
|
1602
|
+
},
|
|
1603
|
+
"elements": [
|
|
1604
|
+
{"type": "text", "content": "5+ times per week"}
|
|
1605
|
+
]
|
|
1606
|
+
}
|
|
1607
|
+
]
|
|
1608
|
+
}
|
|
1609
|
+
```
|
|
1610
|
+
|
|
1611
|
+
**Screen 2: Sleep Quality**
|
|
1612
|
+
```json
|
|
1613
|
+
{
|
|
1614
|
+
"type": "vstack",
|
|
1615
|
+
"spacing": 16,
|
|
1616
|
+
"elements": [
|
|
1617
|
+
{
|
|
1618
|
+
"type": "text",
|
|
1619
|
+
"content": "How's your sleep quality?",
|
|
1620
|
+
"fontSize": 24
|
|
1621
|
+
},
|
|
1622
|
+
{
|
|
1623
|
+
"type": "hstack",
|
|
1624
|
+
"onTap": {
|
|
1625
|
+
"actions": [
|
|
1626
|
+
{"action": "set_variable", "variable": "sleep_quality", "value": "good"},
|
|
1627
|
+
{"action": "navigate", "next_screen": "recommendations"}
|
|
1628
|
+
]
|
|
1629
|
+
},
|
|
1630
|
+
"elements": [{"type": "text", "content": "Good (7-9 hours)"}]
|
|
1631
|
+
},
|
|
1632
|
+
{
|
|
1633
|
+
"type": "hstack",
|
|
1634
|
+
"onTap": {
|
|
1635
|
+
"actions": [
|
|
1636
|
+
{"action": "set_variable", "variable": "sleep_quality", "value": "poor"},
|
|
1637
|
+
{"action": "navigate", "next_screen": "recommendations"}
|
|
1638
|
+
]
|
|
1639
|
+
},
|
|
1640
|
+
"elements": [{"type": "text", "content": "Poor (< 7 hours)"}]
|
|
1641
|
+
}
|
|
1642
|
+
]
|
|
1643
|
+
}
|
|
1644
|
+
```
|
|
1645
|
+
|
|
1646
|
+
**Screen 3: AI-Powered Recommendations**
|
|
1647
|
+
```json
|
|
1648
|
+
{
|
|
1649
|
+
"type": "vstack",
|
|
1650
|
+
"spacing": 24,
|
|
1651
|
+
"padding": 20,
|
|
1652
|
+
"elements": [
|
|
1653
|
+
{
|
|
1654
|
+
"type": "text",
|
|
1655
|
+
"content": "Your Personalized Plan",
|
|
1656
|
+
"fontSize": 28,
|
|
1657
|
+
"fontWeight": "bold"
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
"type": "ai_generated_text",
|
|
1661
|
+
"prompt": "Generate a personalized fitness recommendation for someone who works out {workout_frequency} times per week and has {sleep_quality} sleep quality. Include specific sleep recommendations, recovery tips, and workout intensity guidance. Keep it under 100 words and actionable.",
|
|
1662
|
+
"model": "gpt-4-turbo",
|
|
1663
|
+
"cache": true,
|
|
1664
|
+
"loading_text": "Creating your personalized plan...",
|
|
1665
|
+
"fallback_text": "Based on your activity level and sleep patterns, focus on balanced training and prioritize 7-9 hours of sleep for optimal recovery."
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
"type": "button",
|
|
1669
|
+
"text": "Start Your Journey",
|
|
1670
|
+
"onTap": {"action": "navigate", "next_screen": "complete"}
|
|
1671
|
+
}
|
|
1672
|
+
]
|
|
1673
|
+
}
|
|
1674
|
+
```
|
|
1675
|
+
|
|
1676
|
+
---
|
|
1677
|
+
|
|
1678
|
+
### Example 2: E-commerce Product Recommendations
|
|
1679
|
+
|
|
1680
|
+
**Screen 1: Style Preference**
|
|
1681
|
+
```json
|
|
1682
|
+
{
|
|
1683
|
+
"type": "vstack",
|
|
1684
|
+
"elements": [
|
|
1685
|
+
{
|
|
1686
|
+
"type": "text",
|
|
1687
|
+
"content": "What's your style?",
|
|
1688
|
+
"fontSize": 24
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
"type": "hstack",
|
|
1692
|
+
"onTap": {
|
|
1693
|
+
"action": "set_variable",
|
|
1694
|
+
"variable": "style_preference",
|
|
1695
|
+
"value": "minimalist"
|
|
1696
|
+
},
|
|
1697
|
+
"elements": [{"type": "text", "content": "Minimalist"}]
|
|
1698
|
+
},
|
|
1699
|
+
{
|
|
1700
|
+
"type": "hstack",
|
|
1701
|
+
"onTap": {
|
|
1702
|
+
"action": "set_variable",
|
|
1703
|
+
"variable": "style_preference",
|
|
1704
|
+
"value": "bold"
|
|
1705
|
+
},
|
|
1706
|
+
"elements": [{"type": "text", "content": "Bold & Colorful"}]
|
|
1707
|
+
}
|
|
1708
|
+
]
|
|
1709
|
+
}
|
|
1710
|
+
```
|
|
1711
|
+
|
|
1712
|
+
**Screen 2: Conditional Product Display**
|
|
1713
|
+
```json
|
|
1714
|
+
{
|
|
1715
|
+
"type": "vstack",
|
|
1716
|
+
"elements": [
|
|
1717
|
+
{
|
|
1718
|
+
"type": "text",
|
|
1719
|
+
"content": "Recommended for You"
|
|
1720
|
+
},
|
|
1721
|
+
{
|
|
1722
|
+
"type": "vstack",
|
|
1723
|
+
"conditions": {
|
|
1724
|
+
"show_if": {
|
|
1725
|
+
"variable": "style_preference",
|
|
1726
|
+
"equals": "minimalist"
|
|
1727
|
+
}
|
|
1728
|
+
},
|
|
1729
|
+
"elements": [
|
|
1730
|
+
{"type": "image", "source": "minimalist_product_1.jpg"},
|
|
1731
|
+
{"type": "text", "content": "Clean Lines Tee - $29"}
|
|
1732
|
+
]
|
|
1733
|
+
},
|
|
1734
|
+
{
|
|
1735
|
+
"type": "vstack",
|
|
1736
|
+
"conditions": {
|
|
1737
|
+
"show_if": {
|
|
1738
|
+
"variable": "style_preference",
|
|
1739
|
+
"equals": "bold"
|
|
1740
|
+
}
|
|
1741
|
+
},
|
|
1742
|
+
"elements": [
|
|
1743
|
+
{"type": "image", "source": "bold_product_1.jpg"},
|
|
1744
|
+
{"type": "text", "content": "Vibrant Pattern Tee - $35"}
|
|
1745
|
+
]
|
|
1746
|
+
}
|
|
1747
|
+
]
|
|
1748
|
+
}
|
|
1749
|
+
```
|
|
1750
|
+
|
|
1751
|
+
---
|
|
1752
|
+
|
|
1753
|
+
### Example 3: Conditional Screen Skip
|
|
1754
|
+
|
|
1755
|
+
**Skip wearable sync if user doesn't have one:**
|
|
1756
|
+
```json
|
|
1757
|
+
{
|
|
1758
|
+
"type": "vstack",
|
|
1759
|
+
"elements": [
|
|
1760
|
+
{
|
|
1761
|
+
"type": "text",
|
|
1762
|
+
"content": "Do you have a fitness tracker?"
|
|
1763
|
+
},
|
|
1764
|
+
{
|
|
1765
|
+
"type": "hstack",
|
|
1766
|
+
"onTap": {
|
|
1767
|
+
"actions": [
|
|
1768
|
+
{"action": "set_variable", "variable": "has_wearable", "value": true},
|
|
1769
|
+
{"action": "navigate", "next_screen": "wearable_sync"}
|
|
1770
|
+
]
|
|
1771
|
+
},
|
|
1772
|
+
"elements": [{"type": "text", "content": "Yes"}]
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
"type": "hstack",
|
|
1776
|
+
"onTap": {
|
|
1777
|
+
"actions": [
|
|
1778
|
+
{"action": "set_variable", "variable": "has_wearable", "value": false},
|
|
1779
|
+
{"action": "navigate", "next_screen": "goals_screen"}
|
|
1780
|
+
]
|
|
1781
|
+
},
|
|
1782
|
+
"elements": [{"type": "text", "content": "No"}]
|
|
1783
|
+
}
|
|
1784
|
+
]
|
|
1785
|
+
}
|
|
1786
|
+
```
|
|
1787
|
+
|
|
1788
|
+
**Result:**
|
|
1789
|
+
- User has wearable → Goes to wearable_sync screen
|
|
1790
|
+
- User doesn't have wearable → Skips wearable_sync, goes straight to goals
|
|
1791
|
+
|
|
1792
|
+
---
|
|
1793
|
+
|
|
1794
|
+
### Example 4: Multi-Select with Array Variables
|
|
1795
|
+
```json
|
|
1796
|
+
{
|
|
1797
|
+
"type": "vstack",
|
|
1798
|
+
"elements": [
|
|
1799
|
+
{
|
|
1800
|
+
"type": "text",
|
|
1801
|
+
"content": "Select all that apply:"
|
|
1802
|
+
},
|
|
1803
|
+
{
|
|
1804
|
+
"type": "hstack",
|
|
1805
|
+
"background": "{fitness_goals.includes('lose_weight') ? '#FF6B6B' : '#F5F5F5'}",
|
|
1806
|
+
"onTap": {
|
|
1807
|
+
"action": "conditional",
|
|
1808
|
+
"if": {
|
|
1809
|
+
"variable": "fitness_goals",
|
|
1810
|
+
"contains": "lose_weight"
|
|
1811
|
+
},
|
|
1812
|
+
"then": {
|
|
1813
|
+
"action": "remove",
|
|
1814
|
+
"variable": "fitness_goals",
|
|
1815
|
+
"value": "lose_weight"
|
|
1816
|
+
},
|
|
1817
|
+
"else": {
|
|
1818
|
+
"action": "append",
|
|
1819
|
+
"variable": "fitness_goals",
|
|
1820
|
+
"value": "lose_weight"
|
|
1821
|
+
}
|
|
1822
|
+
},
|
|
1823
|
+
"elements": [
|
|
1824
|
+
{"type": "text", "content": "Lose Weight"}
|
|
1825
|
+
]
|
|
1826
|
+
},
|
|
1827
|
+
{
|
|
1828
|
+
"type": "hstack",
|
|
1829
|
+
"background": "{fitness_goals.includes('build_muscle') ? '#FF6B6B' : '#F5F5F5'}",
|
|
1830
|
+
"onTap": {
|
|
1831
|
+
"action": "conditional",
|
|
1832
|
+
"if": {
|
|
1833
|
+
"variable": "fitness_goals",
|
|
1834
|
+
"contains": "build_muscle"
|
|
1835
|
+
},
|
|
1836
|
+
"then": {
|
|
1837
|
+
"action": "remove",
|
|
1838
|
+
"variable": "fitness_goals",
|
|
1839
|
+
"value": "build_muscle"
|
|
1840
|
+
},
|
|
1841
|
+
"else": {
|
|
1842
|
+
"action": "append",
|
|
1843
|
+
"variable": "fitness_goals",
|
|
1844
|
+
"value": "build_muscle"
|
|
1845
|
+
}
|
|
1846
|
+
},
|
|
1847
|
+
"elements": [
|
|
1848
|
+
{"type": "text", "content": "Build Muscle"}
|
|
1849
|
+
]
|
|
1850
|
+
}
|
|
1851
|
+
]
|
|
1852
|
+
}
|
|
1853
|
+
```
|
|
1854
|
+
|
|
1855
|
+
---
|
|
1856
|
+
|
|
1857
|
+
## Best Practices
|
|
1858
|
+
|
|
1859
|
+
### 1. Keep Logic Simple
|
|
1860
|
+
|
|
1861
|
+
❌ **Don't:**
|
|
1862
|
+
```json
|
|
1863
|
+
{
|
|
1864
|
+
"all": [
|
|
1865
|
+
{
|
|
1866
|
+
"any": [
|
|
1867
|
+
{"variable": "a", "equals": 1},
|
|
1868
|
+
{
|
|
1869
|
+
"all": [
|
|
1870
|
+
{"variable": "b", "equals": 2},
|
|
1871
|
+
{"variable": "c", "equals": 3}
|
|
1872
|
+
]
|
|
1873
|
+
}
|
|
1874
|
+
]
|
|
1875
|
+
},
|
|
1876
|
+
{
|
|
1877
|
+
"not": {
|
|
1878
|
+
"any": [
|
|
1879
|
+
{"variable": "d", "equals": 4},
|
|
1880
|
+
{"variable": "e", "equals": 5}
|
|
1881
|
+
]
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
]
|
|
1885
|
+
}
|
|
1886
|
+
```
|
|
1887
|
+
**Too complex. Hard to debug.**
|
|
1888
|
+
|
|
1889
|
+
✅ **Do:**
|
|
1890
|
+
```json
|
|
1891
|
+
{
|
|
1892
|
+
"all": [
|
|
1893
|
+
{"variable": "workout_frequency", "equals": "3-4"},
|
|
1894
|
+
{"variable": "sleep_quality", "equals": "poor"}
|
|
1895
|
+
]
|
|
1896
|
+
}
|
|
1897
|
+
```
|
|
1898
|
+
**Simple, clear, easy to understand.**
|
|
1899
|
+
|
|
1900
|
+
---
|
|
1901
|
+
|
|
1902
|
+
### 2. Use Computed Variables for Complex Logic
|
|
1903
|
+
|
|
1904
|
+
❌ **Don't:**
|
|
1905
|
+
Repeat complex formulas everywhere:
|
|
1906
|
+
```json
|
|
1907
|
+
{
|
|
1908
|
+
"content": "Your BMI is {weight_kg / (height_m * height_m)}"
|
|
1909
|
+
}
|
|
1910
|
+
```
|
|
1911
|
+
|
|
1912
|
+
✅ **Do:**
|
|
1913
|
+
Define computed variable once:
|
|
1914
|
+
```json
|
|
1915
|
+
{
|
|
1916
|
+
"computed_variables": {
|
|
1917
|
+
"bmi": {
|
|
1918
|
+
"type": "formula",
|
|
1919
|
+
"formula": "weight_kg / (height_m * height_m)"
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
```
|
|
1924
|
+
Then use everywhere:
|
|
1925
|
+
```json
|
|
1926
|
+
{
|
|
1927
|
+
"content": "Your BMI is {bmi}"
|
|
1928
|
+
}
|
|
1929
|
+
```
|
|
1930
|
+
|
|
1931
|
+
---
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
|
|
1935
|
+
---
|
|
1936
|
+
|
|
1937
|
+
### 4. Cache AI Content
|
|
1938
|
+
|
|
1939
|
+
❌ **Don't:**
|
|
1940
|
+
```json
|
|
1941
|
+
{
|
|
1942
|
+
"type": "ai_generated_text",
|
|
1943
|
+
"cache": false
|
|
1944
|
+
}
|
|
1945
|
+
```
|
|
1946
|
+
**Costs $0.008 per user. 1,000 users = $8/day = $240/month**
|
|
1947
|
+
|
|
1948
|
+
✅ **Do:**
|
|
1949
|
+
```json
|
|
1950
|
+
{
|
|
1951
|
+
"type": "ai_generated_text",
|
|
1952
|
+
"cache": true,
|
|
1953
|
+
"cache_duration": 7
|
|
1954
|
+
}
|
|
1955
|
+
```
|
|
1956
|
+
**Costs $0.008 × 50 unique combinations = $0.40 total**
|
|
1957
|
+
|
|
1958
|
+
---
|
|
1959
|
+
|
|
1960
|
+
### 5. Use Meaningful Variable Names
|
|
1961
|
+
|
|
1962
|
+
❌ **Don't:**
|
|
1963
|
+
```json
|
|
1964
|
+
{
|
|
1965
|
+
"variable": "var1",
|
|
1966
|
+
"value": "val1"
|
|
1967
|
+
}
|
|
1968
|
+
```
|
|
1969
|
+
|
|
1970
|
+
✅ **Do:**
|
|
1971
|
+
```json
|
|
1972
|
+
{
|
|
1973
|
+
"variable": "workout_frequency",
|
|
1974
|
+
"value": "3-4"
|
|
1975
|
+
}
|
|
1976
|
+
```
|
|
1977
|
+
|
|
1978
|
+
---
|
|
1979
|
+
|
|
1980
|
+
### 6. Test All Paths
|
|
1981
|
+
|
|
1982
|
+
**Use the Flow Debugger to test:**
|
|
1983
|
+
- All combinations of user selections
|
|
1984
|
+
- Edge cases (empty arrays, null values)
|
|
1985
|
+
- Conditional navigation paths
|
|
1986
|
+
- AI content generation with different variables
|
|
1987
|
+
|
|
1988
|
+
---
|
|
1989
|
+
|
|
1990
|
+
### 7. Track Analytics for Logic Paths
|
|
1991
|
+
```json
|
|
1992
|
+
{
|
|
1993
|
+
"onTap": {
|
|
1994
|
+
"actions": [
|
|
1995
|
+
{"action": "set_variable", "variable": "choice", "value": "A"},
|
|
1996
|
+
{
|
|
1997
|
+
"action": "track_event",
|
|
1998
|
+
"event_name": "logic_path_taken",
|
|
1999
|
+
"properties": {
|
|
2000
|
+
"choice": "A",
|
|
2001
|
+
"screen": "{current_screen}"
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
]
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
```
|
|
2008
|
+
|
|
2009
|
+
**Then analyze which paths users take most often.**
|
|
2010
|
+
|
|
2011
|
+
---
|
|
2012
|
+
|
|
2013
|
+
### 8. Progressive Disclosure
|
|
2014
|
+
|
|
2015
|
+
Don't overwhelm users with too many choices upfront.
|
|
2016
|
+
|
|
2017
|
+
❌ **Don't:**
|
|
2018
|
+
```
|
|
2019
|
+
Screen 1: 10 questions all at once
|
|
2020
|
+
```
|
|
2021
|
+
|
|
2022
|
+
✅ **Do:**
|
|
2023
|
+
```
|
|
2024
|
+
Screen 1: Basic info (2-3 questions)
|
|
2025
|
+
Screen 2: More details (conditional based on Screen 1)
|
|
2026
|
+
Screen 3: Advanced (only if needed)
|
|
2027
|
+
```
|
|
2028
|
+
|
|
2029
|
+
---
|
|
2030
|
+
|
|
2031
|
+
### 9. Validate User Input
|
|
2032
|
+
```json
|
|
2033
|
+
{
|
|
2034
|
+
"type": "button",
|
|
2035
|
+
"text": "Continue",
|
|
2036
|
+
"onTap": {
|
|
2037
|
+
"action": "conditional",
|
|
2038
|
+
"if": {
|
|
2039
|
+
"variable": "fitness_goals",
|
|
2040
|
+
"is_empty": true
|
|
2041
|
+
},
|
|
2042
|
+
"then": {
|
|
2043
|
+
"action": "show_error",
|
|
2044
|
+
"message": "Please select at least one goal"
|
|
2045
|
+
},
|
|
2046
|
+
"else": {
|
|
2047
|
+
"action": "navigate",
|
|
2048
|
+
"next_screen": "next"
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
```
|
|
2053
|
+
|
|
2054
|
+
---
|
|
2055
|
+
|
|
2056
|
+
### 10. Document Your Logic
|
|
2057
|
+
|
|
2058
|
+
**Add comments in JSON (for your reference in dashboard):**
|
|
2059
|
+
```json
|
|
2060
|
+
{
|
|
2061
|
+
"_comment": "This screen shows different content for beginners vs advanced users based on workout_frequency and fitness_level variables",
|
|
2062
|
+
"type": "vstack",
|
|
2063
|
+
"elements": [...]
|
|
2064
|
+
}
|
|
2065
|
+
```
|
|
2066
|
+
|
|
2067
|
+
---
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
|
|
2071
|
+
---
|
|
2072
|
+
|
|
2073
|
+
## Support & Resources
|
|
2074
|
+
|
|
2075
|
+
<!-- ### Documentation
|
|
2076
|
+
- [Variable System Guide](./variables-guide.md)
|
|
2077
|
+
- [Conditional Logic Cookbook](./logic-cookbook.md)
|
|
2078
|
+
- [AI Content Best Practices](./ai-content-guide.md)
|
|
2079
|
+
- [Formula Reference](./formula-reference.md)
|
|
2080
|
+
|
|
2081
|
+
### Examples
|
|
2082
|
+
- [Fitness App Logic Flow](./examples/fitness-app.md)
|
|
2083
|
+
- [E-commerce Personalization](./examples/ecommerce.md)
|
|
2084
|
+
- [Healthcare Recommendations](./examples/healthcare.md)
|
|
2085
|
+
|
|
2086
|
+
### Community
|
|
2087
|
+
- Discord: chat.yourplatform.com/#logic
|
|
2088
|
+
- Gallery: gallery.yourplatform.com/logic
|
|
2089
|
+
- Blog: blog.yourplatform.com/logic-systems -->
|
|
2090
|
+
|
|
2091
|
+
---
|
|
2092
|
+
|
|
2093
|
+
**The Logic System transforms your onboarding from static to intelligent. Build flows that adapt to each user, generate personalized content with AI, and create experiences that convert.**
|
|
2094
|
+
|
|
2095
|
+
🚀 **Start building intelligent onboarding today.**
|