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
- LinkFortyNavObserver - Automatic screen-view tracking
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",
appToken = "at_a1b2c3d4..." // recommended for Cloud — enables organic-install attribution
)
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")
)Reports a screen view. Emits a screen_view event carrying the screen name and the previously tracked screen, stamped with the active last-click attribution context, so the dashboard can build a per-link screen-flow funnel.
suspend fun trackScreenView(
name: String,
properties: Map<String, Any>? = null
)Parameters:
name: Screen name (e.g., "ProductDetail"). Must not be blank.properties: Optional additional properties
Throws: LinkFortyError if tracking fails (including a blank screen name)
Example:
LinkForty.shared.trackScreenView("ProductDetail")For automatic tracking with Jetpack Navigation, use LinkFortyNavObserver.
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 appToken: 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)appToken: Public workspace token (LinkForty Cloud only). Recommended — required for organic installs (App Store discovery, social mentions, etc.) to be attributed to your workspace. Find it in the dashboard under Workspace Settings → App Token. Format:at_<32 hex chars>. Safe to ship in your app bundle.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?) -> UnitA NavController.OnDestinationChangedListener that automatically reports a screen_view (see trackScreenView) whenever the Jetpack Navigation destination changes.
Requires androidx.navigation, which your app already provides if it uses Jetpack Navigation. The SDK depends on it only as compileOnly, so apps that don't use Navigation are unaffected.
class LinkFortyNavObserver(
screenNameExtractor: (NavDestination) -> String? = ::defaultScreenName,
scope: CoroutineScope = CoroutineScope(Dispatchers.Main)
) : NavController.OnDestinationChangedListenerBy default a destination's route (Compose navigation) or label (XML nav graph) is used as the screen name; destinations with neither are skipped. Pass screenNameExtractor to customize.
Example:
import com.linkforty.sdk.navigation.LinkFortyNavObserver
navController.addOnDestinationChangedListener(LinkFortyNavObserver())All 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.