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: [
"iosHidden1": AnyEncodable("hiddenField1"),
"iosHiddenCount": AnyEncodable(75)
]
)
Hooksโ
You can pass the optional hooks parameter to handle message lifecycle events, using the same SurveyHooks structure as Screeb.initSdk().
Screeb.startMessage(
messageId: "<MESSAGE-ID>",
hooks: [
"version": "1.0.0",
"onSurveyShowed": {(e:Any) -> () in print("Screeb message showed " + String(describing: e))}
]
)
Distribution identifierโ
If you want to associate the message start with a specific distribution, you can pass the optional distributionId parameter:
Screeb.startMessage(
messageId: "<MESSAGE-ID>",
distributionId: "<DISTRIBUTION-ID>"
)
Force languageโ
If you want to force the message language, you can pass the optional language parameter with an ISO 639-1 code such as "en" or "fr".
Screeb.startMessage(
messageId: "<MESSAGE-ID>",
language: "en"
)
Close a messageโ
Screeb.closeMessage()
You can also close a specific message:
Screeb.closeMessage("<MESSAGE-ID>")