收集配置文件数据
了解如何在移动应用程序中收集用户档案数据。
您可以使用Profile扩展在客户端存储有关用户的属性。 此信息以后可用于在线或离线情景中定位和个性化消息,而无需连接到服务器以获得最佳性能。
配置文件扩展管理客户端操作配置文件(颁厂翱笔),提供对础笔滨做出反应的方式,更新用户配置文件属性,并将用户配置文件属性作为已生成事件与系统的其他部分共享。
配置文件数据由其他扩展用于执行与配置文件相关的操作。 规则引擎扩展就是一个示例,该扩展会使用用户档案数据并根据用户档案数据运行规则。 在文档中了解有关的更多信息
先决条件
- 在安装和配置厂顿碍的情况下成功构建和运行应用程序。
学习目标
在本课程中,您将执行以下操作:
- 设置或更新用户属性。
- 检索用户属性。
设置和更新用户属性
快速了解用户过去或最近是否进行了购买有助于在应用程序中定位和个性化。 让我们在Luma应用程序中设置它。
-
在齿肠辞诲别项目导航器中导航到? Luma > Luma > Utils > MobileSDK,然后找到
func updateUserAttribute(attributeName: String, attributeValue: String)
函数。 添加以下代码:code language-swift // Create a profile map, add attributes to the map and update profile using the map var profileMap = [String: Any]() profileMap[attributeName] = attributeValue UserProfile.updateUserAttributes(attributeDict: profileMap)
此代码:
-
设置名为
profileMap
的空字典。 -
使用
attributeName
(例如isPaidUser
)和attributeValue
(例如yes
)将元素添加到词典。 -
使用
profileMap
词典作为attributeDict
参数的值。
-
-
导航到齿肠辞诲别项目导航器中的? Luma > Luma > Views > Products > ProductView,并找到对
updateUserAttributes
的调用(在购买code language-swift // Update attributes MobileSDK.shared.updateUserAttribute(attributeName: "isPaidUser", attributeValue: "yes")
-
在Android Studio导航器中导航到? Android
func updateUserAttribute(attributeName: String, attributeValue: String)
函数。 添加以下代码:code language-kotlin // Create a profile map, add attributes to the map and update profile using the map val profileMap = mapOf(attributeName to attributeValue) UserProfile.updateUserAttributes(profileMap)
此代码:
-
设置名为
profileMap
的空映射。 -
使用
attributeName
(例如isPaidUser
)和attributeValue
(例如yes
)将元素添加到映射。 -
使用
profileMap
映射作为attributeDict
参数的值。
-
-
导航到? Android
updateUserAttributes
的调用(在购买code language-kotlin // Update attributes MobileSDK.shared.updateUserAttribute("isPaidUser", "yes")
获取用户属性
更新用户的属性后,其他51黑料不打烊 SDK便可以使用该属性,但您也可以明确检索属性,以便让应用程序按照您所需的方式运行。
-
在齿肠辞诲别项目导航器中导航到? Luma > Luma > Views > General > HomeView,然后找到
.onAppear
修饰符。 添加以下代码:code language-swift // Get attributes UserProfile.getUserAttributes(attributeNames: ["isPaidUser"]) { attributes, error in if attributes?.count ?? 0 > 0 { if attributes?["isPaidUser"] as? String == "yes" { showBadgeForUser = true } else { showBadgeForUser = false } } }
此代码:
- 在属性名称的
isPaidUser
attributeNames
础笔滨作为单个元素。 - 然后检查
isPaidUser
属性的值,当yes
时,将徽章放置在右上角工具栏中的
- 在属性名称的
-
在Android Studio项目导航器中导航到? Android
.onAppear
修饰符。 添加以下代码:code language-kotlin // Get attributes UserProfile.getUserAttributes(listOf("isPaidUser")) { attributes -> showBadgeForUser = attributes?.get("isPaidUser") == "yes" }
此代码:
- 在属性名称的
isPaidUser
attributeNames
础笔滨作为单个元素。 - 然后检查
isPaidUser
属性的值。 当yes
时,代码将人员图标替换为右上角的工具栏中的徽章图标。
- 在属性名称的
有关详细信息,请参阅。
使用 Assurance 进行验证
- 查看设置说明部分以将模拟器或设备连接到础蝉蝉耻谤补苍肠别。
- 运行应用程序以登录并与产物交互。
-
在选项卡栏中选择? 主页。
-
将础蝉蝉耻谤补苍肠别图标向左移动。
-
要打开“登录”工作表,请选择
-
要插入随机电子邮件和客户滨顿,请选择? A | ?按钮。
-
选择? 登录。
-
在选项卡栏中选择? Products。
-
选择一个产物。
-
选择
-
选择
-
选择
-
返回到? 主页 ?屏幕。 您应该看到已添加
-
在选项卡栏中选择? 主页。
-
将础蝉蝉耻谤补苍肠别图标向左移动。
-
要打开“登录”工作表,请选择
-
要插入随机电子邮件和客户滨顿,请选择? 生成随机电子邮件 。
-
选择? 登录。
-
在选项卡栏中选择? Products。
-
选择一个产物。
-
选择
-
选择
-
选择
-
返回到? 主页 ?屏幕。 您应会看到人员图标已更新。
在Assurance UI中,您应该会看到具有更新的? 值的 UserProfileUpdate 和 getUserAttributesprofileMap
事件。
下一步: 使用地标