> ## Documentation Index
> Fetch the complete documentation index at: https://docs.userpilot.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Callbacks

> Configure navigation, analytics, and experience callbacks

Configure how your app handles navigation, analytics events, and experience lifecycle callbacks.

<Warning>
  **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.
</Warning>

Register callbacks **before** calling `Setup()` on Android so events fired during initialization are not lost. Register callbacks **after** calling `Setup()` on iOS.

***

## Navigation Callback

Handles deep link routes triggered by Userpilot experiences (for example, when a user taps a CTA link inside an experience).

### iOS

```csharp theme={null}
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

```csharp theme={null}
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

```csharp theme={null}
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

```csharp theme={null}
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

```csharp theme={null}
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

```csharp theme={null}
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());
```

<Frame>
  [**For any questions or concerns please reach out to support@userpilot.com**](mailto:support@userpilot.com)
</Frame>
