Complete API reference for the LinkForty Android SDK.
- LinkForty - Main SDK class
- LinkFortyConfig - Configuration
- DeepLinkData - Deep link data model
- CreateLinkOptions - Link creation options
- CreateLinkResult - Link creation result
- InstallResponse - Attribution response
- UTMParameters - UTM tracking parameters
- LinkFortyError - Error types
- Type Aliases - Callback types
Main singleton class providing the SDK interface.
LinkForty.sharedThrows LinkFortyError.NotInitialized if initialize() has not been called.
Initializes the SDK with configuration and reports the install.
suspend fun initialize(
context: Context,
config: LinkFortyConfig,
attributionWindowHours: Int = 168,
deviceId: String? = null
): InstallResponseParameters:
context: Android Context (stored asapplicationContext)config: SDK configuration (required)attributionWindowHours: Attribution window in hours (default: 168 = 7 days)deviceId: Optional device identifier for attribution (e.g., GAID)
Returns: InstallResponse with attribution data
Throws: LinkFortyError if initialization fails
Example:
val config = LinkFortyConfig(
baseURL = "https://go.yourdomain.com",
apiKey = "your-api-key"
)
val response = LinkForty.initialize(context, config)
Log.d("LinkForty", "Install ID: ${response.installId}")Handles a deep link URI (App Link or custom scheme).
fun handleDeepLink(uri: Uri)Parameters:
uri: The deep link URI to handle
Example:
intent.data?.let { uri ->
LinkForty.shared.handleDeepLink(uri)
}Registers a callback for deferred deep links (install attribution).
fun onDeferredDeepLink(callback: DeferredDeepLinkCallback)Parameters:
callback: Lambda invoked with deep link data (or null for organic installs)
Example:
LinkForty.shared.onDeferredDeepLink { deepLinkData ->
if (deepLinkData != null) {
Log.d("LinkForty", "Attributed: ${deepLinkData.shortCode}")
} else {
Log.d("LinkForty", "Organic install")
}
}Registers a callback for direct deep links (when app opens from a link).
fun onDeepLink(callback: DeepLinkCallback)Parameters:
callback: Lambda invoked with URI and parsed deep link data
Example:
LinkForty.shared.onDeepLink { uri, deepLinkData ->
Log.d("LinkForty", "Opened from: $uri")
deepLinkData?.deepLinkPath?.let { navigateToPath(it) }
}Creates a short link programmatically.
suspend fun createLink(options: CreateLinkOptions): CreateLinkResultParameters:
options: Link creation options (see CreateLinkOptions)
Returns: CreateLinkResult with the shareable URL, short code, and link ID
Throws:
LinkFortyError.NotInitializedif SDK not initializedLinkFortyError.MissingApiKeyif no API key configured
Note: Requires an API key. If templateId is provided, uses POST /api/links. Otherwise, uses POST /api/sdk/v1/links.
Example:
val result = LinkForty.shared.createLink(
CreateLinkOptions(
deepLinkParameters = mapOf("route" to "VIDEO_VIEWER"),
title = "Check this out!",
utmParameters = UTMParameters(source = "app", campaign = "share")
)
)
Log.d("LinkForty", "Share: ${result.url}")Tracks a custom event.
suspend fun trackEvent(
name: String,
properties: Map<String, Any>? = null
)Parameters:
name: Event name (e.g., "purchase", "signup")properties: Optional event properties (must be JSON-serializable)
Throws: LinkFortyError if tracking fails
Example:
LinkForty.shared.trackEvent("purchase", mapOf("product_id" to "123", "amount" to 29.99))Tracks a revenue event.
suspend fun trackRevenue(
amount: BigDecimal,
currency: String,
properties: Map<String, Any>? = null
)Parameters:
amount: Revenue amount (must be non-negative)currency: Currency code (e.g., "USD", "EUR")properties: Optional additional properties
Throws: LinkFortyError if tracking fails
Example:
LinkForty.shared.trackRevenue(
amount = BigDecimal("29.99"),
currency = "USD",
properties = mapOf("product_id" to "123")
)Flushes the event queue, attempting to send all queued events.
suspend fun flushEvents()Clears the event queue without sending events.
fun clearEventQueue()Returns the number of events currently queued.
val queuedEventCount: IntReturns the install ID if available, null if not initialized.
fun getInstallId(): String?Returns the install attribution data if available.
fun getInstallData(): DeepLinkData?Returns whether this is the first launch.
fun isFirstLaunch(): BooleanClears all stored SDK data.
fun clearData()Resets the SDK to uninitialized state. Does NOT clear stored data — call clearData() first if needed.
fun reset()Configuration for the LinkForty SDK.
data class LinkFortyConfig(
val baseURL: String,
val apiKey: String? = null,
val debug: Boolean = false,
val attributionWindowHours: Int = 168
)Parameters:
baseURL: Backend URL (must be HTTPS except localhost/127.0.0.1/10.0.2.2)apiKey: API key (optional for self-hosted)debug: Enable debug logging (default: false)attributionWindowHours: Attribution window in hours (default: 168 = 7 days, max: 2160 = 90 days)
Validates the configuration. Throws LinkFortyError.InvalidConfiguration if validation fails.
fun validate()Deep link data model containing parsed link information.
val shortCode: String // Link short code (required)
val iosURL: String? // iOS deep link URL
val androidURL: String? // Android deep link URL
val webURL: String? // Fallback web URL
val utmParameters: UTMParameters? // UTM tracking parameters
val customParameters: Map<String, String>? // Custom query parameters
val deepLinkPath: String? // Deep link path for in-app routing
val appScheme: String? // App URI scheme
val clickedAt: String? // ISO 8601 click timestamp
val linkId: String? // Link UUID from the backendParses clickedAt as a java.time.Instant.
fun clickedAtDate(): Instant?Response from install attribution API.
val installId: String // Unique install ID
val attributed: Boolean // Whether install was attributed
val confidenceScore: Double // Confidence score (0-100)
val matchedFactors: List<String> // Matched fingerprint factors
val deepLinkData: DeepLinkData? // Deep link data if attributedOptions for creating a short link programmatically.
data class CreateLinkOptions(
val templateId: String? = null,
val templateSlug: String? = null,
val deepLinkParameters: Map<String, String>? = null,
val title: String? = null,
val description: String? = null,
val customCode: String? = null,
val utmParameters: UTMParameters? = null
)Result of creating a short link.
val url: String // Full shareable URL
val shortCode: String // Generated short code
val linkId: String // Link UUIDUTM parameters for campaign tracking.
val source: String? // Campaign source
val medium: String? // Campaign medium
val campaign: String? // Campaign name
val term: String? // Campaign term
val content: String? // Campaign contentval hasAnyParameter: Boolean // True if any parameter is setSealed class of errors thrown by the SDK.
class NotInitialized : LinkFortyError
class AlreadyInitialized : LinkFortyError
class InvalidConfiguration(detail: String) : LinkFortyError
class NetworkError(cause: Throwable) : LinkFortyError
class InvalidResponse(statusCode: Int?, responseMessage: String?) : LinkFortyError
class DecodingError(cause: Throwable) : LinkFortyError
class EncodingError(cause: Throwable) : LinkFortyError
class InvalidEventData(detail: String) : LinkFortyError
class InvalidDeepLinkUrl(detail: String) : LinkFortyError
class MissingApiKey : LinkFortyErrortry {
LinkForty.shared.trackEvent("test")
} catch (e: LinkFortyError) {
when (e) {
is LinkFortyError.NotInitialized -> Log.e("LinkForty", "Not initialized")
is LinkFortyError.NetworkError -> Log.e("LinkForty", "Network error", e.cause)
is LinkFortyError.InvalidEventData -> Log.e("LinkForty", "Invalid event: ${e.message}")
else -> Log.e("LinkForty", "Error: ${e.message}")
}
}typealias DeferredDeepLinkCallback = (DeepLinkData?) -> Unittypealias DeepLinkCallback = (Uri, DeepLinkData?) -> UnitAll SDK methods are thread-safe. Callbacks are executed on the main thread. Internal state is protected by Kotlin Mutex.
The SDK uses Kotlin coroutines for all asynchronous operations:
lifecycleScope.launch {
val response = LinkForty.initialize(context, config)
LinkForty.shared.trackEvent("test")
LinkForty.shared.flushEvents()
}Events are automatically queued when offline and sent when connectivity is restored. The queue has a maximum size of 100 events.
For more information, see the full documentation or LinkForty Docs.