# Reference

Every public method of Screeb KMP SDK, with its signature.

Complete reference for the Screeb Kotlin Multiplatform SDK. New to Screeb? Start with the [install guide](https://developers.screeb.app/sdk-kmp/install).

## Methods by capability

### Lifecycle

| Method                                                                                                                                                                                             | Description                | More                                                   |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------ |
| `initSdk(channelId: String, userId: String? = null, properties: Map<String, Any>? = null, hooks: ScreebHooks? = null, initOptions: ScreebInitOptions? = null, language: String? = null): Boolean?` | Initialize the Screeb SDK. | [Guide](https://developers.screeb.app/sdk-kmp/install) |
| `closeSdk(): Boolean?`                                                                                                                                                                             | Stop the SDK.              | [Guide](https://developers.screeb.app/sdk-kmp/install) |

### Identity

| Method                                                                        | Description                                                                                                                                                                                                                                       | More                                                                             |
| ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `setIdentity(userId: String, properties: Map<String, Any>? = null): Boolean?` | Identify the current user with optional properties.                                                                                                                                                                                               | [Guide](https://developers.screeb.app/sdk-kmp/identity)                          |
| `setProperties(properties: Map<String, Any>? = null): Boolean?`               | Send visitor properties without changing the identity.                                                                                                                                                                                            | [Guide](https://developers.screeb.app/sdk-kmp/identity)                          |
| `resetIdentity(): Boolean?`                                                   | Reset the current visitor identity.                                                                                                                                                                                                               | [Guide](https://developers.screeb.app/sdk-kmp/identity)                          |
| `setAnonymousId(anonymousId: String): Boolean?`                               | Adopts the anonymous id your CDP already uses (Amplitude device id, Segment or RudderStack anonymous id) on the current respondent, which stays anonymous. Call it right after \[initSdk]: the call is resolved during init. 5 to 128 characters. | [Guide](https://developers.screeb.app/sdk-kmp/identity#2-share-one-anonymous-id) |
| `getIdentity(): Map<String, Any>?`                                            | Get the current visitor identity and properties.                                                                                                                                                                                                  | [Guide](https://developers.screeb.app/sdk-kmp/identity)                          |

### Groups

| Method                                                                                                        | Description                           | More                                                             |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ---------------------------------------------------------------- |
| `assignGroup(groupType: String? = null, groupName: String, properties: Map<String, Any>? = null): Boolean?`   | Assign the current user to a group.   | [Guide](https://developers.screeb.app/sdk-kmp/group-assignation) |
| `unassignGroup(groupType: String? = null, groupName: String, properties: Map<String, Any>? = null): Boolean?` | Remove the current user from a group. | [Guide](https://developers.screeb.app/sdk-kmp/group-assignation) |

### Tracking

| Method                                                                      | Description                      | More                                                           |
| --------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------------- |
| `trackEvent(name: String, properties: Map<String, Any>? = null): Boolean?`  | Track a custom event.            | [Guide](https://developers.screeb.app/sdk-kmp/event-tracking)  |
| `trackScreen(name: String, properties: Map<String, Any>? = null): Boolean?` | Track a screen navigation event. | [Guide](https://developers.screeb.app/sdk-kmp/screen-tracking) |

### Surveys

| Method                                                                                                                                                                                                                                              | Description                               | More                                                                         |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ---------------------------------------------------------------------------- |
| `startSurvey(surveyId: String, allowMultipleResponses: Boolean = true, hiddenFields: Map<String, Any>? = null, ignoreSurveyStatus: Boolean = true, hooks: ScreebHooks? = null, language: String? = null, distributionId: String? = null): Boolean?` | Start a specific survey programmatically. | [Guide](https://developers.screeb.app/sdk-kmp/start-survey-programmatically) |
| `closeSurvey(surveyId: String? = null): Boolean?`                                                                                                                                                                                                   | Close the currently displayed survey.     | -                                                                            |

### Messages

| Method                                                                                                                                                                                                                                                 | Description                                | More                                                                          |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | ----------------------------------------------------------------------------- |
| `startMessage(messageId: String, allowMultipleResponses: Boolean = true, hiddenFields: Map<String, Any>? = null, ignoreMessageStatus: Boolean = true, hooks: ScreebHooks? = null, language: String? = null, distributionId: String? = null): Boolean?` | Start a specific message programmatically. | [Guide](https://developers.screeb.app/sdk-kmp/start-message-programmatically) |
| `closeMessage(messageId: String? = null): Boolean?`                                                                                                                                                                                                    | Close the currently displayed message.     | [Guide](https://developers.screeb.app/sdk-kmp/start-message-programmatically) |

### Session replay

| Method                           | Description                     | More                                                          |
| -------------------------------- | ------------------------------- | ------------------------------------------------------------- |
| `sessionReplayStart(): Boolean?` | Start session replay recording. | [Guide](https://developers.screeb.app/sdk-kmp/session-replay) |
| `sessionReplayStop(): Boolean?`  | Stop session replay recording.  | [Guide](https://developers.screeb.app/sdk-kmp/session-replay) |

### Debug

| Method                      | Description                      | More                                                           |
| --------------------------- | -------------------------------- | -------------------------------------------------------------- |
| `debug(): String?`          | Get SDK debug information.       | [Guide](https://developers.screeb.app/sdk-kmp/troubleshooting) |
| `debugTargeting(): String?` | Get targeting debug information. | [Guide](https://developers.screeb.app/sdk-kmp/troubleshooting) |

### Privacy helpers

| Method                                | Description                                              | More                                                           |
| ------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------------- |
| `View.screebMaskText(): View`         | Mask a view or component in session replay.              | [Guide](https://developers.screeb.app/sdk-kmp/privacy-helpers) |
| `UIView.screebMaskText(): UIView`     | Mask a view or component in session replay.              | [Guide](https://developers.screeb.app/sdk-kmp/privacy-helpers) |
| `View.screebNoCapture(): View`        | Exclude a view or component from session replay capture. | [Guide](https://developers.screeb.app/sdk-kmp/privacy-helpers) |
| `UIView.screebNoCapture(): UIView`    | Exclude a view or component from session replay capture. | [Guide](https://developers.screeb.app/sdk-kmp/privacy-helpers) |
| `View.screebId(id: String): View`     | Set a stable Screeb element ID for IAM targeting.        | [Guide](https://developers.screeb.app/sdk-kmp/privacy-helpers) |
| `UIView.screebId(id: String): UIView` | Set a stable Screeb element ID for IAM targeting.        | [Guide](https://developers.screeb.app/sdk-kmp/privacy-helpers) |

### Other

| Method                         | Description                                                                                                                                                                                                                                                                        | More |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- |
| `handleDeepLink(url: String?)` | Forward an incoming deep link (e.g. `screeb-<channel-id>://inspector`) to the SDK so it can act on it - used by the in-app message editor / native inspector. Pass the URL of the launch (or new) intent. On Android, call this from your Activity's `onCreate` and `onNewIntent`. | -    |

## API signatures

### Lifecycle

```kotlin
initSdk(channelId: String, userId: String? = null, properties: Map<String, Any>? = null, hooks: ScreebHooks? = null, initOptions: ScreebInitOptions? = null, language: String? = null): Boolean?
closeSdk(): Boolean?
```

### Identity

```kotlin
setIdentity(userId: String, properties: Map<String, Any>? = null): Boolean?
setProperties(properties: Map<String, Any>? = null): Boolean?
resetIdentity(): Boolean?
setAnonymousId(anonymousId: String): Boolean?
getIdentity(): Map<String, Any>?
```

### Groups

```kotlin
assignGroup(groupType: String? = null, groupName: String, properties: Map<String, Any>? = null): Boolean?
unassignGroup(groupType: String? = null, groupName: String, properties: Map<String, Any>? = null): Boolean?
```

### Tracking

```kotlin
trackEvent(name: String, properties: Map<String, Any>? = null): Boolean?
trackScreen(name: String, properties: Map<String, Any>? = null): Boolean?
```

### Surveys

```kotlin
startSurvey(surveyId: String, allowMultipleResponses: Boolean = true, hiddenFields: Map<String, Any>? = null, ignoreSurveyStatus: Boolean = true, hooks: ScreebHooks? = null, language: String? = null, distributionId: String? = null): Boolean?
closeSurvey(surveyId: String? = null): Boolean?
```

### Messages

```kotlin
startMessage(messageId: String, allowMultipleResponses: Boolean = true, hiddenFields: Map<String, Any>? = null, ignoreMessageStatus: Boolean = true, hooks: ScreebHooks? = null, language: String? = null, distributionId: String? = null): Boolean?
closeMessage(messageId: String? = null): Boolean?
```

### Session replay

```kotlin
sessionReplayStart(): Boolean?
sessionReplayStop(): Boolean?
```

### Debug

```kotlin
debug(): String?
debugTargeting(): String?
```

### Privacy helpers

```kotlin
View.screebMaskText(): View
UIView.screebMaskText(): UIView
View.screebNoCapture(): View
UIView.screebNoCapture(): UIView
View.screebId(id: String): View
UIView.screebId(id: String): UIView
```

### Other

```kotlin
handleDeepLink(url: String?)
```

## Hooks

Hooks can be passed to initialization and programmatic survey/message starts. Callback payloads are forwarded as JSON strings by the mobile wrappers.

```kotlin
val hooks = ScreebHooks(
    version = "1.0.0",
    callbacks = mapOf(
        "onSurveyShowed" to { payload -> /* handle hook payload */ },
    ),
)
```

For complete hook payload definitions, see the [JS tag hooks reference](https://developers.screeb.app/sdk-kmp/hooks).

## Privacy helpers

```kotlin
view.screebMaskText()

view.screebNoCapture()

view.screebId("checkout-button")
```

## Type definitions

```kotlin
data class ScreebHooks( val version: String, val callbacks: Map<String, suspend (String) -> Any?> = emptyMap(), )

data class ScreebInitOptions( val isDebugMode: Boolean = false, val disableMirror: Boolean = false, )
```
