Skip to main content
Configure how your app handles navigation, analytics events, and experience lifecycle callbacks. Defines how your app handles deep link route triggers configured in Userpilot experiences, requiring you to route the user to the appropriate location.
public interface UserpilotNavigationHandler {
     public fun navigateTo(uri: Uri)
}
The Userpilot SDK automatically handles navigation if you haven’t implemented UserpilotNavigationHandler. When a deep link with a defined scheme and host is present in the manifest file, the SDK will open the corresponding Activity. If the link is external, the SDK will handle it appropriately. For complete control over link handling, implement UserpilotNavigationHandler to customize behavior for all link types. The useInAppBrowser flag (when you do not implement UserpilotNavigationHandler) determines whether to open URLs using an in-app browser (e.g., Chrome Custom Tabs) or fall back to the system browser.
  • When useInAppBrowser is true: opens using Chrome Custom Tabs for a faster, integrated experience.
  • When useInAppBrowser is false or not set: opens using the default system browser or another fallback.

Analytics Listener

Receives callbacks whenever the SDK tracks an event, screen, or identifies a user. Use this to integrate with another analytics tool.
public interface UserpilotAnalyticsListener {

    /**
     * Notifies the listener when a Userpilot analytics event is tracked.
     *
     * @param type The type of analytic being tracked. Possible values are:
     * - `Identify`: Represents an identify event.
     * - `Screen`: Represents a screen tracking event.
     * - `Event`: Represents a custom event.
     * @param value The primary value of the analytic being tracked:
     * - For `Identify`: The user ID.
     * - For `Screen`: The screen title.
     * - For `Event`: The event name.
     * @param properties Additional context or metadata associated with the analytic, provided as a `Payload` object.
     */
    public fun didTrack(type: UserpilotAnalytic, value: String, properties: Payload)
}

public enum class UserpilotAnalytic {
    Identify,
    Screen,
    Event
}

Experience Listener

Receives callbacks when experiences start, complete, or are dismissed, and when step state changes. Implement this to forward data to another destination or to react to user actions.
public interface UserpilotExperienceListener {

    /**
     * Notifies the listener of changes in the state of a Userpilot experience.
     *
     * @param experienceType The current experience type.
     * @param experienceId A unique identifier for the experience.
     * @param experienceState The current state of the experience.
     */
    public fun onExperienceStateChanged(
        experienceType: UserpilotExperienceType,
        experienceId: Int?,
        experienceState: UserpilotExperienceState
    )

    /**
     * Notifies the listener when the state of a specific step in a Userpilot experience changes.
     *
     * @param experienceType The current experience type.
     * @param experienceId A unique identifier for the experience.
     * @param stepId A unique identifier for the experience step.
     * @param stepState The current step state of the experience.
     * @param step The index of the current step in the experience.
     * @param totalSteps The total number of steps in the experience.
     */
    @Suppress("LongParameterList")
    public fun onExperienceStepStateChanged(
        experienceType: UserpilotExperienceType,
        experienceId: Int,
        stepId: Int,
        stepState: UserpilotExperienceState,
        step: Int?,
        totalSteps: Int?
    )
}

/**
 * Enum representing the possible states of a Userpilot experience.
 */
public enum class UserpilotExperienceType {
    Flow,
    Survey,
    NPS
}

/**
 * Enum representing the possible states of a Userpilot experience.
 */
public enum class UserpilotExperienceState {
    /**
     * Indicates that the experience has started.
     */
    Started,

    /**
     * Indicates that the experience has successfully completed.
     */
    Completed,

    /**
     * Indicates that the experience was dismissed before completion.
     */
    Dismissed,

    /**
     * Indicates that the experience/step was skipped.
     */
    Skipped,

    /**
     * Indicates that the experience/step was submitted.
     */
    Submitted
}