Skip to main content

API Reference

Detour

Main SDK singleton. All methods are @JvmStatic for Java interoperability.

Methods

initialize

Detour.initialize(context: Context, config: DetourConfig): Unit

Initializes the SDK. Must be called once before any other SDK method — typically in Application.onCreate() or at the start of your launcher Activity. Sets up the internal API client, fingerprint collector, install referrer helper, and analytics subsystem. Throws if apiKey or appId are blank.

suspend fun Detour.processLink(intent: Intent): LinkResult

Main entry point for link processing. Automatically detects the link source from the given Intent and returns the appropriate result. Checks in priority order:

  1. App Links — HTTP/HTTPS URLs from verified domains (returns LinkType.VERIFIED)
  2. Scheme links — custom scheme deep links, if linkProcessingMode is ALL (returns LinkType.SCHEME)
  3. Deferred links — queries the Detour API on first launch (returns LinkType.DEFERRED)

If a web URL has a single path segment (short link), the SDK resolves it to the full destination URL before returning.

suspend fun Detour.getDeferredLink(): LinkResult

Resolves deferred links only, ignoring App Links and scheme links. Useful when you handle other link types separately. Returns LinkResult.NotFirstLaunch on subsequent calls within the same session — deferred matching runs only once per app install.

suspend fun Detour.resolveShortLink(url: String): ShortLinkResponse?

Resolves a Detour short link URL to its full destination. Returns null if resolution fails or the URL is not a valid short link.

DetourDelegate

Lifecycle-aware helper that wraps Detour.processLink() for Activity / Fragment integrations. Manages coroutine scope internally and delivers results via callback.

Constructor

DetourDelegate(
lifecycleOwner: LifecycleOwner,
config: DetourConfig,
onLinkResult: (LinkResult) -> Unit,
)
ParameterTypeDescription
lifecycleOwnerLifecycleOwnerThe Activity, AppCompatActivity, or Fragment that owns this delegate
configDetourConfigSDK configuration. Also used to call Detour.initialize() if not already initialized
onLinkResult(LinkResult) -> UnitCallback invoked with the link processing result

Methods

onCreate

fun onCreate(intent: Intent): Unit

Call from Activity.onCreate(). Processes the launching intent for App Links, scheme links, and deferred links.

onNewIntent

fun onNewIntent(intent: Intent): Unit

Call from Activity.onNewIntent(). Processes links received while the app is already running.

DetourConfig

SDK configuration object. Accepts required credentials and optional behavioral settings.

Data class

data class DetourConfig(
val apiKey: String,
val appId: String,
val linkProcessingMode: LinkProcessingMode = LinkProcessingMode.ALL,
val storage: DetourStorage? = null,
)
FieldTypeRequiredDefaultDescription
apiKeyStringYesPublishable API key from the Detour dashboard. Used as a Bearer token for all API calls (deferred link matching, short-link resolution, analytics)
appIdStringYesUnique app identifier from the Detour dashboard. Used to route API requests to the correct app
linkProcessingModeLinkProcessingModeNoALLControls which link sources the SDK processes. See LinkProcessingMode for details on each value
storageDetourStorageNoSharedPreferencesCustom storage adapter for SDK persistence. The SDK stores a first-entrance flag (for deferred link matching) and a device ID (for analytics). Defaults to SharedPreferences-based storage

Java builder

For Java callers, a builder pattern is available:

DetourConfig.Builder(apiKey: String, appId: String)
.linkProcessingMode(LinkProcessingMode)
.storage(DetourStorage)
.build()

LinkResult

Sealed class returned by processLink() and getDeferredLink(). Pattern-match on the subtype to handle each outcome.

sealed class LinkResult {
data class Success(
val url: String,
val route: String,
val pathname: String,
val type: LinkType,
val params: Map<String, String>,
) : LinkResult()

data object NotFirstLaunch : LinkResult()
data object NoLink : LinkResult()
data class Error(val exception: Exception) : LinkResult()
}

Subtypes

SubtypeDescription
SuccessA link was successfully resolved. Contains the parsed link data — see fields below
NotFirstLaunchNo deferred link available because this is not the first app launch. Only returned by the deferred link flow
NoLinkNormal app launch without any deep link
ErrorAn error occurred during link processing. The exception field contains the cause

Success fields

FieldTypeDescription
urlStringFull URL that was matched or opened
routeStringIn-app route for navigation — path with query string, first path segment (app hash) stripped (e.g. /promo/123?utm=1)
pathnameStringRoute path without query string (e.g. /promo/123)
typeLinkTypeHow the link arrived — DEFERRED, VERIFIED, or SCHEME
paramsMap<String, String>Parsed query parameters as key-value pairs

LinkProcessingMode

enum class LinkProcessingMode {
ALL,
WEB_ONLY,
DEFERRED_ONLY,
}

Controls which link sources Detour.processLink() handles:

ValueBehavior
ALL (default)Processes all link sources: deferred links from the Detour API, App Links (verified HTTP/HTTPS URLs), and custom scheme deep links
WEB_ONLYSame as ALL but filters out custom scheme links. Only deferred links and App Links (HTTP/HTTPS) are processed
DEFERRED_ONLYOnly processes deferred links from the Detour API. Skips App Link and scheme link detection. Recommended when your navigation framework already handles runtime deep links

LinkType

enum class LinkType {
DEFERRED,
VERIFIED,
SCHEME,
}

Describes how the link arrived in the app:

ValueMeaning
DEFERREDThe link was obtained from the Detour deferred-link API. This happens when a user who doesn't have the app installed clicks a Detour link, installs the app, and opens it — the SDK retrieves the original link from the backend on first launch
VERIFIEDThe link arrived as an Android App Link — an HTTP/HTTPS URL from a verified domain that the OS delivered directly to your app
SCHEMEThe link arrived via a custom URL scheme (e.g. myapp://path). These are non-HTTP URLs that the OS routes to your app based on the registered intent filter

ShortLinkResponse

data class ShortLinkResponse(
val link: String,
val route: String?,
val parameters: String?,
)

Returned by Detour.resolveShortLink().

FieldTypeDescription
linkStringThe full destination URL after short-link resolution
routeString?Extracted in-app route, or null if not available
parametersString?Raw query parameter string, or null if none

DetourStorage

interface DetourStorage {
suspend fun getItem(key: String): String?
suspend fun setItem(key: String, value: String)
suspend fun removeItem(key: String) { }
}

Interface for custom storage adapters. The SDK persists a first-entrance flag (used for deferred link matching — only triggers on first app install) and a stable device ID (used for analytics). All methods are suspending functions.

By default, the SDK uses a SharedPreferences-based implementation. Provide a custom adapter if you need encrypted storage, DataStore, or another persistence layer. See Custom Storage for examples.

DetourAnalytics

Analytics module initialized by Detour.initialize(). All calls are fire-and-forget — they run on a background dispatcher and never propagate exceptions. Both methods are @JvmStatic for Java interoperability.

Methods

logEvent

DetourAnalytics.logEvent(eventName: DetourEventNames, data: Any? = null): Unit

Records a user action or custom event and sends it to the Detour backend. Pass one of the predefined DetourEventNames values. The optional data parameter accepts any Gson-serializable object (maps, primitives, data classes, etc.).

logRetention

DetourAnalytics.logRetention(eventName: String): Unit

Records a retention/lifecycle event for user engagement tracking with a free-form event name string.

DetourEventNames

CategoryEvent NameString Value
GeneralLoginlogin
Searchsearch
Shareshare
SignUpsign_up
TutorialBegintutorial_begin
TutorialCompletetutorial_complete
ReEngagere_engage
Inviteinvite
OpenedFromPushNotificationopened_from_push_notification
SalesAddPaymentInfoadd_payment_info
AddShippingInfoadd_shipping_info
AddToCartadd_to_cart
RemoveFromCartremove_from_cart
Refundrefund
ViewItemview_item
BeginCheckoutbegin_checkout
Purchasepurchase
AdImpressionad_impression