Skip to main content
Version: .NET MAUI SDK

Examples

Practical, task-based code snippets for the .NET MAUI SDK.

Basic setupโ€‹

If the user is already authenticated when the app loads, pass their identity directly to InitSdk() to avoid creating an anonymous user:

using Screeb.Maui;

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "<USER-ID>",
properties: new Dictionary<string, object>
{
["email"] = "support@screeb.app",
["plan"] = "pro"
}
);

If the user isn't authenticated yet, init without identity and call SetIdentity() after login (see below).

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

Identify a user after loginโ€‹

When a user logs in post-init, identify them:

using Screeb.Maui;

await Screeb.SetIdentity("user-123", new Dictionary<string, object>
{
["email"] = "support@screeb.app",
["plan"] = "premium",
["signup_date"] = DateTime.Parse("2024-01-15")
});

Track an eventโ€‹

Track user actions with optional properties for context:

using Screeb.Maui;

// Simple event
await Screeb.TrackEvent("button_clicked");

// Event with properties
await Screeb.TrackEvent("checkout_completed", new Dictionary<string, object>
{
["amount"] = 99.99,
["currency"] = "USD",
["items_count"] = 3,
["payment_method"] = "credit_card"
});

Start a surveyโ€‹

Trigger a survey programmatically when a user performs an action:

using Screeb.Maui;

// Start a specific survey
await Screeb.StartSurvey("<SURVEY-ID>");

// Prevent multiple responses
await Screeb.StartSurvey("<SURVEY-ID>", allowMultipleResponses: false);

// Add hidden fields for context
await Screeb.StartSurvey(
"<SURVEY-ID>",
allowMultipleResponses: true,
hiddenFields: new Dictionary<string, object>
{
["source"] = "checkout_page",
["cart_value"] = 149.99
}
);

Use hooksโ€‹

Set up hooks during initialization to react to survey events:

using Screeb.Maui;

var hooks = new ScreebHooks
{
Version = "1.0.0",
Callbacks = new Dictionary<string, Func<string, Task<object?>>>
{
["onReady"] = async (payload) =>
{
Console.WriteLine($"Screeb SDK is ready: {payload}");
return null;
},
["onSurveyCompleted"] = async (payload) =>
{
Console.WriteLine($"Survey completed: {payload}");
// Track completion in your analytics
// Show a thank you message
return null;
},
["onSurveyDisplayAllowed"] = async (payload) =>
{
Console.WriteLine($"Survey about to display: {payload}");
// Return false to prevent display
return true;
}
}
};

await Screeb.InitSdk(
channelId: "<YOUR-CHANNEL-ID>",
userId: "user-123",
properties: new Dictionary<string, object>
{
["email"] = "support@screeb.app"
},
hooks: hooks
);

Reset on logoutโ€‹

Clear the current user identity when they log out:

using Screeb.Maui;

private async Task HandleLogout()
{
// Clear user session
await Screeb.ResetIdentity();
// Navigate to login screen
}

Full example projectโ€‹

For a complete working example, check out the example-maui directory in the Screeb SDK repository.