Skip to main content
Configure how your app handles navigation, analytics events, and experience lifecycle callbacks.
Important (iOS)On iOS, callback instances must be stored in static fields to prevent the .NET garbage collector from finalizing them. The native Swift SDK holds weak Objective-C references to these objects, which the .NET GC cannot see.
Register callbacks before calling Setup() on Android so events fired during initialization are not lost. Register callbacks after calling Setup() on iOS.
Handles deep link routes triggered by Userpilot experiences (for example, when a user taps a CTA link inside an experience).

iOS

public class AppNavigationCallbackiOS : Userpilot.UserpilotNavigationCallback
{
    public override void OnNavigate(string url)
    {
        Console.WriteLine($"[Userpilot] Navigate to: {url}");
        // Handle navigation to the URL
    }
}

// Store in a static field to prevent GC
private static AppNavigationCallbackiOS? _navCallback;

// Register the callback (after SDK setup)
_navCallback = new AppNavigationCallbackiOS();
Userpilot.UserpilotSdk.SetNavigationCallback(_navCallback);

Android

public class AppNavigationCallback : Java.Lang.Object, Userpilot.UserpilotSdk.Companion.INavigationCallback
{
    public void OnNavigate(string url)
    {
        Android.Util.Log.Info("Userpilot", $"Navigate to: {url}");
        // Handle navigation to the URL
    }
}

// Register the callback (before SDK setup)
Userpilot.UserpilotSdk.SetNavigationCallback(new AppNavigationCallback());

Analytics Callback

Receives callbacks whenever the SDK tracks an event, screen, or identifies a user. Use this to integrate with another analytics tool or log events for debugging.

iOS

public class AppAnalyticsCallbackiOS : Userpilot.UserpilotAnalyticsCallback
{
    public override void OnAnalyticTracked(string analytic, string value, NSDictionary? properties)
    {
        Console.WriteLine($"[Userpilot] {analytic}: {value}");
    }
}

private static AppAnalyticsCallbackiOS? _analyticsCallback;

_analyticsCallback = new AppAnalyticsCallbackiOS();
Userpilot.UserpilotSdk.SetAnalyticsCallback(_analyticsCallback);

Android

public class AppAnalyticsCallback : Java.Lang.Object, Userpilot.UserpilotSdk.Companion.IAnalyticsCallback
{
    public void OnAnalyticTracked(string analytic, string value, string properties)
    {
        Android.Util.Log.Info("Userpilot", $"{analytic}: {value} | {properties}");
    }
}

Userpilot.UserpilotSdk.SetAnalyticsCallback(new AppAnalyticsCallback());

Experience Callback

Receives callbacks when Userpilot experiences (flows, surveys, NPS) start, complete, are dismissed, or progress through steps. Experience Types: Flow, Survey, NPS Experience States: Started, Completed, Dismissed, Skipped, Submitted

iOS

public class AppExperienceCallbackiOS : Userpilot.UserpilotExperienceCallback
{
    public override void OnExperienceStateChanged(
        string experienceType, int experienceId, string experienceState)
    {
        Console.WriteLine($"[Userpilot] {experienceType} #{experienceId} -> {experienceState}");
    }

    public override void OnExperienceStepStateChanged(
        string experienceType, NSNumber experienceId, int stepId,
        string stepState, int step, int totalSteps)
    {
        Console.WriteLine($"[Userpilot] {experienceType} #{experienceId} step {step}/{totalSteps} -> {stepState}");
    }
}

private static AppExperienceCallbackiOS? _experienceCallback;

_experienceCallback = new AppExperienceCallbackiOS();
Userpilot.UserpilotSdk.SetExperienceCallback(_experienceCallback);

Android

public class AppExperienceCallback : Java.Lang.Object, Userpilot.UserpilotSdk.Companion.IExperienceCallback
{
    public void OnExperienceStateChanged(
        string experienceType, int experienceId, string experienceState)
    {
        Android.Util.Log.Info("Userpilot", $"{experienceType} #{experienceId} -> {experienceState}");
    }

    public void OnExperienceStepStateChanged(
        string experienceType, int experienceId, int stepId,
        string stepState, int step, int totalSteps)
    {
        Android.Util.Log.Info("Userpilot", $"{experienceType} #{experienceId} step {step}/{totalSteps} -> {stepState}");
    }
}

Userpilot.UserpilotSdk.SetExperienceCallback(new AppExperienceCallback());