Hooks
Hooks let your app decide how to react to Screeb lifecycle events, or whether a survey/message is allowed to display.
KMP hooks are supported on Android and iOS for:
initSdkstartSurveystartMessage
Register hooksโ
import app.screeb.sdk.kmp.ScreebHooks
val hooks = ScreebHooks(
version = "1.0.0",
callbacks = mapOf(
"onSurveyDisplayAllowed" to { payload ->
println("Display decision payload: $payload")
true
},
"onSurveyShowed" to { payload ->
println("Survey shown: $payload")
null
},
),
)
Screeb.initSdk(
channelId = "<YOUR_CHANNEL_ID>",
hooks = hooks,
)
The callback receives the native Screeb hook payload as a JSON string.
Available hook names (same set as the native SDKs): onReady,
onSurveyShowed, onSurveyStarted, onSurveyCompleted, onSurveyHidden,
onSurveyDisplayAllowed, onMessageShowed, onMessageStarted,
onMessageCompleted, onMessageHidden, onMessageDisplayAllowed,
onQuestionReplied, onAppStoreRatingTriggered.
Return a hook resultโ
Return true or false from decision hooks such as onSurveyDisplayAllowed.
Decision hooks (onSurveyDisplayAllowed, onMessageDisplayAllowed) must answer within 5 seconds. Past that deadline the display evaluation fails and the survey is not shown โ keep these callbacks fast and avoid slow network calls.
"onSurveyDisplayAllowed" to { payload ->
val canDisplay = isUserAllowedToSeeSurvey()
canDisplay
}
Return null when the hook does not need to send a decision back to Screeb.
Start a survey with hooksโ
Screeb.startSurvey(
surveyId = "<SURVEY_ID>",
hooks = hooks,
)
Start a message with hooksโ
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
hooks = hooks,
)