Start a message programmatically
How to start a message programmatically?โ
In most cases, you should let the Screeb targeting engine start the message. But sometimes, you may want to run a message on user action.
You can find the MESSAGE_ID in the Manual section of the message editor.
You can also find it in the message editor URL, after the /messages/ part.
Screeb.startMessage(
messageId = "<MESSAGE_ID>"
)
Prevent multiple displays?โ
If the current user already replied to your message and you would rather not display it many times, add the allowMultipleResponses argument:
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
allowMultipleResponses = false
)
Respect message status?โ
By default, using manual message start will ignore the message status. If you want to respect the message status, add the ignoreMessageStatus argument and set it to false:
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
ignoreMessageStatus = false
)
Contextualize responseโ
The startMessage command accepts a list of hidden fields. Values passed as parameters will be listed alongside the responses, on the Screeb platform.
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
hiddenFields = HiddenFields().apply {
this["h1"] = "hidden_field1"
this["h_count"] = 75
}
)
Hooksโ
You can pass the optional hooks parameter to handle message lifecycle events, using the same hooks structure as Screeb.initSdk().
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
hooks = hashMapOf(
"version" to "1.0.0",
"onSurveyShowed" to { payload: Any -> Log.d("Screeb", "Message showed $payload") }
)
)
Force languageโ
If you want to force the message language, you can pass the language parameter:
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
language = "en"
)
Distribution identifierโ
If you want to associate the message start with a specific distribution, pass the optional distributionId parameter:
Screeb.startMessage(
messageId = "<MESSAGE_ID>",
distributionId = "<DISTRIBUTION_ID>"
)
Close a messageโ
Screeb.closeMessage()
You can also close a specific message:
Screeb.closeMessage("<MESSAGE_ID>")