# Session & Data Saving

Control session saving and data upload. **Applies to: any flow ending on the results screen** (Workout player and Challenge).

| Parameter | Type | Default | Applies to | What it does internally |
|-----------|------|---------|------------|-------------------------|
| shouldSendStats | boolean | false (true for AI Trainer) | Workout player, Challenge | Saves the completed session to the KinesteX backend: per-exercise stats, accuracy scores, calories and the motion recording (used for session replay). Saved sessions are available in the [Workout Sessions API](/docs/trainer-api/trainer-api-workout-sessions). For AI Trainer launches the default is `true` so the chat can show the completed-workout card. Send a boolean by postMessage or inside `?data=` |

**Messages posted to the host during saving:**
- `workout_session_saved`: the session was stored (includes the session ID and scores)
- `motion_upload_progress`: motion-recording upload progress
- `session_save_complete`: everything (session and motion data) finished uploading
- `motion_upload_error`: the motion upload failed or timed out

**Offline behavior:** if saving fails (e.g. no connectivity), the result is queued on the device and retried when the connection returns or on the next launch. A successful retry sends `workout_session_saved` (and `plan_progression_saved` for plan workouts) only, without the motion-upload messages.

**Note:** independent of this flag, the results screen always posts the `workout_overview` / `exercise_overview` summaries to the host. `shouldSendStats` only controls **backend persistence**. With `motionDataEnabled: false`, the saved session has no replay data.

**Session Saving Configuration**

_Swift (iOS)_
```swift
kinestex.createWorkoutView(
    workout: "Full Body Burn",
    user: nil,
    style: nil,
    isLoading: $isLoading,
    customParams: [
        "shouldSendStats": true
    ],
    onMessageReceived: { message in /* ... */ }
)
```

_Kotlin (Android)_
```kotlin
KinesteXSDK.createWorkoutView(
    context = this,
    workoutName = "Full Body Burn",
    customParams = mutableMapOf(
        "shouldSendStats" to true
    ),
    isLoading = viewModel.isLoading,
    onMessageReceived = { message -> handleWebViewMessage(message) },
    permissionHandler = this
)
```

_React Native_
```jsx
const postData: IPostData = {
  key: 'YOUR_API_KEY',
  userId: 'user-123',
  company: 'YOUR_COMPANY',
  customParameters: {
    shouldSendStats: true,
  },
};
```

_Flutter_
```dart
KinesteXAIFramework.createWorkoutView(
  workoutName: "Full Body Burn",
  customParams: {
    "shouldSendStats": true,
  },
  isShowKinestex: showKinesteX,
  isLoading: isLoading,
  onMessageReceived: handleMessage,
);
```

_HTML / JavaScript_
```html
const postData = {
  userId: "user-123",
  company: "YOUR_COMPANY",
  key: "YOUR_API_KEY",
  shouldSendStats: true,
};
```

_React (TypeScript)_
```tsx
const postData: IPostData = {
  key: 'YOUR_API_KEY',
  userId: 'user-123',
  company: 'YOUR_COMPANY',
  customParameters: {
    shouldSendStats: true,
  },
};
```

---
Source: https://www.kinestex.com/docs/customization-parameters/session-data · Index: https://www.kinestex.com/llms.txt
