Skip to main content
Version: .NET MAUI SDK

Hooks

iOS limitation (v0.1.0)

iOS limitation in v0.1.0

Hook callbacks are not yet supported on iOS in v0.1.0. Hooks are registered and the version key is passed to the native SDK, but callback invocations from the iOS side are not wired in v0.1.0. This will be addressed in v0.2.0. Android hook callbacks work fully.

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 NameAvailable on InitSdk()Available on StartSurvey()Available on StartMessage()
onSurveyShowedYes ✅Yes ✅Yes ✅
onMessageShowedYes ✅Yes ✅Yes ✅
onSurveyStartedYes ✅Yes ✅Yes ✅
onMessageStartedYes ✅Yes ✅Yes ✅
onQuestionRepliedYes ✅Yes ✅Yes ✅
onSurveyCompletedYes ✅Yes ✅Yes ✅
onMessageCompletedYes ✅Yes ✅Yes ✅
onSurveyHiddenYes ✅Yes ✅Yes ✅
onMessageHiddenYes ✅Yes ✅Yes ✅
onAppStoreRatingTriggeredYes ✅Yes ✅Yes ✅
onReadyYes ✅No ❌No ❌
onSurveyDisplayAllowedYes ✅No ❌No ❌
onMessageDisplayAllowedYes ✅No ❌No ❌

Set hooks on SDK init

var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onReady"] = async (payload) =>
{
Console.WriteLine($"onReady: {payload}");
return null;
},
["onSurveyDisplayAllowed"] = async (payload) =>
{
Console.WriteLine($"onSurveyDisplayAllowed: {payload}");
// return false to prevent display
return true;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
properties: new Dictionary<string, object>
{
["isConnected"] = false,
["age"] = 29,
["product"] = "iPhone 13",
["email"] = "support@screeb.app"
},
hooks: hooks
);

Set hooks on survey start

var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onSurveyShowed"] = async (payload) =>
{
Console.WriteLine($"onSurveyShowed: {payload}");
return null;
}
}
};

await Screeb.StartSurvey(
surveyId: "<survey-id>",
allowMultipleResponses: true,
hiddenFields: new Dictionary<string, object>(),
ignoreSurveyStatus: true,
hooks: hooks
);

Set hooks on message start

var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onMessageShowed"] = async (payload) =>
{
Console.WriteLine($"onMessageShowed: {payload}");
return null;
}
}
};

await Screeb.StartMessage(
messageId: "<message-id>",
allowMultipleResponses: true,
hiddenFields: new Dictionary<string, object>(),
ignoreMessageStatus: true,
hooks: hooks
);

onSurveyShowed

Called when a survey is showed.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onSurveyShowed"] = async (payload) =>
{
Console.WriteLine($"onSurveyShowed: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);
Payload definition
{
channel: {
id: string,
type: "android" | "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
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onSurveyStarted"] = async (payload) =>
{
Console.WriteLine($"onSurveyStarted: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);
Payload definition
{
channel: {
id: string,
type: "android" | "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
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onQuestionReplied"] = async (payload) =>
{
Console.WriteLine($"onQuestionReplied: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onSurveyCompleted

Called when a survey is completed.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onSurveyCompleted"] = async (payload) =>
{
Console.WriteLine($"onSurveyCompleted: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onSurveyHidden

Called when a survey is hidden.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onSurveyHidden"] = async (payload) =>
{
Console.WriteLine($"onSurveyHidden: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onMessageShowed

Called when a message is showed.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onMessageShowed"] = async (payload) =>
{
Console.WriteLine($"onMessageShowed: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onMessageStarted

Called when a message is started.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onMessageStarted"] = async (payload) =>
{
Console.WriteLine($"onMessageStarted: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onMessageCompleted

Called when a message is completed.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onMessageCompleted"] = async (payload) =>
{
Console.WriteLine($"onMessageCompleted: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onMessageHidden

Called when a message is hidden.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onMessageHidden"] = async (payload) =>
{
Console.WriteLine($"onMessageHidden: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onAppStoreRatingTriggered

Called when app store rating is triggered.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onAppStoreRatingTriggered"] = async (payload) =>
{
Console.WriteLine($"onAppStoreRatingTriggered: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onReady

Called when the SDK is ready.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onReady"] = async (payload) =>
{
Console.WriteLine($"onReady: {payload}");
return null;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onSurveyDisplayAllowed

Called before a survey is about to be displayed. Return false to prevent the display.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onSurveyDisplayAllowed"] = async (payload) =>
{
Console.WriteLine($"onSurveyDisplayAllowed: {payload}");
// Return false to prevent display
return true;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);

onMessageDisplayAllowed

Called before a message is about to be displayed. Return false to prevent the display.

Example
var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onMessageDisplayAllowed"] = async (payload) =>
{
Console.WriteLine($"onMessageDisplayAllowed: {payload}");
// Return false to prevent display
return true;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
hooks: hooks
);