# Install

Add the Screeb SDK to your app and start it with your channel id, so surveys, messages and session replay can run.

Install the Screeb SDK once, at the start of your app, with the channel id of your workspace. Until a user is identified, Screeb tracks them as an anonymous visitor: see [Identity](https://developers.screeb.app/sdk-flutter/identity) to attach your own user id.

Your channel id is on the [Install page of your workspace settings](https://admin.screeb.app/org/last/settings/install). The steps on the admin side are in the help center: [Install Screeb on your website](https://help.screeb.app/install/install-web/) and [Install Screeb in your mobile app](https://help.screeb.app/install/install-mobile/).

> [!TIP]
> Turn the SDK off in your CI and end-to-end test runs. Every run creates new anonymous users, which count toward your monthly tracked users.

## Requirements

- iOS 15.0 or later and Swift 5.9 or later for the iOS SDK. Android API 21 or later, compileSdk 35 and Kotlin 2.1 or later for the Android SDK.
- Flutter 3.19 or later. Kotlin Multiplatform: Kotlin 2.1.0 or later, Android minSdk 21, iOS 15. .NET MAUI: Android API 24 and iOS 15.
- The SDK adds about 450 KB to an iOS release app and about 110 KB to an Android one. The iOS SDK has no third-party dependency.

## Add the SDK to your project

```sh
flutter pub add plugin_screeb
```

After you upgrade the SDK, run `pod update Screeb` in your `ios/` directory (or at the root of a native iOS project) to pull the new iOS version.

## Start the SDK

```dart
import 'package:flutter/material.dart';
import 'package:plugin_screeb/plugin_screeb.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  PluginScreeb.initSdk("<YOUR-CHANNEL-ID>");
  runApp(const MyApp());
}
```

Start the SDK once, when the app launches. When the user is already logged in at that point, pass their user id and properties too, so Screeb never creates an anonymous visitor for them (see [Identity](https://developers.screeb.app/sdk-flutter/identity)).

## Declare permissions

The SDK needs network access. Audio and video answers, and photos taken from a survey, also need the camera and the microphone.

```xml
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Only for audio and video answers -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
```

```xml
<!-- Info.plist, only for audio and video answers -->
<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to record video answers.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to the microphone to record audio answers.</string>
```

On iOS, a video answer asks for both the camera and the microphone, and refusing either one makes it fail. Without these two keys, iOS turns audio and video answers off: respondents never see those buttons. Once a respondent refuses, iOS never asks again, so Screeb hides the buttons. Picking an existing image from the photo library needs no permission.

## Open the app from the message editor

The Screeb in-app message editor opens your app through a deep link on the `screeb-<YOUR-CHANNEL-ID>` scheme. Declare the scheme, then forward the links to the SDK.

```xml
<!-- Info.plist -->
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Viewer</string>
    <key>CFBundleURLName</key>
    <string>screeb</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>screeb-<YOUR-CHANNEL-ID></string>
    </array>
  </dict>
</array>
```

```xml
<!-- AndroidManifest.xml, inside your main <activity> -->
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="screeb-<YOUR-CHANNEL-ID>" />
</intent-filter>
```

```swift
import Screeb

// AppDelegate
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
    Screeb.handleDeepLink(url: url)
    return true
}

// Or SceneDelegate, when your app has one
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    Screeb.handleDeepLink(url: URLContexts.first?.url)
}
```

```kotlin
// MainActivity.kt
import app.screeb.sdk.Screeb

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    Screeb.handleDeepLink(intent)
}

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    Screeb.handleDeepLink(intent)
}
```

## Stop the SDK

Stop Screeb at any time, for example when the user withdraws consent. It stays off until you start it again.

```dart
await PluginScreeb.closeSdk();
```

## Next steps

- [Identify your users](https://developers.screeb.app/sdk-flutter/identity) to follow them across devices and target surveys on their properties.
- [Track events](https://developers.screeb.app/sdk-flutter/event-tracking) to trigger surveys and messages on what users do.
- [Start a survey from your code](https://developers.screeb.app/sdk-flutter/start-survey-programmatically) when the targeting rules are not enough.
