追蹤事件資料
瞭解如何追蹤行動應用程式中的事件。
Edge Network擴充功能提供API,可將體驗事件傳送至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
-
將下列醒目提示的程式碼新增至 按鈕 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圖示向左移動。
- 在索引標籤列中選取「首頁」,並確認您在「首頁」畫面中看到 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