Skip to content
Open Screeb

Copy ready-made code for the most common Screeb tasks, from setup and identity to events, surveys, hooks and logout.

Each example below covers one common task. They assume the SDK is installed as shown in Install. Replace the placeholders with your own values.

For a complete working app, open the example for your SDK in the examples folder of the Screeb SDK repository.

When the user is already logged in at startup, pass their id and properties to the initialization. Screeb then ties the session to that user from the start, with no anonymous user in between.

Screeb.initSdk(
this,
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
VisitorProperties().apply {
this["email"] = "jane@example.com"
this["plan"] = "pro"
},
)

When the app starts before the user logs in, initialize Screeb without a user, then identify them once they log in. Screeb keeps the activity of the anonymous session and attaches it to that user. See Identity for the details.

Screeb.setIdentity(
"<USER-ID>",
TrackingEventProperties().apply {
this["email"] = "jane@example.com"
this["plan"] = "pro"
},
)

Track what the user does, with properties that describe it. You can then target surveys at users who did it. See Event tracking.

Screeb.trackEvent(
"plan_upgraded",
TrackingEventProperties().apply {
this["plan"] = "pro"
this["seats"] = 5
},
)

Report each screen the user opens, so you can target surveys at a screen. See Screen tracking.

Screeb.trackScreen("Checkout")

Put the user in a group, such as their company, with properties that describe the group. See Group assignation.

Screeb.assignGroup(
"company",
"Acme",
GroupProperties().apply {
this["plan"] = "enterprise"
},
)

Start a survey from your code, for example once a checkout completes, and pass hidden fields that Screeb saves with the response. See Start a survey programmatically for the other options.

Screeb.startSurvey(
surveyId = "<SURVEY-ID>",
hiddenFields = HiddenFields().apply {
this["source"] = "checkout"
this["cart_value"] = 149.99
},
)

Pass hooks to the initialization to run your code on Screeb events. This one logs each completed survey. Hooks always need a version. See Hooks for every hook and its payload.

Screeb.initSdk(
this,
"<YOUR-CHANNEL-ID>",
hooks = hashMapOf(
"version" to "1.0.0",
"onSurveyCompleted" to { payload: Any ->
Log.d("Screeb", "Survey completed: $payload")
},
),
)

When the user logs out, reset the identity. Screeb starts a new anonymous session, so the next person on the device is not mixed with the previous user.

Screeb.resetIdentity()