API reference
Every export, method, field and error code in react-native-lander 0.1.1.
Everything below comes from one import:
import { Lander, LanderError, LanderLink, landerSdkVersion, useLanderDeepLink } from 'react-native-lander'
import type { LanderConfidence, LanderShortLink } from 'react-native-lander'| Export | Kind |
|---|---|
Lander | The SDK object |
useLanderDeepLink | React hook |
LanderLink | Type of a link delivered to the app, and helpers to build one |
LanderShortLink | Type of a link created with createLink |
LanderConfidence | Type: how sure Lander is |
LanderError | The error every call rejects with |
landerSdkVersion | The SDK version string |
LanderOptions, CreateLinkOptions, TrackEventOptions | Option types of initialize, createLink and trackEvent |
LanderLinkInit, LanderParamValue, LanderLinkListener, LanderSubscription | Supporting types |
Lander
const Lander: {
initialize(options: LanderOptions): Promise<void>
onDeepLink(listener: (link: LanderLink) => void): LanderSubscription
getInitialLink(): Promise<LanderLink | null>
createLink(options?: CreateLinkOptions): Promise<LanderShortLink>
claimHandoff(userId: string): Promise<LanderLink | null>
trackEvent(name: string, properties?: Record<string, unknown>, options?: TrackEventOptions): Promise<void>
readonly installId: string | null
}A single object; you never create an instance. Every method that returns a Promise reports its errors as a rejected LanderError, never by throwing synchronously.
Lander.initialize
Lander.initialize(options: {
apiKey: string
baseUrl?: string // default 'https://api.golander.link'
enableLogging?: boolean // default false
}): Promise<void>Starts the SDK. Call it once, as early as possible (module scope of your entry file). Loads or creates the install ID, starts listening for links and app state, reads the launch link, then reports the launch with POST /v1/sdk/init in the background. The returned Promise does not wait for the network.
Prop
Type
- Rejects with
invalid_argumentwhenapiKey, trimmed, is a secret key or not a publishable key (pk_test_orpk_live_followed by at least 24 letters or digits). The key is never included in the error. - Never rejects for network errors.
- A second call is ignored and returns the Promise of the first call.
- Without the native module (Expo Go, or an app not rebuilt), warns once, keeps the install ID in memory and skips the launch report.
Lander.onDeepLink
Lander.onDeepLink(listener: (link: LanderLink) => void): { remove(): void }Calls listener with every link the app receives: Universal Links, App Links, custom scheme URLs and deferred links. Call remove() on the returned subscription to stop.
- Safe to call at any time, even before
initialize. - Links that arrive while nobody listens are buffered and replayed, in order, to the next listener, in a microtask after
onDeepLinkreturns. - Every active listener receives live links.
- Includes the launch link unless
getInitialLinkclaimed it first. - Unknown links and links that could not be resolved are delivered with
isResolved === falseand onlyurlset. - Does not include links returned by
claimHandoff. - Throws a
LanderError(invalid_argument) synchronously whenlisteneris not a function.
Lander.getInitialLink
Lander.getInitialLink(): Promise<LanderLink | null>The link that launched the app, or null. On a first launch this may be a deferred link, so it waits for the launch report in that case. Delivered once: resolves null if onDeepLink or an earlier call already delivered it, and after this call onDeepLink will not deliver it.
Rejects with not_initialized before initialize.
Lander.createLink
Lander.createLink(options?: {
path?: string // default '/'
params?: Record<string, string | number | boolean> // default {}
title?: string
campaign?: string
channel?: string
tags?: string[]
iosFallbackUrl?: string
androidFallbackUrl?: string
webFallbackUrl?: string
ogTitle?: string
ogDescription?: string
ogImageUrl?: string
expiresAt?: Date | string
}): Promise<LanderShortLink>Creates a short link with POST /v1/sdk/links. The slug is random and the domain is the project's default domain.
Prop
Type
- Rejects with
invalid_argumentwhenpathdoes not start with/, aparamsvalue is not a string, number or boolean, orexpiresAtis not a valid date. - Rejects with a
LanderErrorcarrying the API or network error when the request fails after retries. - Rejects with
not_initializedbeforeinitialize.
See Creating links.
Lander.claimHandoff
Lander.claimHandoff(userId: string): Promise<LanderLink | null>Claims the link your backend bound to this user with POST /v1/handoffs, after sign in. Resolves the link (isDeferred true, confidence 'deterministic', method 'authenticated_handoff') or null when nothing is pending. The newest pending handoff wins and every pending one for the user is cleared.
- The link is only returned, never also delivered to
onDeepLink. - Rejects with
invalid_argumentwhenuserId, trimmed, is empty or longer than 256 characters. - Rejects with a
LanderErrorwhen the request fails after retries, or with codeinstall_not_registeredwhen the install could not be registered yet (the SDK retries that first), orinvalid_responsefor an answer it cannot use. - Rejects with
not_initializedbeforeinitialize.
See Deferred links.
Lander.trackEvent
Lander.trackEvent(
name: string,
properties?: Record<string, unknown>, // default {}
options?: { linkId?: string | null },
): Promise<void>Records a custom event in the on device queue, which sends it in batches with retries. Resolves once the event is queued.
Prop
Type
- Rejects with
invalid_argumentfor an invalidname, alinkIdthat is not a UUID, or properties that cannot be sent as JSON (functions, symbols, bigints, non finite numbers, cycles,Dateand other class instances). - Never rejects for network errors.
- Rejects with
not_initializedbeforeinitialize.
See Events.
Lander.installId
Lander.installId: string | nullThe random UUID v4 of this install, once initialize has resolved; null before. Stored outside backups and removed on uninstall.
useLanderDeepLink
function useLanderDeepLink(listener: (link: LanderLink) => void): voidSubscribes to Lander.onDeepLink in an effect while the component is mounted and removes the subscription on unmount. The latest listener is always called, so it does not need to be memoized. Use it once, near the root, where your navigator is available.
LanderLink
interface LanderLink {
readonly url: string
readonly linkId: string | null
readonly shortUrl: string | null
readonly path: string | null
readonly route: string
readonly params: Readonly<Record<string, string | number | boolean>>
readonly campaign: string | null
readonly channel: string | null
readonly isDeferred: boolean
readonly confidence: LanderConfidence
readonly method: string | null
readonly isResolved: boolean
}A deep link delivered to the app: a frozen plain object, safe to pass as a navigation param or serialize as JSON. When Lander knows the link, the fields mirror the ResolvedLink returned by the API. When it does not (unknown link, custom scheme URL, network unavailable) only url is set and isResolved is false.
Prop
Type
route examples:
url | path | route |
|---|---|---|
https://acme.golander.link/p-123 | '/product/123' | /product/123 |
https://acme.golander.link/unknown | null | /unknown |
acmeshop://product/123?color=red | null | /product/123?color=red |
acmeshop:// | null | / |
Helpers
LanderLink is also a value with three functions that build links, for example in your own tests. See Testing.
LanderLink.create(init: {
url: string
linkId?: string | null
shortUrl?: string | null
path?: string | null
params?: Record<string, string | number | boolean>
campaign?: string | null
channel?: string | null
isDeferred?: boolean // default false
confidence?: LanderConfidence // default 'unattributed'
method?: string | null
}): LanderLink
/** A link Lander could not resolve. Only url is set. */
LanderLink.unresolved(url: string): LanderLink
/** Builds a link from a ResolvedLink JSON object. url falls back to the link's own URL. */
LanderLink.fromJson(json: Record<string, unknown>, url?: string): LanderLinkroute and isResolved are computed from the other fields. fromJson never throws: fields of an unexpected type are treated as missing.
LanderShortLink
interface LanderShortLink {
readonly id: string
readonly url: string
readonly domain: string
readonly slug: string
readonly path: string
readonly params: Readonly<Record<string, string | number | boolean>>
readonly title: string | null
readonly campaign: string | null
readonly channel: string | null
readonly tags: readonly string[]
readonly expiresAt: string | null
readonly createdAt: string | null
}A short link created with Lander.createLink, as a frozen plain object.
Prop
Type
LanderConfidence
type LanderConfidence = 'deterministic' | 'probabilistic' | 'unattributed'| Value | Meaning |
|---|---|
'deterministic' | Matched by an exact identifier: a Universal Link or App Link open, an Android install referrer token, the iOS Continue in app page or an authenticated handoff. |
'probabilistic' | Matched by coarse signals (OS version, country, click time, optionally a network hash) within a short window. Only iOS deferred links of projects that opted in. |
'unattributed' | No link could be tied to this open. Any other value from the API is read as this. |
LanderError
class LanderError extends Error {
readonly code: string
readonly message: string
readonly statusCode: number | null
readonly retryAfter: number | null
get isRetryable(): boolean
}The only error type the SDK uses. Check it with e instanceof LanderError and branch on code.
Prop
Type
Client side codes:
code | Meaning |
|---|---|
invalid_argument | A programming mistake in the arguments: a bad key, path, params, expiresAt, event name, properties, linkId or userId. |
not_initialized | A method that needs the SDK was called before Lander.initialize. |
network_error | The request could not be sent or no response arrived. |
timeout | No response within 10 seconds. |
invalid_response | A response that is not the JSON Lander sends (for example a captive portal page). |
install_not_registered | claimHandoff could not register this install with Lander yet. |
API error codes you may see from the SDK endpoints: validation_error, invalid_domain, destination_blocked (400), invalid_api_key (401), wrong_key_kind, project_suspended (403), install_not_found (404), rate_limited, link_quota_exceeded (429), internal_error (500).
toString() returns LanderError(code, statusCode): message.
landerSdkVersion
const landerSdkVersion: string // '0.1.1'The version reported to the API as sdkVersion and in the X-Lander-Sdk header.
Network behavior
The SDK only talks to Lander's public API, never to a database.
| Endpoint | Called by | Attempts |
|---|---|---|
POST /v1/sdk/init | initialize, every launch; again when the app becomes active, before claimHandoff and before event sends while no report has succeeded | 3 on a first launch, 1 otherwise |
POST /v1/sdk/resolve | Every http or https link that opens the app | 2 |
POST /v1/sdk/events | The event queue | 1 per flush; the queue retries with backoff |
POST /v1/sdk/links | createLink | 3 |
POST /v1/sdk/handoffs/claim | claimHandoff | 3 |
- Every request sends
Authorization: Bearer <publishable key>,Content-Type: application/jsonandX-Lander-Sdk: react-native/0.1.1. The launch report'splatformisPlatform.OS(iosorandroid). - Every attempt has a 10 second timeout.
- Retries happen only for network errors, timeouts,
invalid_response, 408, 429 and 5xx, with exponential backoff from 500 ms up to 4 s (or longer ifRetry-Afterasks). One call waits at most 10 seconds in total between attempts; a longerRetry-Afterends the retries.link_quota_exceededis never retried. - A 2xx response must be a JSON object (a 204 may be empty), otherwise the call fails with
invalid_response. appVersionandosVersionare cut to 50 characters.- Every write carries an
Idempotency-Keythat stays the same across retries, so a retry never creates a second link or claim.POST /v1/sdk/initignores the key: the API keeps one record per install ID, so a repeated launch report never creates a second install.