跟踪事件数据
了解如何跟踪移动应用程序中的事件。
Edge Network扩展提供了一个API,用于将Experience事件发送到Platform Edge Network。 体验事件是一个对象,其中包含符合XDM ExperienceEvent架构定义的数据。 更简单地说,这些事件捕获用户在您的移动应用程序中的操作。 在Platform Edge Network收到数据后,该数据可以转发到在数据流中配置的应用程序和服务,例如Adobe Analytics和Experience Platform。 在产品文档中了解有关体验事件的更多信息。
先决条件
- 所有程序包依赖项均在您的Xcode项目中配置。
- 已在 AppDelegate 中注册扩展。
- 已将MobileCore扩展配置为使用开发
appId
。 - 导入的SDK。
- 通过上述更改成功构建并运行应用程序。
学习目标
在本课程中,您将执行以下操作
- 了解如何基于架构构建XDM数据。
- 基于标准字段组发送XDM事件。
- 基于自定义字段组发送XDM事件。
- 发送XDM购买事件。
- 使用Assurance进行验证。
构建体验事件
Adobe Experience Platform Edge扩展可以将遵循之前定义的XDM架构的事件发送到Adobe Experience Platform Edge Network。
这个过程是这样的……
-
识别您尝试跟踪的移动应用程序交互。
-
检查您的架构并确定相应的事件。
-
查看您的架构并确定应用于描述事件的任何其他字段。
-
构造和填充数据对象。
-
创建并发送事件。
-
验证。
标准字段组
对于标准字段组,此过程如下所示:
-
在您的架构中,识别您尝试收集的事件。 在此示例中,您正在跟踪商务体验事件,例如产品查看(productViews)事件。
-
要在应用程序中构建包含体验事件数据的对象,您可以使用以下代码:
code language-swift |
---|
|
在此代码中:
-
eventType
:描述发生的事件,尽可能使用已知值。 -
commerce.productViews.value
:事件的数值或布尔值。 如果它是一个布尔值(在Adobe Analytics中为“计数器”),则该值始终设置为1。 如果是数值或货币事件,该值可以大于1。
code language-kotlin |
---|
|
在此代码中:
-
eventType
:描述发生的事件,尽可能使用已知值。 -
commerce.productViews.value
:事件的数值或布尔值。 如果它是一个布尔值(在Adobe Analytics中为“计数器”),则该值始终设置为1。 如果是数值或货币事件,该值可以大于1。
-
在您的架构中,标识与商业产品查看事件关联的任何其他数据。 在此示例中,包括 productListItems,它是用于任何商业相关事件的标准字段集:
* 请注意,**productListItems**是一个数组,因此可以提供多个产品。
-
要添加此数据,请展开
xdmData
对象以包含补充数据:
code language-swift |
---|
|
code language-kotlin |
---|
|
- 您现在可以使用此数据结构创建
ExperienceEvent
:
code language-swift |
---|
|
code language-kotlin |
---|
|
- 并使用
sendEvent
API将事件和数据发送到Platform Edge Network:
code language-swift |
---|
|
code language-kotlin |
---|
|
Edge.sendEvent
API是AEP Mobile SDK等效于MobileCore.trackAction
和MobileCore.trackState
API调用。 有关详细信息,请参阅从Analytics移动扩展迁移到Adobe Experience Platform Edge Network。
现在,您即将在项目中实施此代码。
您的应用程序中有不同的商业产品相关操作,并且您要根据用户执行的以下操作发送事件:
- 视图:在用户查看特定产品时发生,
- 添加到购物车:当用户点击产品详细信息屏幕中的
- 暂存:当用户点击产品详细信息屏幕中的
- 购买:用户点按
要以可重用方式实施与商业相关的体验事件的发送,请使用专用函数:
-
在Xcode项目导航器中导航到 Luma > Luma > Utils > MobileSDK,并将以下内容添加到
func sendCommerceExperienceEvent(commerceEventType: String, product: Product)
函数。code language-swift // Set up a data dictionary, create an experience event and send the event. let xdmData: [String: Any] = [ "eventType": "commerce." + commerceEventType, "commerce": [ commerceEventType: [ "value": 1 ] ], "productListItems": [ [ "name": product.name, "priceTotal": product.price, "SKU": product.sku ] ] ] let commerceExperienceEvent = ExperienceEvent(xdm: xdmData) Edge.sendEvent(experienceEvent: commerceExperienceEvent)
此函数将商务体验事件类型和产品作为参数和
- 将XDM有效负载设置为词典,使用函数中的参数,
- 使用词典设置体验事件,
- 使用
Edge.sendEvent
API发送体验事件。
-
在Xcode项目导航器中导航到 Luma > Luma > Views > Products > ProductView,并将各种调用添加到
sendCommerceExperienceEvent
函数:-
在
.task
修饰符处,在ATTrackingManager.trackingAuthorizationStatus
结束处。 在初始化并显示产品视图时调用此.task
修饰符,以便您想要在该特定时刻发送产品视图事件。code language-swift // Send productViews commerce experience event MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "productViews", product: product)
-
对于工具栏中的每个按钮(
ATTrackingManager.trackingAuthorizationStatus == .authorized
关闭内添加相关调用:-
对于
code language-swift // Send saveForLater commerce experience event MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "saveForLaters", product: product)
-
对于
code language-swift // Send productListAdds commerce experience event MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "productListAdds", product: product)
-
对于
code language-swift // Send purchase commerce experience event MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "purchases", product: product)
-
-
-
在Android Studio导航器中导航到 Android
func sendCommerceExperienceEvent(commerceEventType: String, product: Product)
函数中。code language-kotlin // Set up a data map, create an experience event and send the event. val xdmData = mapOf( "eventType" to "commerce.$commerceEventType", "commerce" to mapOf(commerceEventType to mapOf("value" to 1)), "productListItems" to listOf( mapOf( "name" to product.name, "priceTotal" to product.price, "SKU" to product.sku ) ) ) val commerceExperienceEvent = ExperienceEvent.Builder().setXdmSchema(xdmData).build() Edge.sendEvent(commerceExperienceEvent, null)
此函数将商务体验事件类型和产品作为参数和
- 使用函数中的参数将XDM有效负载设置为映射,
- 使用映射设置体验事件,
- 使用
Edge.sendEvent
API发送体验事件。
-
在Android Studio导航器中导航到 应用程序 > kotlin+java > com.adobe.luma.tutorial.android > 视图 > ProductView.kt,并将各种调用添加到
sendCommerceExperienceEvent
函数:-
通过
LaunchedEffect(Unit)
可组合功能,您希望在查看产品的特定时刻发送产品查看事件。code language-kotlin // Send productViews commerce experience event MobileSDK.shared.sendCommerceExperienceEvent("productViews", product)
-
对于工具栏中的每个按钮(
scope.launch
的if (MobileSDK.shared.trackingEnabled == TrackingStatus.AUTHORIZED) statement
中添加相关调用:-
对于
code language-kotlin // Send saveForLater commerce experience event MobileSDK.shared.sendCommerceExperienceEvent("saveForLaters", product)
-
对于
code language-kotlin // Send productListAdds commerce experience event MobileSDK.shared.sendCommerceExperienceEvent("productListAdds", product)
-
对于
code language-kotlin // Send purchase commerce experience event MobileSDK.shared.sendCommerceExperienceEvent("purchases", product)
-
-
java.util.Map
)作为构建XDM有效负载的基础接口。自定义字段组
假设您想跟踪应用程序本身中的屏幕查看次数和交互次数。 请记住,您已为此类型事件定义了自定义字段组。
-
在您的架构中,识别您尝试收集的事件。
-
开始构建对象。
note note NOTE -
标准字段组始终以对象根开头。
-
自定义字段组始终以Experience Cloud组织
_techmarketingdemos
特有的对象开头。
-
-
对于应用程序交互事件,您可以构建如下对象:
code language-swift |
---|
|
code language-kotlin |
---|
|
- 对于屏幕跟踪事件,您可以构建如下对象:
code language-swift |
---|
|
code language-kotlin |
---|
|
- 您现在可以使用此数据结构创建
ExperienceEvent
。
code language-swift |
---|
|
code language-kotlin |
---|
|
- 将事件和数据发送到Platform Edge Network。
code language-swift |
---|
|
code language-kotlin |
---|
|
再次重申,请在项目中实施此代码。
-
为方便起见,您在 MobileSDK 中定义了两个函数。 在Xcode项目导航器中导航到 Luma > Luma > Utils > MobileSDK。
-
一个用于应用程序交互。 将此代码添加到
func sendAppInteractionEvent(actionName: String)
函数:code language-swift // Set up a data dictionary, create an experience event and send the event. let xdmData: [String: Any] = [ "eventType": "application.interaction", tenant : [ "appInformation": [ "appInteraction": [ "name": actionName, "appAction": [ "value": 1 ] ] ] ] ] let appInteractionEvent = ExperienceEvent(xdm: xdmData) Edge.sendEvent(experienceEvent: appInteractionEvent)
此函数使用操作名称作为参数,并且
- 将XDM有效负载设置为词典,使用函数中的参数,
- 使用词典设置体验事件,
- 使用
Edge.sendEvent
API发送体验事件。
-
还有一个用于屏幕跟踪。 将此代码添加到
func sendTrackScreenEvent(stateName: String)
函数:code language-swift // Set up a data dictionary, create an experience event and send the event. let xdmData: [String: Any] = [ "eventType": "application.scene", tenant : [ "appInformation": [ "appStateDetails": [ "screenType": "App", "screenName": stateName, "screenView": [ "value": 1 ] ] ] ] ] let trackScreenEvent = ExperienceEvent(xdm: xdmData) Edge.sendEvent(experienceEvent: trackScreenEvent)
此函数使用状态名称作为参数并
- 将XDM有效负载设置为词典,使用函数中的参数,
- 使用词典设置体验事件,
- 使用
Edge.sendEvent
API发送体验事件。
-
-
导航到 Luma > Luma > Views > General > 登录工作表。
-
在“登录”按钮结尾处添加以下高亮显示的代码:
code language-swift // Send app interaction event MobileSDK.shared.sendAppInteractionEvent(actionName: "login")
-
将以下高亮显示的代码添加到
onAppear
修饰符:code language-swift // Send track screen event MobileSDK.shared.sendTrackScreenEvent(stateName: "luma: content: ios: us: en: login")
-
-
为方便起见,您在 MobileSDK 中定义了两个函数。 在Android Studio导航器中导航到 Android
-
一个用于应用程序交互。 将此代码添加到
fun sendAppInteractionEvent(actionName: String)
函数:code language-kotlin // Set up a data map, create an experience event and send the event. val xdmData = mapOf( "eventType" to "application.interaction", tenant.value to mapOf( "appInformation" to mapOf( "appInteraction" to mapOf( "name" to actionName, "appAction" to mapOf("value" to 1) ) ) ) ) val appInteractionEvent = ExperienceEvent.Builder().setXdmSchema(xdmData).build() Edge.sendEvent(appInteractionEvent, null)
此函数使用操作名称作为参数,并且
- 使用函数中的参数将XDM有效负载设置为映射,
- 使用映射设置体验事件,
- 使用
Edge.sendEvent
API发送体验事件。
-
还有一个用于屏幕跟踪。 将此代码添加到
fun sendTrackScreenEvent(stateName: String)
函数:code language-kotlin // Set up a data map, create an experience event and send the event. val xdmData = mapOf( "eventType" to "application.scene", tenant.value to mapOf( "appInformation" to mapOf( "appStateDetails" to mapOf( "screenType" to "App", "screenName" to stateName, "screenView" to mapOf("value" to 1) ) ) ) ) val trackScreenEvent = ExperienceEvent.Builder().setXdmSchema(xdmData).build() Edge.sendEvent(trackScreenEvent, null)
此函数使用状态名称作为参数并
- 使用函数中的参数将XDM有效负载设置为映射,
- 使用映射设置体验事件,
- 使用
Edge.sendEvent
API发送体验事件。
-
-
导航到 Android
-
将以下高亮显示的代码添加到 Button onClick 事件:
code language-kotlin // Send app interaction event MobileSDK.shared.sendAppInteractionEvent("login")
-
将以下高亮显示的代码添加到
LaunchedEffect(Unit)
可组合函数:code language-kotlin // Send track screen event MobileSDK.shared.sendTrackScreenEvent("luma: content: android: us: en: login")
-
验证
-
查看设置说明部分,将您的模拟器或设备连接到Assurance。
- 将Assurance图标向左移动。
- 在选项卡栏中选择 Home,并验证您是否在Home屏幕中看到 ECID、电子邮件 和 CRM ID。
- 在选项卡栏中选择 Products。
- 选择产品。
- 选择
- 选择
- 选择


-
在Assurance UI中,查找来自 com.adobe.edge.konductor 供应商的 hitReceived 事件。
-
选择事件并查看 消息 对象中的XDM数据。 或者,您可以使用
后续步骤
您现在应该拥有所有工具,能够开始向应用程序添加数据收集。 您可以为用户在应用程序中与产品的交互方式添加更多智能,并为应用程序添加更多应用程序交互和屏幕跟踪调用:
- 在应用程序中实施订单、结帐、空购物篮和其他功能,并将相关的商务体验事件添加到此功能。
- 使用相应的参数重复对
sendAppInteractionEvent
的调用,以跟踪用户进行的其他应用程序交互。 - 使用相应的参数重复对
sendTrackScreenEvent
的调用,以跟踪用户在应用程序中查看的屏幕。
将事件发送到Analytics和Platform
现在您已收集事件并将它们发送到Platform Edge Network,将它们发送到数据流中配置的应用程序和服务。 在以后的课程中,您需要将此数据映射到Adobe Analytics、Adobe Experience Platform和其他Adobe Experience Cloud解决方案(如Adobe Target和Adobe Journey Optimizer)。
下一步: 处理WebViews