安装
此流程仅需执行一次,即首次在项目中安装 SDK 时。后续更新请参阅 Update 部分的说明。 SDK 通过私有的 Cloudsmith Maven 仓库分发。
1
添加您的 Cloudsmith 凭证
在您的 将
local.properties 中添加 Kleep 提供的凭证:local.properties
cloudsmithUser=token
cloudsmithApiKey=TOKEN_VALUE
TOKEN_VALUE 替换为 Kleep 提供的 token。用户名为固定字符串 token。2
添加 Cloudsmith Maven 仓库
在您的
settings.gradle 或 settings.gradle.kts 中添加以下内容:val localProps = java.util.Properties().apply {
val localFile = file("local.properties")
if (localFile.exists()) load(localFile.inputStream())
}
dependencyResolutionManagement {
// ...
repositories {
// ...
maven {
url = uri("https://dl.cloudsmith.io/basic/kleep/kleep-android/maven/")
credentials {
username = localProps.getProperty("cloudsmithUser") ?: ""
password = localProps.getProperty("cloudsmithApiKey") ?: ""
}
}
}
}
def localProps = new Properties()
def localFile = file("local.properties")
if (localFile.exists()) localProps.load(localFile.newDataInputStream())
dependencyResolutionManagement {
// ...
repositories {
// ...
maven {
url "https://dl.cloudsmith.io/basic/kleep/kleep-android/maven/"
credentials {
username = localProps.getProperty("cloudsmithUser") ?: ""
password = localProps.getProperty("cloudsmithApiKey") ?: ""
}
}
}
}
3
添加依赖
在您模块的
build.gradle 或 build.gradle.kts 文件中添加以下内容以创建依赖:dependencies {
implementation 'com.klipfit:kleep-android:version'
}
dependencies {
implementation("com.klipfit:kleep-android:version")
}
旧版安装方式(JitPack)
旧版安装方式(JitPack)
以下说明适用于通过 JitPack 分发的旧版 SDK。
-
在您的
gradle.properties中添加以下 token:authToken=jp_9ibcequhrjtge3cmavt2k4sq6a -
在您的
settings.gradle或settings.gradle.kts中添加以下内容:dependencyResolutionManagement { // ... repositories { // ... maven { url "https://jitpack.io" credentials { username authToken } } } }dependencyResolutionManagement { // ... repositories { // ... maven { url = uri("https://jitpack.io") credentials(PasswordCredentials::class) { val authToken: String by settings username = authToken } } } } -
在您模块的
build.gradle或build.gradle.kts文件中添加以下内容以创建依赖:dependencies { implementation 'com.github.KlipFit:kleep-android:version' }dependencies { implementation("com.github.KlipFit:kleep-android:version") }
初始化
编辑您自定义的
Application 类,并提供 applicationContext 进行初始化。
import com.kleep.sdk.KleepResult
import com.kleep.sdk.Kleep
class CustomApplication: Application() {
override fun onCreate() {
super.onCreate()
Kleep.init(applicationContext)
}
}
Manifest.xml
<application
android:name=".CustomApplication"
...
>
...
</application>
导入
您可以在
MainActivity.kt 开头手动导入模块
import com.kleep.sdk.KleepResult
import com.kleep.sdk.Kleep
使用方法
SDK 提供 3 个方法:
| method | 加载时间 |
|---|---|
show | 首次启动:250ms,后续启动:50-250ms |
requestSize | 250ms |
track | 250ms |
方法 1:requestSize
此方法用于实现 CTA 的逻辑。
逻辑图示
此图示说明如何更新打开 Kleep 的 CTA。
https://www.figma.com/board/BlurZ01lR3JBQZeTUU98TE/Mobile---CTA-Logic?node-id=0-1&t=ccXWciNziIdfhgew-1
实现示例
Kleep.builder(this, onResult = {
when (it) {
is KleepResult.NotSupported -> {
// Handle the NotSupported case
}
is KleepResult.NoRecommendationYet -> {
// Handle the NoRecommendationYet case
}
is KleepResult.RecommendationFound -> {
val resultText = it.size
val variantId = it.variantId
Toast.makeText(this, resultText, Toast.LENGTH_SHORT).show()
}
else -> {
}
}
})
.setPackageName(packageName) // optional
.setLang(DEFAULT_LANGUAGE) // required: "fr", "en", "es", "it", "pt", "nl"
.setProductId("1234") // required
.setRetailer("retailer_name") // required
.setTrackingId("uuid") // empty if non-existent
.setCustomerId("unique_customer_id") // optional
.requestSize()
package com.kleep.sdk
/**
* Interface with the Kleep SDK in order to compute the recommended size of a product given some user information
*/
interface KleepDialogBuilder {
/**
* Set the package name, not required
* @return interface of the SDK builder
*/
fun setPackageName(packageName: String): KleepDialogBuilder
/**
* Set the language to use: required (default to FR)
* Values supported: "fr", "en", "es", "it", "pt", "nl"
* @return interface of the SDK builder
*/
fun setLang(lang: String): KleepDialogBuilder
/**
* Set product ID, required to compute the recommended size.
* @return interface of the SDK builder
*/
fun setProductId(productId: String): KleepDialogBuilder
/**
* Set tracking id, required. Should represent unique tracking id.
* Should be an empty string if the tracking id does not exist.
*
* @return interface of the SDK builder
*/
fun setTrackingId(tracking_id: String): KleepDialogBuilder
/**
* Set customer id, optonal. Should represent customer id linked to backend.
* Should be an empty string if the tracking id does not exist.
*
* @return interface of the SDK builder
*/
fun setCustomerId(customer_id: String): KleepDialogBuilder
/**
* Set retail name (mandatory), required for stock/similar_products requests.
*
* @return interface of the SDK builder
*/
fun setRetailer(retailerName: String): KleepDialogBuilder
/**
* Sets the stock availability for items.
* Providing an empty map or omitting this function disables stock checking.
*
* @return interface of the SDK builder
*/
fun setStocks(stocks: Map<String, Boolean>): KleepDialogBuilder
/**
* Display the Kleep UI inside a BottomSheet, so the user can fill a survey or take 2 pictures
* in order to compute and display the recommended size to the user
*/
fun show()
/**
* Get the latest recommended size for the last viewed user.
* As it's an async process and take several seconds,
* the result will be give by the onResult listener , provided to the SDK builder
*/
fun requestSize()
}
方法 2:show
此方法在点击 CTA 时调用,用于加载各个界面。集成 SDK 的开发者应将其嵌入底部弹窗(bottom sheet)中。
| parameter | priority | description |
|---|---|---|
| productID | 必填 | 您的产品 ID |
| retailer | 必填 | 零售商名称 |
| customerID | 可选 | CRM 标识符,用于分析 |
| trackingID | 可选 | 外部追踪服务使用的 ID |
| stocks | 可选 | 商品变体 ID 与库存状态的映射。true 表示有货,false(默认)表示缺货,传空 Map 或不传则跳过库存检查。 |
Kleep.builder(this, onResult = {
when (it) {
is KleepResult.NotSupported -> {
// Handle the NotSupported case
}
is KleepResult.NoRecommendationYet -> {
// Handle the NoRecommendationYet casem
}
is KleepResult.RecommendationFound -> {
val resultText = it.size
val variantId = it.variantId
// addToCart(variantId)
Toast.makeText(this, resultText, Toast.LENGTH_SHORT).show()
}
else -> {
}
}
})
.setPackageName(packageName) // optional
.setLang(DEFAULT_LANGUAGE) // required: "fr", "en", "es", "it", "pt", "nl"
.setProductId("1234") // required
.setRetailer("retailer_name") // required
.setTrackingId("tracking_id") // optional
.setCustomerId("unique_customer_id") // optional
.setStocks(stocks: Map<String, Boolean>) // optional
.show()
方法 3:track
此方法用于追踪自定义事件。
Kleep.track(eventName: String, eventInfo: Map<String, String>)
| eventName | 触发时机 |
|---|---|
product_viewed | 查看商品详情页时 |
product_added_to_cart | 商品加入购物车时 |
checkout_completed | 支付完成后收到订单确认时 |
product_viewed
参数(CSV)
示例
{
productId: str
}
product_added_to_cart
参数(CSV)
示例
{
productId: str,
variantId: str,
cart: [
{
productId: "123ABC456",
variantId: "123ABC456-00R",
sku: "XYZ",
size: "S",
quantity: 2,
price: {
amount: "50",
currencyCode: "EUR"
}
},
{
productId: "123ABC456",
variantId: "123ABC456-00R",
sku: "XYZ",
size: "S",
quantity: 1,
price: {
amount: "40",
currencyCode: "USD"
}
}
...
],
}
checkout_completed
参数(CSV)
示例
{
orderId: "000001",
cart: [
{
lineItemId: "000001#1",
productId: "123ABC456",
variantId: "123ABC456-00R",
sku: "XYZ",
size: "S",
quantity: 2,
price: {
amount: "50",
currencyCode: "EUR"
}
},
{
lineItemId: "000000#2",
productId: "123ABC456",
variantId: "123ABC456-00R",
sku: "XYZ",
size: "S",
quantity: 1,
price: {
amount: "40",
currencyCode: "USD"
}
}
...
],
}
