Skip to main content
Version: iOS SDK

Hooks

Set hooksโ€‹

You can define custom hooks to be executed on various events.

Thanks to this you will be able to interact with your app when a survey or message appears, or execute some custom code when a survey is submitted.

You can define hooks on Screeb.initSdk(), Screeb.startSurvey() and Screeb.startMessage() commands. Hooks use the same SurveyHooks structure and are all optional.

Available hooksโ€‹

Hook NameAvailable on Screeb.initSdk()Available on Screeb.startSurvey()Available on Screeb.startMessage()
onSurveyShowedYes โœ…Yes โœ…Yes โœ…
onSurveyStartedYes โœ…Yes โœ…Yes โœ…
onQuestionRepliedYes โœ…Yes โœ…Yes โœ…
onSurveyCompletedYes โœ…Yes โœ…Yes โœ…
onSurveyHiddenYes โœ…Yes โœ…Yes โœ…
onAppStoreRatingTriggeredYes โœ…Yes โœ…Yes โœ…
onReadyYes โœ…No โŒNo โŒ
onSurveyDisplayAllowedYes โœ…No โŒNo โŒ
onMessageShowedYes โœ…Yes โœ…Yes โœ…
onMessageStartedYes โœ…Yes โœ…Yes โœ…
onMessageCompletedYes โœ…Yes โœ…Yes โœ…
onMessageHiddenYes โœ…Yes โœ…Yes โœ…
onMessageDisplayAllowedYes โœ…No โŒNo โŒ

Set hooks on SDK initโ€‹

Screeb.initSdk(
context: window?.rootViewController,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onReady": {(e:Any) -> () in print("Screeb sdk ready " + String(describing: e))},
"onSurveyDisplayAllowed": {(e:Any) -> Bool in print("onSurveyDisplayAllowed " + String(describing: e)); return true}
]
)

Set hooks on survey startโ€‹

Screeb.startSurvey(
surveyId: "<survey-id>",
allowMultipleResponses: true,
hiddenFields: [
"iosHidden1": AnyEncodable("hiddenField1"),
"iosHiddenCount": AnyEncodable(75)
],
hooks: [
"version": "1.0.0",
"onSurveyShowed": {(e:Any) -> () in print("Screeb survey showed " + String(describing: e))},
]
)

Set hooks on message startโ€‹

Screeb.startMessage(
messageId: "<message-id>",
allowMultipleResponses: true,
hiddenFields: [
"iosHidden1": AnyEncodable("hiddenField1"),
"iosHiddenCount": AnyEncodable(75)
],
hooks: [
"version": "1.0.0",
"onSurveyShowed": {(e:Any) -> () in print("Screeb message showed " + String(describing: e))},
]
)

onSurveyShowedโ€‹

Called when a survey is showed.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onSurveyShowed": {(e:Any) -> () in print("Screeb survey showed " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
survey: {
id: string,
survey_position: "center-left" | "center-center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right",
survey_size: 25 | 50 | 75 | 100 | 125 | 150,
survey_format: "conversational" | "cards",
},
response: {
id: string,
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onSurveyStartedโ€‹

Called when a survey is started.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onSurveyStarted": {(e:Any) -> () in print("Screeb survey started " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
survey: {
id: string,
survey_position: "center-left" | "center-center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right",
survey_size: 25 | 50 | 75 | 100 | 125 | 150,
survey_format: "conversational" | "cards",
},
response: {
id: string,
},
user: {
anonymous_id: string,
user_id: string,
}
}

onQuestionRepliedโ€‹

Called when a question is replied.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onQuestionReplied": {(e:Any) -> () in print("Screeb Question Replied " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
survey: {
id: string,
survey_position: "center-left" | "center-center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right",
survey_size: 25 | 50 | 75 | 100 | 125 | 150,
survey_format: "conversational" | "cards",
},
response: {
id: string,
status: "started" | "ended" | "closed" | "interrupted"
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
};
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onSurveyCompletedโ€‹

Called when a survey is completed.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onSurveyCompleted": {(e:Any) -> () in print("Screeb survey completed " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
survey: {
id: string,
survey_position: "center-left" | "center-center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right",
survey_size: 25 | 50 | 75 | 100 | 125 | 150,
survey_format: "conversational" | "cards",
},
response: {
id: string,
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onSurveyHiddenโ€‹

Called when a survey is hidden.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onSurveyHidden": {(e:Any) -> () in print("Screeb survey hidden " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
survey: {
id: string,
survey_position: "center-left" | "center-center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right",
survey_size: 25 | 50 | 75 | 100 | 125 | 150,
survey_format: "conversational" | "cards",
},
response: {
id: string,
hide_reason: "started" | "ended" | "closed" | "interrupted",
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onAppStoreRatingTriggeredโ€‹

Called when an App Store Rating question is triggered.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onAppStoreRatingTriggered": {(e:Any) -> () in print("Screeb app store rating triggered " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
user: {
anonymous_id: string,
user_id: string,
}
}

onReadyโ€‹

Called when the SDK is ready. Only available on Screeb.initSdk().

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onReady": {(e:Any) -> () in print("Screeb SDK ready " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
user: {
anonymous_id: string,
user_id: string,
}
}

onSurveyDisplayAllowedโ€‹

Called before a survey display to allow it or not. Only available on Screeb.initSdk(). Return a boolean value. Return false to prevent display.

caution

The answer must arrive within 5 seconds. Past that deadline the display evaluation fails and the survey is not shown โ€” keep this callback fast and avoid slow network calls; when unsure, return true early.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onSurveyDisplayAllowed": {(e:Any) -> Bool in print("Screeb survey display available " + String(describing: e)); return true},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
survey: {
id: string,
},
user: {
anonymous_id: string,
user_id: string,
}
}

onMessageShowedโ€‹

Called when a message is showed.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onMessageShowed": {(e:Any) -> () in print("Screeb message showed " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
message: {
message_size: 25 | 50 | 75 | 100 | 125 | 150,
id: string | null,
},
response: {
id: string,
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onMessageStartedโ€‹

Called when a message is started.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onMessageStarted": {(e:Any) -> () in print("Screeb message showed " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
message: {
message_size: 25 | 50 | 75 | 100 | 125 | 150,
id: string | null,
},
response: {
id: string,
},
user: {
anonymous_id: string,
user_id: string,
}
}

onMessageCompletedโ€‹

Called when a message is completed.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onMessageCompleted": {(e:Any) -> () in print("Screeb message showed " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
message: {
message_size: 25 | 50 | 75 | 100 | 125 | 150,
id: string | null,
},
response: {
id: string,
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onMessageHiddenโ€‹

Called when a message is hidden.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onMessageHidden": {(e:Any) -> () in print("Screeb message showed " + String(describing: e))},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
message: {
message_size: 25 | 50 | 75 | 100 | 125 | 150,
id: string | null,
},
response: {
id: string,
hide_reason: "started" | "ended" | "closed" | "interrupted",
items: {
question: {
id: string;
title: string;
type: "text" | "video";
url: string;
};
answer: {
fields: {
type: "string" | "number" | "boolean" | "none" | "time" | "url";
},
text: string;
number: number;
boolean: boolean;
time: Date;
url: string;
}[] | undefined;
replied_at: Date | undefined;
}[];
},
user: {
anonymous_id: string,
user_id: string,
}
}

onMessageDisplayAllowedโ€‹

Called before a message display to allow it or not. Only available on initSdk(). Return a boolean value. Return false to prevent display.

caution

The answer must arrive within 5 seconds. Past that deadline the display evaluation fails and the message is not shown โ€” keep this callback fast and avoid slow network calls; when unsure, return true early.

Example
Screeb.initSdk(
context: nil,
channelId: "<YOUR-CHANNEL-ID>",
hooks: [
"version": "1.0.0",
"onMessageDisplayAllowed": {(e:Any) -> Bool in print("Screeb message display available " + String(describing: e)); return true},
]
)
Payload definition
{
channel: {
id: string,
type: "ios"
},
message: {
id: string,
},
user: {
anonymous_id: string,
user_id: string,
}
}