Creating links
Make short links from inside the app for share and invite flows with Lander.createLink.
Lander.createLink creates a Lander short link from the app, for example when someone taps Share on a product or Invite a friend. The link works like one made in the dashboard: it opens your app on the right screen, or sends people without the app to the App Store or your website.
Create a link
import Lander
import SwiftUI
struct ShareProductButton: View {
let id: String
let name: String
@State private var link: URL?
@State private var error: String?
var body: some View {
Group {
if let link {
ShareLink(item: link) // iOS 16 and later
} else {
Button("Share") { Task { await create() } }
}
}
.alert("Could not create a link", isPresented: .constant(error != nil)) {
Button("OK") { error = nil }
} message: {
Text(error ?? "")
}
}
private func create() async {
do {
let short = try await Lander.createLink(
path: "/product/\(id)",
params: ["productId": .string(id)],
title: name,
channel: "share"
)
link = short.url
} catch let lander as LanderError {
error = lander.message
} catch {
self.error = error.localizedDescription
}
}
}link.url is the shareable URL, for example https://acme.golander.link/x7Kp2Qa. Hand it to ShareLink, UIActivityViewController or UIPasteboard.
When someone opens that link, your app receives a LanderLink with path == "/product/123" and params == ["productId": "123"]. See Receiving links.
Parameters
static func createLink(
path: String = "/",
params: [String: LanderParamValue] = [:],
title: String? = nil,
campaign: String? = nil,
channel: String? = nil,
tags: [String] = [],
iosFallbackURL: URL? = nil,
androidFallbackURL: URL? = nil,
webFallbackURL: URL? = nil,
ogTitle: String? = nil,
ogDescription: String? = nil,
ogImageURL: URL? = nil,
expiresAt: Date? = nil
) async throws -> LanderShortLinkProp
Type
What you cannot choose from the app:
- The slug is always random (7 characters).
- The domain is the project's default domain.
- The environment follows the key: a
pk_test_key creates test links, apk_live_key creates live links.
Fallback URLs change deferred linking
An iOS fallback URL sends iPhone users without the app to that URL instead of the App Store, which also skips the Continue in app page. Likewise an Android fallback URL means no install referrer token on Android. Leave them empty if you want deferred deep links. See Deferred links.
The result
createLink returns a LanderShortLink, a Sendable, Hashable struct:
| Field | Type | Example |
|---|---|---|
id | String | Link ID (UUID) |
url | URL | https://acme.golander.link/x7Kp2Qa |
domain | String | acme.golander.link |
slug | String | x7Kp2Qa |
path | String | /product/123 |
params | [String: LanderParamValue] | ["productId": "123"] |
title, campaign, channel | String? | As sent |
tags | [String] | As sent |
expiresAt, createdAt | Date? | Parsed from the API |
description returns the URL, so "Check this out: \(link)" reads naturally.
Errors
createLink throws a LanderError. Before it sends anything, it throws:
invalid_argumentwhenpathdoes not start with/.not_initializedbeforeLander.initialize.
Everything else is checked by the API:
code | statusCode | Meaning |
|---|---|---|
validation_error | 400 | A field is too long or malformed (see the limits above). |
destination_blocked | 400 | A fallback URL failed Lander's safety screening. |
rate_limited | 429 | Too many links from this install (20 per minute) or project (60 per minute). retryAfter says when to try again, in seconds. |
link_quota_exceeded | 429 | The project created 1000 links in the last 24 hours. |
invalid_api_key | 401 | The publishable key is wrong or revoked. |
network_error, timeout | nil | No response after retries. |
invalid_response | nil or 2xx | The response was not the JSON Lander sends, for example a captive portal page. |
error.isRetryable is true for network errors, timeouts, invalid_response, 408, 429 (except link_quota_exceeded) and 5xx responses.
Retries never create two links
The SDK retries network errors, timeouts, 408, 429 and 5xx responses up to 3 attempts in total, with a short backoff (and waits at least as long as a Retry-After header asks). It waits at most 10 seconds in total between attempts, so a share button never hangs on a long Retry-After: the LanderError comes back with retryAfter instead. link_quota_exceeded is not retried. Every attempt carries the same Idempotency-Key, and Lander replays the first successful response for a repeated key, so a retry after a lost response returns the same link instead of creating a second one.
The install ID is sent along, which is how the API applies the per install rate limit.