Android (Kotlin) SDK
LIKYLY shows each user of your app the products they are most likely to want: “You may also like” on a product page, “Recommended for you” on the home screen. It learns from what your users do, browsing included.
This SDK runs on your users’ phones, so it uses the public key and covers what that key allows. It asks what to show, reports what users do and what happens to the recommendations, and keeps an anonymous id on the device. Your catalog is sent from your server, with a server SDK and the secret key.
Any Android app (minSdk 21+) and any JVM · Kotlin, suspend functions · a single dependency: kotlinx-coroutines
Installation
// app/build.gradle.kts
dependencies {
implementation("com.likyly:likyly-android:1.0.0")
}Published on Maven Central. Your app needs the INTERNET permission (<uses-permission android:name="android.permission.INTERNET" />).
The public key, never the secret key
Anything shipped in an app can be extracted from it. Use the public key (pk_…, Account page, “Public key”): all it can do is ask for recommendations and record events. The SDK rejects a secret key (sk_) or a developer key (lk_) as soon as it is created: you see the error right away, instead of shipping it in a release.
Quick start
1. One client and one session for the whole app
class ShopApp : Application() {
lateinit var likyly: Likyly
lateinit var session: LikylySession
override fun onCreate() {
super.onCreate()
likyly = Likyly(BuildConfig.LIKYLY_PUBLIC_KEY) // the PUBLIC key
session = LikylySession(FileAnonymousIdStore(filesDir)) // anonymous id, kept in the app
}
}2. Show a placement, and report what was seen and tapped
viewModelScope.launch {
val result = try {
likyly.recommend(PlacementRequest(
placement = "pdp-related", // set up once in LIKYLY
context = PlacementContext(itemId = productId, userId = userId, sessionId = session.anonymousId),
limit = 4))
} catch (e: LikylyException) {
null // show your own content
}
_items.value = result?.items.orEmpty()
}
// A card becomes visible (once per card), then is tapped:
likyly.events.impression(EventInput(itemId = item.itemId, sessionId = session.anonymousId,
recommendationId = result.recommendationId, placement = "pdp-related"))
likyly.events.click(EventInput(itemId = item.itemId, sessionId = session.anonymousId,
recommendationId = result.recommendationId, placement = "pdp-related"))A placement (pdp-related, home-for-you…) is set up once in LIKYLY, by your AI assistant or in the console. Send the recommendationId back with the impression and the click: LIKYLY learns which recommendations work, and you measure what they bring in.
3. What your users do elsewhere in the app
likyly.events.view(EventInput(itemId = "SKU-456", userId = userId, sessionId = session.anonymousId))
likyly.events.addToCart(EventInput(itemId = "SKU-456", sessionId = session.anonymousId, quantity = 1))
// A purchase: eventId makes sure a retry never counts it twice
likyly.events.purchase(EventInput(itemId = "SKU-456", userId = userId, quantity = 1,
eventId = "purchase_${orderId}_SKU-456"))
likyly.events.track("favorite", EventInput(itemId = "SKU-456", userId = userId)) // your own typesBrowsing alone is useful: a user who never buys still teaches LIKYLY which products go together, and gets recommendations. Set an eventId on purchases.
4. On sign-in
session.identify(likyly, userId) // on sign-in (calling it again does nothing)The device’s anonymous history then counts toward the user’s account.
Full example: A complete ViewModel.
If LIKYLY doesn't answer
Placement answers are kept in memory for an hour: coming back to a screen costs nothing. After a network error, a timeout, a 429 or a 5xx error, placement calls fail right away for 30 seconds (a “paused” error): the screen shows its own content instead of waiting. Both can be tuned or turned off:
Likyly(key, LikylyOptions(cache = RecommendCacheOptions(ttlSeconds = 600, pauseSeconds = 15)))
Likyly(key, LikylyOptions(cache = null)) // no cache, no pause
likyly.clearRecommendationCache() // forgets the cached answersRetries: 429, 502, 503, 504 and dropped connections are retried with a growing delay (a Retry-After of up to 60 s is honored). An event without an eventId is never retried after an ambiguous failure, so it is never recorded twice.
Errors
Everything thrown is a LikylyException:
| Error | When |
|---|---|
ValidationException | Invalid call, caught before sending, or a 422 from the API |
NetworkException | No HTTP response: offline, DNS, dropped connection |
TimeoutException | The request timed out |
PausedException | LIKYLY failed a few seconds ago (retryInSeconds): show your fallback content |
AuthenticationException | 401: missing, invalid or revoked key |
PermissionDeniedException | 403: for example an operation the public key does not allow |
NotFoundException | 404: for example an unknown placement |
RateLimitException | 429: see retryAfterSeconds |
ApiException | Any other error status (statusCode, requestId, body) |
Configuration
| Setting | Option | Default |
|---|---|---|
| Base URL | baseUrl | https://api.likyly.com |
| Catalog | catalog | your only catalog |
| Timeout | timeoutMillis (per attempt) | 10,000 |
| Retries | maxRetries | 2 |
| User-Agent suffix | userAgent | none |
| Recommendation cache | cache | 1 hour; 30 s pause after a failure |
| HTTP client | transport (LikylyTransport) | HttpURLConnection (OkHttp supported) |
Notes
- Java 8 bytecode in pure Kotlin: works in any Android app and on any JVM, without the Android Gradle plugin. No JSON or HTTP library is bundled.
- Coroutine cancellation is never wrapped in a
LikylyException: a screen you leave stops its calls cleanly. LikylySessionkeeps a random id in the app's private files: it is not the advertising id and is never shared with other apps.
Package: com.likyly:likyly-android on Maven Central. Source code: github.com/Likyly/likyly-recsys/tree/main/sdk/android.