# Reference

Every public method of @screeb/react-native, with its signature.

Complete reference for `@screeb/react-native`. New to Screeb? Start with the [install guide](https://developers.screeb.app/sdk-react-native/install).

## Methods by capability

### Lifecycle

| Method                                                                                                                                                                                    | Description                | More                                                            |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | --------------------------------------------------------------- |
| `initSdk(channelId: string, userId?: string, properties?: Record<string, unknown> \| Map<string, unknown>, hooks?: HookMap, initOptions?: InitOptions, language?: string): Promise<void>` | Initialize the Screeb SDK. | [Guide](https://developers.screeb.app/sdk-react-native/install) |
| `closeSdk(): Promise<void>`                                                                                                                                                               | Stop the SDK.              | [Guide](https://developers.screeb.app/sdk-react-native/install) |

### Identity

| Method                                                                                                             | Description                                                                   | More                                                                                      |
| ------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `setIdentity(userId: string, properties?: Record<string, unknown> \| Map<string, unknown> \| null): Promise<void>` | Identify the current user with optional properties.                           | [Guide](https://developers.screeb.app/sdk-react-native/identity)                          |
| `setProperties(properties?: Record<string, unknown> \| Map<string, unknown> \| null): Promise<void>`               | Send visitor properties without changing the identity.                        | [Guide](https://developers.screeb.app/sdk-react-native/identity)                          |
| `resetIdentity(): Promise<void>`                                                                                   | Reset the current visitor identity.                                           | [Guide](https://developers.screeb.app/sdk-react-native/identity)                          |
| `setAnonymousId(anonymousId: string): Promise<void>`                                                               | Tell Screeb which anonymous id your CDP already uses for the current visitor. | [Guide](https://developers.screeb.app/sdk-react-native/identity#2-share-one-anonymous-id) |
| `getIdentity(): Promise<{ [key: string]: unknown; } \| null>`                                                      | Get the current visitor identity and properties.                              | [Guide](https://developers.screeb.app/sdk-react-native/identity)                          |

### Groups

| Method                                                                                                                                   | Description                           | More                                                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------- |
| `assignGroup(type: string \| null, name: string, properties?: Record<string, unknown> \| Map<string, unknown> \| null): Promise<void>`   | Assign the current user to a group.   | [Guide](https://developers.screeb.app/sdk-react-native/group-assignation) |
| `unassignGroup(type: string \| null, name: string, properties?: Record<string, unknown> \| Map<string, unknown> \| null): Promise<void>` | Remove the current user from a group. | [Guide](https://developers.screeb.app/sdk-react-native/group-assignation) |

### Tracking

| Method                                                                                                           | Description                      | More                                                                    |
| ---------------------------------------------------------------------------------------------------------------- | -------------------------------- | ----------------------------------------------------------------------- |
| `trackEvent(name: string, properties?: Record<string, unknown> \| Map<string, unknown> \| null): Promise<void>`  | Track a custom event.            | [Guide](https://developers.screeb.app/sdk-react-native/event-tracking)  |
| `trackScreen(name: string, properties?: Record<string, unknown> \| Map<string, unknown> \| null): Promise<void>` | Track a screen navigation event. | [Guide](https://developers.screeb.app/sdk-react-native/screen-tracking) |

### Surveys

| Method                                                                                                                                                                                                                                              | Description                               | More                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------- |
| `startSurvey(surveyId: string, allowMultipleResponses?: boolean, hiddenFields?: Record<string, unknown> \| Map<string, unknown> \| null, ignoreSurveyStatus?: boolean, hooks?: HookMap, language?: string, distributionId?: string): Promise<void>` | Start a specific survey programmatically. | [Guide](https://developers.screeb.app/sdk-react-native/start-survey-programmatically) |
| `closeSurvey(surveyId?: string): Promise<void>`                                                                                                                                                                                                     | Close the currently displayed survey.     | -                                                                                     |

### Messages

| Method                                                                                                                                                                                                                                                 | Description                                | More                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | -------------------------------------------------------------------------------------- |
| `startMessage(messageId: string, allowMultipleResponses?: boolean, hiddenFields?: Record<string, unknown> \| Map<string, unknown> \| null, ignoreMessageStatus?: boolean, hooks?: HookMap, language?: string, distributionId?: string): Promise<void>` | Start a specific message programmatically. | [Guide](https://developers.screeb.app/sdk-react-native/start-message-programmatically) |
| `closeMessage(messageId?: string): Promise<void>`                                                                                                                                                                                                      | Close the currently displayed message.     | [Guide](https://developers.screeb.app/sdk-react-native/start-message-programmatically) |

### Session replay

| Method                                | Description                     | More                                                                   |
| ------------------------------------- | ------------------------------- | ---------------------------------------------------------------------- |
| `sessionReplayStart(): Promise<void>` | Start session replay recording. | [Guide](https://developers.screeb.app/sdk-react-native/session-replay) |
| `sessionReplayStop(): Promise<void>`  | Stop session replay recording.  | [Guide](https://developers.screeb.app/sdk-react-native/session-replay) |

### Debug

| Method                              | Description                      | More                                                                    |
| ----------------------------------- | -------------------------------- | ----------------------------------------------------------------------- |
| `debug(): Promise<string>`          | Get SDK debug information.       | [Guide](https://developers.screeb.app/sdk-react-native/troubleshooting) |
| `debugTargeting(): Promise<string>` | Get targeting debug information. | [Guide](https://developers.screeb.app/sdk-react-native/troubleshooting) |

### Privacy helpers

| Method                                           | Description                                              | More                                                                    |
| ------------------------------------------------ | -------------------------------------------------------- | ----------------------------------------------------------------------- |
| `ScreebMaskText(props: ScreebPrivacyViewProps)`  | Mask a view or component in session replay.              | [Guide](https://developers.screeb.app/sdk-react-native/privacy-helpers) |
| `ScreebNoCapture(props: ScreebPrivacyViewProps)` | Exclude a view or component from session replay capture. | [Guide](https://developers.screeb.app/sdk-react-native/privacy-helpers) |
| `ScreebId({ id, ...props }: ScreebIdProps)`      | Set a stable Screeb element ID for IAM targeting.        | [Guide](https://developers.screeb.app/sdk-react-native/privacy-helpers) |

### Other

| Method                                       | Description                                                                             | More |
| -------------------------------------------- | --------------------------------------------------------------------------------------- | ---- |
| `handleDeepLink(url: string): Promise<void>` | Forward a Screeb deep link to the SDK, so editor, survey and message links open in-app. | -    |

## API signatures

### Lifecycle

```ts
initSdk(channelId: string, userId?: string, properties?: Record<string, unknown> | Map<string, unknown>, hooks?: HookMap, initOptions?: InitOptions, language?: string): Promise<void>
closeSdk(): Promise<void>
```

### Identity

```ts
setIdentity(userId: string, properties?: Record<string, unknown> | Map<string, unknown> | null): Promise<void>
setProperties(properties?: Record<string, unknown> | Map<string, unknown> | null): Promise<void>
resetIdentity(): Promise<void>
setAnonymousId(anonymousId: string): Promise<void>
getIdentity(): Promise<{ [key: string]: unknown; } | null>
```

### Groups

```ts
assignGroup(type: string | null, name: string, properties?: Record<string, unknown> | Map<string, unknown> | null): Promise<void>
unassignGroup(type: string | null, name: string, properties?: Record<string, unknown> | Map<string, unknown> | null): Promise<void>
```

### Tracking

```ts
trackEvent(name: string, properties?: Record<string, unknown> | Map<string, unknown> | null): Promise<void>
trackScreen(name: string, properties?: Record<string, unknown> | Map<string, unknown> | null): Promise<void>
```

### Surveys

```ts
startSurvey(surveyId: string, allowMultipleResponses?: boolean, hiddenFields?: Record<string, unknown> | Map<string, unknown> | null, ignoreSurveyStatus?: boolean, hooks?: HookMap, language?: string, distributionId?: string): Promise<void>
closeSurvey(surveyId?: string): Promise<void>
```

### Messages

```ts
startMessage(messageId: string, allowMultipleResponses?: boolean, hiddenFields?: Record<string, unknown> | Map<string, unknown> | null, ignoreMessageStatus?: boolean, hooks?: HookMap, language?: string, distributionId?: string): Promise<void>
closeMessage(messageId?: string): Promise<void>
```

### Session replay

```ts
sessionReplayStart(): Promise<void>
sessionReplayStop(): Promise<void>
```

### Debug

```ts
debug(): Promise<string>
debugTargeting(): Promise<string>
```

### Privacy helpers

```ts
ScreebMaskText(props: ScreebPrivacyViewProps)
ScreebNoCapture(props: ScreebPrivacyViewProps)
ScreebId({ id, ...props }: ScreebIdProps)
```

### Other

```ts
handleDeepLink(url: string): Promise<void>
```

## Hooks

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

```ts
const hooks = {
  version: "1.0.0",
  onSurveyShowed: async (payload: string) => {
    // handle hook payload
  },
};
```

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

## Privacy helpers

```ts
<ScreebMaskText>
  <Text>Sensitive content</Text>
</ScreebMaskText>

<ScreebNoCapture>
  <Text>Do not record</Text>
</ScreebNoCapture>

<ScreebId id="checkout-button">
  <Button title="Checkout" />
</ScreebId>
```

## Type definitions

```ts
type HookMap = {
  version?: string;
  [key: string]: unknown;
};

type InitOptions = {
  isDebugMode?: boolean;
  disableMirror?: boolean;
};

type ScreebPrivacyViewProps = ViewProps;

type ScreebIdProps = ViewProps & {
  id: string;
};
```
