在 React Native SDK 中设置用户属性

您可以为应用用户设置可选属性,例如电子邮件、电话号码等。然后,您可以使用这些属性来创建用户市场细分,或直接在 CRM 中查看。

设置用户属性

要设置用户属性,请调用 .updateProfile() 方法:

// Only for TypeScript validation
import type { AdaptyProfileParameters } from 'react-native-adapty';

const params: AdaptyProfileParameters = {
    email: '[email protected]',
    phoneNumber: '+18888888888',
    firstName: 'John',
    lastName: 'Appleseed',
    gender: 'other',
    birthday: new Date().toISOString(),
};

try {
    await adapty.updateProfile(params);
} catch (error) {
    // handle `AdaptyError`
}

请注意,之前通过 updateProfile 方法设置的属性不会被重置。

想了解 Adapty SDK 如何集成到移动应用中的真实示例?请查看我们的示例应用,其中展示了完整的配置过程,包括显示付费墙、完成购买以及其他基本功能。

允许的键列表

AdaptyProfileParameters.Builder 的允许键 <Key> 及其对应值 <Value> 如下所示:

email

phoneNumber

firstName

lastName

String
gender枚举类型,允许的值为:femalemaleother
birthdayDate

自定义用户属性

您可以设置自定义属性。这些属性通常与应用使用情况相关。例如,对于健身应用,可能是每周锻炼次数;对于语言学习应用,可能是用户的知识水平等。您可以在市场细分中使用它们来创建有针对性的付费墙和优惠,也可以在分析中使用它们来了解哪些产品指标对收入影响最大。

try {
  await adapty.updateProfile({
    codableCustomAttributes: {
      key_1: 'value_1',
      key_2: 2,
    },
  });
} catch (error) {
    // handle `AdaptyError`
}

要删除已有的键,请使用 .withRemoved(customAttributeForKey:) 方法:

try {
  // to remove a key, pass null as its value
  await adapty.updateProfile({
    codableCustomAttributes: {
      key_1: null,
      key_2: null,
    },
  });
} catch (error) {
    // handle `AdaptyError`
}

有时您需要查看之前已设置了哪些自定义属性。为此,请使用 AdaptyProfile 对象的 customAttributes 字段。

请注意,customAttributes 的值可能不是最新的,因为用户属性可以随时从不同设备发送,服务器上的属性可能在上次同步后已发生变化。

限制

  • 每位用户最多 30 个自定义属性
  • 键名最长 30 个字符。键名可包含字母数字字符及以下任意字符:_ - .
  • 值可以是字符串或浮点数,最多 50 个字符。