在 Kotlin Multiplatform SDK 中设置用户属性
您可以为应用的用户设置可选属性,例如电子邮件、电话号码等。之后可以利用这些属性创建用户市场细分,或直接在 CRM 中查看。
设置用户属性
要设置用户属性,请调用 .updateProfile() 方法:
val builder = AdaptyProfileParameters.Builder()
.withEmail("email@email.com")
.withPhoneNumber("+18888888888")
.withFirstName("John")
.withLastName("Appleseed")
.withGender(AdaptyProfile.Gender.FEMALE)
.withBirthday(AdaptyProfile.Date(1970, 1, 3))
Adapty.updateProfile(builder.build())
.onSuccess {
// profile updated successfully
}
.onError { error ->
// handle the error
}
请注意,之前通过 updateProfile 方法设置的属性不会被重置。
Tip
想查看 Adapty SDK 集成到移动应用的真实示例?请参阅我们的示例应用,其中演示了完整的配置流程,包括显示付费墙、发起购买以及其他基本功能。
允许的键列表
AdaptyProfileParameters.Builder 的允许键 <Key> 及其对应值 <Value> 如下所示:
| 键 | 值 |
|---|---|
phoneNumber firstName lastName | String |
| gender | 枚举,允许的值为:AdaptyProfile.Gender.FEMALE、AdaptyProfile.Gender.MALE、AdaptyProfile.Gender.OTHER |
| birthday | Date |
自定义用户属性
你可以设置自己的自定义用户属性,这些属性通常与应用的使用情况相关。例如,健身应用可以记录每周的锻炼次数,语言学习应用可以记录用户的知识水平,等等。你可以在市场细分中使用这些属性来创建精准的付费墙和优惠活动,也可以在分析中利用它们找出哪些产品数据图表对收入影响最大。
val builder = AdaptyProfileParameters.Builder()
builder.withCustomAttribute("key1", "value1")
要删除已有的键,请使用 .withRemovedCustomAttribute() 方法:
val builder = AdaptyProfileParameters.Builder()
builder.withRemovedCustomAttribute("key2")
有时你需要查看此前已设置了哪些自定义属性。为此,请使用 AdaptyProfile 对象的 customAttributes 字段。
Warning
请注意,customAttributes 的值可能不是最新的,因为用户属性可以随时从不同设备发送,服务器上的属性可能在上次同步后已发生变化。
限制
- 每个用户最多 30 个自定义属性
- 键名最长 30 个字符,键名可包含字母数字字符及以下任意字符:
_-. - 值可以是字符串或浮点数,最长不超过 50 个字符。