在 Unity SDK 中设置用户属性

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

设置用户属性

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

var builder = new Adapty.ProfileParameters.Builder()
        .SetFirstName("John")
        .SetLastName("Appleseed")
        .SetBirthday(new DateTime(1970, 1, 3))
        .SetGender(ProfileGender.Female)
        .SetEmail("[email protected]");

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

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

想了解 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 字段。

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

限制

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