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 application when a survey appears, or execute some custom code when a survey is submitted.
You can define hooks on initSdk(), startSurvey(), and startMessage() commands. Hooks are all optional.
Available hooksโ
| Hook Name | Available on initSdk() | Available on startSurvey() | Available on startMessage() |
|---|---|---|---|
onSurveyShowed | Yes โ | Yes โ | Yes โ |
onMessageShowed | Yes โ | Yes โ | Yes โ |
onSurveyStarted | Yes โ | Yes โ | Yes โ |
onMessageStarted | Yes โ | Yes โ | Yes โ |
onQuestionReplied | Yes โ | Yes โ | Yes โ |
onSurveyCompleted | Yes โ | Yes โ | Yes โ |
onMessageCompleted | Yes โ | Yes โ | Yes โ |
onSurveyHidden | Yes โ | Yes โ | Yes โ |
onMessageHidden | Yes โ | Yes โ | Yes โ |
onAppStoreRatingTriggered | Yes โ | Yes โ | Yes โ |
onReady | Yes โ | No โ | No โ |
onSurveyDisplayAllowed | Yes โ | No โ | No โ |
onMessageDisplayAllowed | Yes โ | No โ | No โ |
Set hooks on SDK initโ
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{
isConnected: false,
age: 29,
product: "iPhone 13",
email: "support@screeb.app",
},
{
version: "1.0.0",
onReady: (payload: any) => {
console.log("onReady", payload);
},
onSurveyDisplayAllowed: (payload: any) => {
console.log("onSurveyDisplayAllowed", payload);
// return false to prevent display
return true;
},
}
);
Set hooks on survey startโ
startSurvey(
"<survey-id>",
true, // allowMultipleResponses
{}, // hiddenFields
true, // ignoreSurveyStatus
{
version: "1.0.0",
onSurveyShowed: (payload: any) => {
console.log("onSurveyShowed", payload);
},
}
);
Set hooks on message startโ
startMessage(
"<message-id>",
true, // allowMultipleResponses
{}, // hiddenFields
true, // ignoreMessageStatus
{
version: "1.0.0",
onMessageShowed: (payload: any) => {
console.log("onMessageShowed", payload);
},
}
);
onSurveyShowedโ
Called when a survey is showed.
Example
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onSurveyShowed: (payload: any) => {
console.log("onSurveyShowed", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onSurveyStarted: (payload: any) => {
console.log("onSurveyStarted", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onQuestionReplied: (payload: any) => {
console.log("onQuestionReplied", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onSurveyCompleted: (payload: any) => {
console.log("onSurveyCompleted", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onSurveyHidden: (payload: any) => {
console.log("onSurveyHidden", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onAppStoreRatingTriggered: (payload: any) => {
console.log("onAppStoreRatingTriggered", payload);
},
}
);
Payload definition
{
channel: {
id: string,
type: "ios"
},
user: {
anonymous_id: string,
user_id: string,
}
}
onReadyโ
Called when the SDK is ready. Only available on initSdk().
Example
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onReady: (payload: any) => {
console.log("onReady", payload);
},
}
);
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 initSdk().
Return a boolean value. Return false to prevent display.
Example
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onSurveyDisplayAllowed: (payload: any) => {
console.log("onSurveyDisplayAllowed", payload);
// return false to prevent display
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onMessageShowed: (payload: any) => {
console.log("onMessageShowed", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onMessageStarted: (payload: any) => {
console.log("onMessageStarted", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onMessageCompleted: (payload: any) => {
console.log("onMessageCompleted", payload);
},
}
);
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
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onMessageHidden: (payload: any) => {
console.log("onMessageHidden", payload);
},
}
);
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.
Example
initSdk(
"<YOUR-CHANNEL-ID>",
"<USER-ID>",
{...},
{
version: "1.0.0",
onMessageDisplayAllowed: (payload: any) => {
console.log("onMessageDisplayAllowed", payload);
// return false to prevent display
return true;
},
}
);
Payload definition
{
channel: {
id: string,
type: "ios"
},
message: {
id: string,
},
user: {
anonymous_id: string,
user_id: string,
}
}