Docs

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'
ExportKind
LanderThe SDK object
useLanderDeepLinkReact hook
LanderLinkType of a link delivered to the app, and helpers to build one
LanderShortLinkType of a link created with createLink
LanderConfidenceType: how sure Lander is
LanderErrorThe error every call rejects with
landerSdkVersionThe SDK version string
LanderOptions, CreateLinkOptions, TrackEventOptionsOption types of initialize, createLink and trackEvent
LanderLinkInit, LanderParamValue, LanderLinkListener, LanderSubscriptionSupporting 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_argument when apiKey, trimmed, is a secret key or not a publishable key (pk_test_ or pk_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(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 onDeepLink returns.
  • Every active listener receives live links.
  • Includes the launch link unless getInitialLink claimed it first.
  • Unknown links and links that could not be resolved are delivered with isResolved === false and only url set.
  • Does not include links returned by claimHandoff.
  • Throws a LanderError (invalid_argument) synchronously when listener is not a function.
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(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_argument when path does not start with /, a params value is not a string, number or boolean, or expiresAt is not a valid date.
  • Rejects with a LanderError carrying the API or network error when the request fails after retries.
  • Rejects with not_initialized before initialize.

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_argument when userId, trimmed, is empty or longer than 256 characters.
  • Rejects with a LanderError when the request fails after retries, or with code install_not_registered when the install could not be registered yet (the SDK retries that first), or invalid_response for an answer it cannot use.
  • Rejects with not_initialized before initialize.

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_argument for an invalid name, a linkId that is not a UUID, or properties that cannot be sent as JSON (functions, symbols, bigints, non finite numbers, cycles, Date and other class instances).
  • Never rejects for network errors.
  • Rejects with not_initialized before initialize.

See Events.

Lander.installId

Lander.installId: string | null

The random UUID v4 of this install, once initialize has resolved; null before. Stored outside backups and removed on uninstall.

function useLanderDeepLink(listener: (link: LanderLink) => void): void

Subscribes 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.

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:

urlpathroute
https://acme.golander.link/p-123'/product/123'/product/123
https://acme.golander.link/unknownnull/unknown
acmeshop://product/123?color=rednull/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): LanderLink

route and isResolved are computed from the other fields. fromJson never throws: fields of an unexpected type are treated as missing.

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'
ValueMeaning
'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:

codeMeaning
invalid_argumentA programming mistake in the arguments: a bad key, path, params, expiresAt, event name, properties, linkId or userId.
not_initializedA method that needs the SDK was called before Lander.initialize.
network_errorThe request could not be sent or no response arrived.
timeoutNo response within 10 seconds.
invalid_responseA response that is not the JSON Lander sends (for example a captive portal page).
install_not_registeredclaimHandoff 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.

EndpointCalled byAttempts
POST /v1/sdk/initinitialize, every launch; again when the app becomes active, before claimHandoff and before event sends while no report has succeeded3 on a first launch, 1 otherwise
POST /v1/sdk/resolveEvery http or https link that opens the app2
POST /v1/sdk/eventsThe event queue1 per flush; the queue retries with backoff
POST /v1/sdk/linkscreateLink3
POST /v1/sdk/handoffs/claimclaimHandoff3
  • Every request sends Authorization: Bearer <publishable key>, Content-Type: application/json and X-Lander-Sdk: react-native/0.1.1. The launch report's platform is Platform.OS (ios or android).
  • 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 if Retry-After asks). One call waits at most 10 seconds in total between attempts; a longer Retry-After ends the retries. link_quota_exceeded is never retried.
  • A 2xx response must be a JSON object (a 204 may be empty), otherwise the call fails with invalid_response.
  • appVersion and osVersion are cut to 50 characters.
  • Every write carries an Idempotency-Key that stays the same across retries, so a retry never creates a second link or claim. POST /v1/sdk/init ignores the key: the API keeps one record per install ID, so a repeated launch report never creates a second install.

On this page