在 Unity SDK 中设置用户属性

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

设置用户属性

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

var builder = new Adapty.ProfileParameters.Builder()
        .SetFirstName("John")
        .SetLastName("Appleseed")
        .SetBirthday(new DateTime(1970, 1, 3))
        .SetGender(ProfileGender.Female)
        .SetEmail("example@adapty.io");

Adapty.UpdateProfile(builder.Build(), (error) => {
    if(error != nil) {
        // handle the error                        
    }
});

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

Tip

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

允许的键列表

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

email

phoneNumber

firstName

lastName

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

自定义用户属性

您可以设置自己的自定义用户属性,通常与应用使用情况相关。例如,健身应用可以记录每周锻炼次数,语言学习应用可以记录用户的掌握程度,等等。您可以在市场细分中使用这些属性来创建针对性的付费墙和优惠,也可以在分析中用来找出哪些产品数据图表对收入影响最大。

try {
    builder = builder.SetCustomStringAttribute("string_key", "string_value");
    builder = builder.SetCustomDoubleAttribute("double_key", 123.0f);
} catch (Exception e) {
    // handle the exception
}

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

try {
    builder = builder.RemoveCustomAttribute("key_to_remove");
} catch (Exception e) {
    // handle the exception
}

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

Warning

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

限制

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