Start survey programmatically
How to start a survey programmatically?โ
In most cases, you should let the Screeb targeting engine start the survey. But sometimes, you may want to run a survey on user action.
You can find the <SURVEY-ID> in the Manual section of the survey editor.
You can also find it in the survey editor URL, after the /surveys/ part.

Screeb.startSurvey(
surveyId: "<SURVEY-ID>"
)
Prevent multiple displays?โ
If current user already replied to your survey and you would rather not display it many times, please add the allowMultipleResponses argument:
Screeb.startSurvey(
surveyId: "<SURVEY-ID>",
allowMultipleResponses: false
)
Respect survey status?โ
By default, using manual survey start will ignore the survey status. If you want to respect the survey status, you can add the ignoreSurveyStatus argument and set it to false:
Screeb.startSurvey(
surveyId: "<SURVEY-ID>",
ignoreSurveyStatus: false
)
Contextualize responseโ
The startSurvey command accepts a list of hidden fields. Values passed as parameters will be listed alongside the responses, on the Screeb platform.
Screeb.startSurvey(
surveyId: "<SURVEY-ID>",
hiddenFields: [
"iosHidden1": AnyEncodable("hiddenField1"),
"iosHiddenCount": AnyEncodable(75)
]
)
Hooksโ
You can pass the optional hooks parameter to handle survey lifecycle events, using the same SurveyHooks structure as Screeb.initSdk().
Screeb.startSurvey(
surveyId: "<SURVEY-ID>",
hooks: [
"version": "1.0.0",
"onSurveyShowed": {(e:Any) -> () in print("Screeb survey showed " + String(describing: e))}
]
)
Distribution identifierโ
If you want to associate the survey start with a specific distribution, you can pass the optional distributionId parameter:
Screeb.startSurvey(
surveyId: "<SURVEY-ID>",
distributionId: "<DISTRIBUTION-ID>"
)
Force languageโ
If you want to force the survey language, you can pass the optional language parameter with an ISO 639-1 code such as "en" or "fr".
Here is the order of priority for the language:
survey.start param > init param > user property > browser language.
Screeb.startSurvey(
surveyId: "<SURVEY-ID>",
language: "en"
)