# Troubleshooting

Find out why the SDK does not load, a survey does not show or a hook does not run, and fix the cause in your code.

This page covers the causes that live in your code: the SDK does not start, the user is not identified, a hook blocks the display. Many surveys and messages do not show for a reason set in Screeb itself: the channel is not live, a targeting rule does not match, capping applies or the user has already answered. For those, follow [My survey or message is not displayed](https://help.screeb.app/troubleshooting/survey-not-displayed) in the help center.

## Debug the SDK and its targeting

Two calls print what the SDK knows: the state of the current session, then the status of each targeting rule of each active survey.

```kotlin
Screeb.debug()
Screeb.debugTargeting()
```

On a website, the output goes to the browser console. In a mobile app, it goes to the native logs: the Xcode console on iOS, Logcat at the `info` level on Android.

### Read the session state

The session debug looks like this:

```text
******************* SCREEB SESSION DEBUG *********************
Screeb channel id: <UUID>
Screeb channel type: widget
Screeb respondent id: <UUID>
Screeb survey id: none
Screeb response id: none

Screeb current session start: Thu May 04 2023 16:53:49 GMT+0200
Screeb current session last activity: Thu May 04 2023 17:41:30 GMT+0200

Screeb targeting engine status: disabled
Screeb targeting engine: 3 surveys

Detected platform: desktop
Detected locale: en-GB
Detected timezone: -120
**************************************************************
```

- An empty channel id means the SDK was never initialized: check that the initialization runs, with the right channel id.
- An empty respondent id means your workspace reached its monthly user quota.

### Read the targeting rules

The targeting debug lists each active survey with a link to it in Screeb, then each of its rules. A passing rule is marked green, a failing rule red: a red rule is the reason the survey does not show. Disabled surveys are not listed.

## A survey or message does not show

Once the debug output looks right, check these causes in your code:

- **The SDK starts once, with the right channel id.** Initialize Screeb once, when the app starts. The same channel id works on the web, iOS and Android.
- **The user is identified before the trigger.** A rule on a user property or a group only matches after you identify the user and send that property. See [Identity](https://developers.screeb.app/sdk-kmp/identity).
- **The display hook lets it through.** If you set `onSurveyDisplayAllowed` or `onMessageDisplayAllowed`, it must return `true` for the survey or message to show. See [Hooks](https://developers.screeb.app/sdk-kmp/hooks).
- **Identity is not ignored.** With the consent exemption mode on, Screeb ignores identity calls. See [Consent exemption](https://developers.screeb.app/sdk-kmp/consent-exemption).

For everything else, go through [My survey or message is not displayed](https://help.screeb.app/troubleshooting/survey-not-displayed).

## Hooks are not called

- Set `version` to `"1.0.0"`. A missing or other version makes the whole call fail with `Unexpected empty hooks version` or `Unsupported hooks version`.
- Check the hook names against [Hooks](https://developers.screeb.app/sdk-kmp/hooks). An unknown name also makes the call fail, with `Unexpected hook type`, so a typo in one hook can stop Screeb from starting.
- Pass each hook where it applies: global hooks, such as `onReady` or `onSurveyDisplayAllowed`, only to the initialization; survey and message hooks to the initialization or to the call that starts the survey or message.

## Too many anonymous users

Every user Screeb sees, identified or not, counts toward your monthly user quota.

- Keep Screeb out of your tests, CI and preview builds: initialize it only when your environment flag says the app runs for real users.
- When the user is already logged in at startup, pass their id to the initialization instead of identifying them later.
- Reset the identity only on logout. Each reset starts a new anonymous user.

To show nothing to visitors who never log in, turn on the "Ignore anonymous users" setting of your workspace, described in [My survey or message is not displayed](https://help.screeb.app/troubleshooting/survey-not-displayed).

## Nothing shows on Android

- The SDK needs network access, and its manifest does not request it. Add the permission to your app's `AndroidManifest.xml` if it is not there yet:

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

- Code shrinking needs no extra rule: the SDK ships its own ProGuard and R8 keep rules.

## Kotlin Multiplatform: calls do not compile or do nothing

Every method is a suspend function: call it from a coroutine. Each one returns `null` when the native call fails, so check the result while you set up.
