跟踪事件数据

了解如何跟踪移动应用程序中的事件。

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。

这个过程是这样的……

  1. 识别您尝试跟踪的移动应用程序交互。

  2. 检查您的架构并确定相应的事件。

  3. 查看您的架构并确定应用于描述事件的任何其他字段。

  4. 构造和填充数据对象。

  5. 创建并发送事件。

  6. 验证。

标准字段组

对于标准字段组,此过程如下所示:

  • 在您的架构中,识别您尝试收集的事件。 在此示例中,您正在跟踪商务体验事件,例如产品查看(productViews)事件。

    产品视图架构 {modal="regular"}

  • 要在应用程序中构建包含体验事件数据的对象,您可以使用以下代码:

iOS
code language-swift
var xdmData: [String: Any] = [
    "eventType": "commerce.productViews",
    "commerce": [
        "productViews": [
        "value": 1
        ]
    ]
]

在此代码中:

  • eventType:描述发生的事件,尽可能使用已知值

  • commerce.productViews.value:事件的数值或布尔值。 如果它是一个布尔值(在Adobe Analytics中为“计数器”),则该值始终设置为1。 如果是数值或货币事件,该值可以大于1。

Android
code language-kotlin
val xdmData = mapOf(
    "eventType" to "commerce.productViews",
    "commerce" to mapOf(
        "productViews" to mapOf(
        "value": 1
        )
    )
)

在此代码中:

  • eventType:描述发生的事件,尽可能使用已知值

  • commerce.productViews.value:事件的数值或布尔值。 如果它是一个布尔值(在Adobe Analytics中为“计数器”),则该值始终设置为1。 如果是数值或货币事件,该值可以大于1。

  • 在您的架构中,标识与商业产品查看事件关联的任何其他数据。 在此示例中,包括​ productListItems,它是用于任何商业相关事件的标准字段集:

    产品列表项架构 {modal="regular"}

    * 请注意,**productListItems**​是一个数组,因此可以提供多个产品。

  • 要添加此数据,请展开xdmData对象以包含补充数据:

iOS
code language-swift
var xdmData: [String: Any] = [
    "eventType": "commerce.productViews",
    "commerce": [
        "productViews": [
            "value": 1
        ]
    ],
    "productListItems": [
        [
            "name":  productName,
            "SKU": sku,
            "priceTotal": priceString,
            "quantity": 1
        ]
    ]
]
Android
code language-kotlin
val xdmData = mapOf(
    "eventType" to "commerce.productViews",
    "commerce" to mapOf(
        "productViews" to mapOf(
        "value": 1
        )
    ),
    "productListItems" to mapOf(
        "name": productName,
        "SKU": sku,
        "priceTotal", priceString,
        "quantity", 1
    )
)
  • 您现在可以使用此数据结构创建ExperienceEvent
iOS
code language-swift
let productViewEvent = ExperienceEvent(xdm: xdmData)
Android
code language-kotlin
val productViewEvent = ExperienceEvent.Builder().setXdmSchema(xdmData).build()
  • 并使用sendEvent API将事件和数据发送到Platform Edge Network:
iOS
code language-swift
Edge.sendEvent(experienceEvent: productViewEvent)
Android
code language-kotlin
Edge.sendEvent(productViewEvent, null)

Edge.sendEvent API是AEP Mobile SDK等效于MobileCore.trackActionMobileCore.trackState API调用。 有关详细信息,请参阅从Analytics移动扩展迁移到Adobe Experience Platform Edge Network

现在,您即将在项目中实施此代码。
您的应用程序中有不同的商业产品相关操作,并且您要根据用户执行的以下操作发送事件:

  • 视图:在用户查看特定产品时发生,
  • 添加到购物车:当用户点击产品详细信息屏幕中的 ShoppingCart 时,
  • 暂存:当用户点击产品详细信息屏幕中的 心 / ThumbUp 时,
  • 购买:用户点按 信用卡 产品详细信息屏幕时。

要以可重用方式实施与商业相关的体验事件的发送,请使用专用函数:

iOS
  1. 在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发送体验事件。
  2. 在Xcode项目导航器中导航到​ Luma > Luma > Views > Products > ProductView,并将各种调用添加到sendCommerceExperienceEvent函数:

    1. .task修饰符处,在ATTrackingManager.trackingAuthorizationStatus结束处。 在初始化并显示产品视图时调用此.task修饰符,以便您想要在该特定时刻发送产品视图事件。

      code language-swift
      // Send productViews commerce experience event
      MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "productViews", product: product)
      
    2. 对于工具栏中的每个按钮( Heart ShoppingCart CreditCard ),在ATTrackingManager.trackingAuthorizationStatus == .authorized关闭内添加相关调用:

      1. 对于 心

        code language-swift
        // Send saveForLater commerce experience event
        MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "saveForLaters", product: product)
        
      2. 对于 ShoppingCart

        code language-swift
        // Send productListAdds commerce experience event
        MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "productListAdds", product: product)
        
      3. 对于 信用卡

        code language-swift
        // Send purchase commerce experience event
        MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "purchases", product: product)
        
Android
  1. 在Android Studio导航器中导航到​ Android ChevronDown > 应用程序 > kotlin+java > com.adobe.luma.tutorial.android > 模型 > MobileSDK,并将以下内容添加到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发送体验事件。
  2. 在Android Studio导航器中导航到​ 应用程序 > kotlin+java > com.adobe.luma.tutorial.android > 视图 > ProductView.kt,并将各种调用添加到sendCommerceExperienceEvent函数:

    1. 通过LaunchedEffect(Unit)可组合功能,您希望在查看产品的特定时刻发送产品查看事件。

      code language-kotlin
      // Send productViews commerce experience event
      MobileSDK.shared.sendCommerceExperienceEvent("productViews", product)
      
    2. 对于工具栏中的每个按钮( ThumbUp ShoppingCart CreditCard ),在scope.launchif (MobileSDK.shared.trackingEnabled == TrackingStatus.AUTHORIZED) statement中添加相关调用:

      1. 对于 ThumbUp

        code language-kotlin
        // Send saveForLater commerce experience event
        MobileSDK.shared.sendCommerceExperienceEvent("saveForLaters", product)
        
      2. 对于 ShoppingCart

        code language-kotlin
        // Send productListAdds commerce experience event
        MobileSDK.shared.sendCommerceExperienceEvent("productListAdds", product)
        
      3. 对于 信用卡

        code language-kotlin
        // Send purchase commerce experience event
        MobileSDK.shared.sendCommerceExperienceEvent("purchases", product)
        
TIP
如果您正在针对Android™进行开发,请使用映射(java.util.Map)作为构建XDM有效负载的基础接口。

自定义字段组

假设您想跟踪应用程序本身中的屏幕查看次数和交互次数。 请记住,您已为此类型事件定义了自定义字段组。

  • 在您的架构中,识别您尝试收集的事件。
    应用交互架构 {modal="regular"}

  • 开始构建对象。

    note note
    NOTE
    • 标准字段组始终以对象根开头。

    • 自定义字段组始终以Experience Cloud组织_techmarketingdemos特有的对象开头。

  • 对于应用程序交互事件,您可以构建如下对象:

iOS
code language-swift
let xdmData: [String: Any] = [
    "eventType": "application.interaction",
    "_techmarketingdemos": [
    "appInformation": [
        "appInteraction": [
            "name": "login",
            "appAction": [
                "value": 1
                ]
            ]
        ]
    ]
]
Android
code language-kotlin
val xdmData = mapOf(
    "eventType" to "application.interaction",
    "_techmarketingdemos" to mapOf(
        "appInformation" to mapOf(
            "appInteraction" to mapOf(
                "name" to "login",
                "appAction" to mapOf("value" to 1)
            )
        )
    )
)
  • 对于屏幕跟踪事件,您可以构建如下对象:
iOS
code language-swift
var xdmData: [String: Any] = [
    "eventType": "application.scene",
    "_techmarketingdemos": [
        "appInformation": [
            "appStateDetails": [
                "screenType": "App",
                "screenName": "luma: content: ios: us: en: login",
                "screenView": [
                    "value": 1
                ]
            ]
        ]
    ]
]
Android
code language-kotlin
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)
            )
        )
    )
)
  • 您现在可以使用此数据结构创建ExperienceEvent
iOS
code language-swift
let event = ExperienceEvent(xdm: xdmData)
Android
code language-kotlin
val event = ExperienceEvent(xdmData)
  • 将事件和数据发送到Platform Edge Network。
iOS
code language-swift
Edge.sendEvent(experienceEvent: event)
Android
code language-kotlin
Edge.sendEvent(event, null)

再次重申,请在项目中实施此代码。

iOS
  1. 为方便起见,您在​ 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发送体验事件。
  2. 导航到​ Luma > Luma > Views > General > 登录工作表

    1. 在“登录”按钮结尾处添加以下高亮显示的代码:

      code language-swift
      // Send app interaction event
      MobileSDK.shared.sendAppInteractionEvent(actionName: "login")
      
    2. 将以下高亮显示的代码添加到onAppear修饰符:

      code language-swift
      // Send track screen event
      MobileSDK.shared.sendTrackScreenEvent(stateName: "luma: content: ios: us: en: login")
      
Android
  1. 为方便起见,您在​ MobileSDK ​中定义了两个函数。 在Android Studio导航器中导航到​ Android ChevronDown app > kotlin+java > com.adobe.luma.tutorial.android > 模型 > MobileSDK

    • 一个用于应用程序交互。 将此代码添加到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发送体验事件。
  2. 导航到​ Android ChevronDown app>kotlin+java>com.adobe.luma.tutorial.android>​视图​>​ LoginSheet.kt ​

    1. 将以下高亮显示的代码添加到​ Button onClick ​事件:

      code language-kotlin
      // Send app interaction event
      MobileSDK.shared.sendAppInteractionEvent("login")
      
    2. 将以下高亮显示的代码添加到LaunchedEffect(Unit)可组合函数:

      code language-kotlin
      // Send track screen event
      MobileSDK.shared.sendTrackScreenEvent("luma: content: android: us: en: login")
      

验证

  1. 查看设置说明部分,将您的模拟器或设备连接到Assurance。

    1. 将Assurance图标向左移动。
    2. 在选项卡栏中选择​ Home,并验证您是否在Home屏幕中看到​ ECID电子邮件 ​和​ CRM ID
    3. 在选项卡栏中选择​ Products
    4. 选择产品。
    5. 选择 心 (iOS)或 ThumbUp (Android)。
    6. 选择 购物车添加
    7. 选择 信用卡
iOS
{width="300"}
Android
{width="278"}
  1. 在Assurance UI中,查找来自​ com.adobe.edge.konductor ​供应商的​ hitReceived ​事件。

  2. 选择事件并查看​ 消息 ​对象中的XDM数据。 或者,您可以使用 复制 复制原始事件 ​并使用首选项的文本或代码编辑器粘贴和检查该事件。

    数据收集验证 {modal="regular"}

后续步骤

您现在应该拥有所有工具,能够开始向应用程序添加数据收集。 您可以为用户在应用程序中与产品的交互方式添加更多智能,并为应用程序添加更多应用程序交互和屏幕跟踪调用:

  • 在应用程序中实施订单、结帐、空购物篮和其他功能,并将相关的商务体验事件添加到此功能。
  • 使用相应的参数重复对sendAppInteractionEvent的调用,以跟踪用户进行的其他应用程序交互。
  • 使用相应的参数重复对sendTrackScreenEvent的调用,以跟踪用户在应用程序中查看的屏幕。
TIP
有关更多示例,请查看完成的应用程序

将事件发送到Analytics和Platform

现在您已收集事件并将它们发送到Platform Edge Network,将它们发送到数据流中配置的应用程序和服务。 在以后的课程中,您需要将此数据映射到Adobe AnalyticsAdobe Experience Platform和其他Adobe Experience Cloud解决方案(如Adobe Target和Adobe Journey Optimizer)。

SUCCESS
现在,您已设置应用程序以在Adobe Experience Platform Edge Network中跟踪商务、应用程序交互和屏幕跟踪事件。 以及您在数据流中定义的所有服务。
感谢您投入时间学习Adobe Experience Platform Mobile SDK。 如果您有任何疑问、希望分享一般反馈或有关于未来内容的建议,请在此Experience League社区讨论帖子上分享这些内容。

下一步: 处理WebViews

recommendation-more-help
9fed61f5-c338-47ad-8005-0b89a5f4af8b