在 Capacitor SDK 中设置用户属性
您可以为应用用户设置可选属性,例如电子邮件、电话号码等。之后可以利用这些属性创建用户市场细分,或直接在 CRM 中查看。
设置用户属性
调用 .updateProfile() 方法可设置用户属性:
const params = {
email: 'email@email.com',
phoneNumber: '+18888888888',
firstName: 'John',
lastName: 'Appleseed',
gender: 'other',
birthday: new Date().toISOString(),
};
try {
await adapty.updateProfile(params);
console.log('Profile updated successfully');
} catch (error) {
console.error('Failed to update profile:', error);
}
请注意,您之前通过 updateProfile 方法设置的属性不会被重置。
Tip
想查看 Adapty SDK 集成到移动应用的真实示例?请参阅我们的示例应用,其中演示了完整的配置流程,包括显示付费墙、发起购买以及其他基本功能。
允许的键列表
AdaptyProfileParameters 允许的键及其值如下所示:
| 键 | 值 |
|---|---|
| 字符串 | |
| phoneNumber | 字符串 |
| firstName | 字符串 |
| lastName | 字符串 |
| gender | 枚举,允许的值为:'female'、'male'、'other' |
| birthday | ISO 格式的日期字符串 |
自定义用户属性
您可以设置自定义用户属性,这些属性通常与您的应用使用情况相关。例如,对于健身应用,可以是每周锻炼次数;对于语言学习应用,可以是用户的知识水平,等等。您可以在市场细分中使用这些属性来创建精准的付费墙和优惠活动,也可以在分析中用来了解哪些产品数据图表对收益影响最大。
try {
await adapty.updateProfile({
codableCustomAttributes: {
key_1: 'value_1',
key_2: 2,
},
});
console.log('Custom attributes updated successfully');
} catch (error) {
console.error('Failed to update custom attributes:', error);
}
要删除已有的键,请将其值设为 null:
try {
// to remove keys, pass null as their values
await adapty.updateProfile({
codableCustomAttributes: {
key_1: null,
key_2: null,
},
});
console.log('Custom attributes removed successfully');
} catch (error) {
console.error('Failed to remove custom attributes:', error);
}
有时你需要先了解已设置了哪些自定义属性。为此,请使用 AdaptyProfile 对象的 customAttributes 字段。
Warning
请注意,customAttributes 的值可能已过期,因为用户属性可以随时从不同设备发送,服务器上的属性可能在上次同步后已发生变化。
限制
- 每位用户最多 30 个自定义属性
- 键名最长 30 个字符,键名可包含字母数字字符及以下任意字符:
_、-、. - 值可以是字符串或浮点数,最多 50 个字符。