Hooks
Define custom hooks to execute on survey and message events. All hooks are optional.
Available hooks
| Hook Name | init | surveyStart | messageStart |
|---|---|---|---|
onReady | ✅ | ❌ | ❌ |
onSurveyDisplayAllowed | ✅ | ❌ | ❌ |
onMessageDisplayAllowed | ✅ | ❌ | ❌ |
onSurveyShowed | ✅ | ✅ | ❌ |
onSurveyStarted | ✅ | ✅ | ❌ |
onQuestionReplied | ✅ | ✅ | ✅ |
onSurveyCompleted | ✅ | ✅ | ❌ |
onSurveyHidden | ✅ | ✅ | ❌ |
onMessageShowed | ✅ | ❌ | ✅ |
onMessageStarted | ✅ | ❌ | ✅ |
onMessageCompleted | ✅ | ❌ | ✅ |
onMessageHidden | ✅ | ❌ | ✅ |
Payload structure
Hook payloads are nested. They use the following shared types:
type Channel = {
id: string;
type: "widget" | "ios" | "android";
};
type User = {
anonymous_id: string;
userId?: string;
};
type Survey = {
id: string;
survey_position:
| "center-left"
| "center-center"
| "center-right"
| "bottom-left"
| "bottom-center"
| "bottom-right";
survey_format: "conversationnal" | "cards";
survey_size: 100;
};
type Message = {
id: string;
messagey_size: 100;
};
type ResponseStatus =
| "displayed"
| "started"
| "ended"
| "closed"
| "interrupted";
type ResponseItemQuestion = {
id: string;
title: string;
type: "text" | "video";
url?: string;
};
type ResponseItemAnswer = {
replied_at?: string;
fields?: {
type: "string" | "number" | "boolean" | "none" | "time" | "file";
text?: string;
number?: number;
boolean?: boolean;
time?: string;
}[];
};
type ResponseItem = {
question: ResponseItemQuestion;
answer: ResponseItemAnswer;
};
Exact callback payloads:
onReady(payload: { channel: Channel; user: User }): void;
onSurveyDisplayAllowed(payload: {
channel: Channel;
user: User;
survey: Survey;
}): boolean;
onMessageDisplayAllowed(payload: {
channel: Channel;
user: User;
survey: Survey;
}): boolean;
onSurveyShowed(payload: {
channel: Channel;
user: User;
survey: Survey;
response: {
id: string;
items: ResponseItem[];
};
}): void;
onSurveyStarted(payload: {
channel: Channel;
user: User;
survey: Survey;
response: {
id: string;
};
}): void;
onSurveyCompleted(payload: {
channel: Channel;
user: User;
survey: Survey;
response: {
id: string;
items: ResponseItem[];
};
}): void;
onSurveyHidden(payload: {
channel: Channel;
user: User;
survey: Survey;
response: {
id: string;
items: ResponseItem[];
hide_reason: ResponseStatus;
};
}): void;
onQuestionReplied(payload: {
channel: Channel;
user: User;
survey: Survey;
response: {
id: string;
status: null;
question: ResponseItemQuestion;
answer: ResponseItemAnswer;
items: ResponseItem[];
};
}): void;
onMessageShowed(payload: {
channel: Channel;
user: User;
message: Message;
response: {
id: string;
items: ResponseItem[];
};
}): void;
onMessageStarted(payload: {
channel: Channel;
user: User;
message: Message;
response: {
id: string;
};
}): void;
onMessageCompleted(payload: {
channel: Channel;
user: User;
message: Message;
response: {
id: string;
items: ResponseItem[];
};
}): void;
onMessageHidden(payload: {
channel: Channel;
user: User;
message: Message;
response: {
id: string;
items: ResponseItem[];
hide_reason: ResponseStatus;
};
}): void;
On init
import * as Screeb from "@screeb/sdk-browser";
Screeb.init("<YOUR-CHANNEL-ID>", undefined, undefined, {
version: "1.0.0",
onReady: (payload) => {
console.log("Screeb ready", payload);
},
onSurveyShowed: (payload) => {
console.log("Survey shown", payload);
},
onSurveyCompleted: (payload) => {
console.log("Survey completed", payload);
},
onMessageShowed: (payload) => {
console.log("Message shown", payload);
},
});
On surveyStart
Screeb.surveyStart("<SURVEY_ID>", undefined, true, {}, {
onSurveyCompleted: (payload) => {
console.log("Survey completed", payload);
},
});
On messageStart
Screeb.messageStart("<MESSAGE_ID>", true, {}, {
onMessageHidden: (payload) => {
console.log("Message hidden", payload);
},
});
For complete hook payload definitions, see the JS tag hooks reference.