Learn how to track events in a mobile app.
The Edge Network extension provides an API to send Experience Events to Platform Edge Network. An Experience Event is an object that contains data conforming to the XDM ExperienceEvent schema definition. More simply, they capture what people do in your mobile app. Once data is received by Platform Edge Network, it can be forwarded to applications and services configured in your datastream, such as Adobe Analytics and Experience Platform. Learn more about the Experience Events in the product documentation.
In this lesson, you will:
The Adobe Experience Platform Edge extension can send events that follow a previously defined XDM schema to Adobe Experience Platform Edge Network.
The process goes like this…
Identify the mobile app interaction you are trying to track.
Review your schema and identify the appropriate event.
Review your schema and identify any additional fields that should be used to describe the event.
Construct & populate the data object.
Create & send event.
Validate.
Let’s look at a couple of examples.
Review the following example without trying to implement it in the sample app:
In your schema, identify the event you are trying to collect, in this example we are tracking a product view.
Begin constructing your object:
var xdmData: [String: Any] = [
"eventType": "commerce.productViews",
"commerce": [
"productViews": [
"value": 1
]
]
]
In your schema, identify any additional data associated with the event. In this example, include productListItems
which is a standard set of fields used with commerce-related events:
productListItems
is an array so multiple products could be provided.Expand your xdmData object to include supplementary data:
var xdmData: [String: Any] = [
"eventType": "commerce.productViews",
"commerce": [
"productViews": [
"value": 1
]
],
"productListItems": [
[
"name": productName,
"SKU": sku,
"priceTotal": priceString,
"quantity": 1
]
]
]
Use the data structure to create an ExperienceEvent
:
let productViewEvent = ExperienceEvent(xdm: xdmData)
Send the event and data to Platform Edge Network:
Edge.sendEvent(experienceEvent: productViewEvent)
Review the following example without trying to implement it in the sample app:
In your schema, identify the event you are trying to collect. In this example, track an “App Interaction” which consists of an App Action event & name.
Begin constructing your object.
Standard field groups always begin in the object root.
Custom fields groups always begin under an object unique to your Experience Cloud Org, “_techmarketingdemos” in this example.
var xdmData: [String: Any] = [
"_techmarketingdemos": [
"appInformation": [
"appInteraction": [
"name": actionName,
"appAction": [
"value": 1
]
]
]
]
]
Or alternatively…
var xdmData: [String: Any] = [:]
xdmData["_techmarketingdemos"] = [
"appInformation": [
"appInteraction": [
"name": actionName,
"appAction": [
"value": 1
]
]
]
]
Use the data structure to create an ExperienceEvent
.
let appInteractionEvent = ExperienceEvent(xdm: xdmData)
Send the event and data to Platform Edge Network.
Edge.sendEvent(experienceEvent: appInteractionEvent)
The above examples have hopefully explained the thought process when constructing an XDM data object. Next we will add screen view tracking in the Luma app.
Navigate to Home.swift
.
Add the following code to viewDidAppear(...)
.
let stateName = "luma: content: ios: us: en: home"
var xdmData: [String: Any] = [:]
//Page View
xdmData["_techmarketingdemos"] = [
"appInformation": [
"appStateDetails": [
"screenType": "App",
"screenName": stateName,
"screenView": [
"value": 1
]
]
]
]
let experienceEvent = ExperienceEvent(xdm: xdmData)
Edge.sendEvent(experienceEvent: experienceEvent)
Repeat for each screen in the app, updating stateName
as you go.
hitReceived
event from the com.adobe.edge.konductor
vendor.messages
object.In this example, assume that the user successfully made the following purchase:
Here are the related schema fields to use:
Custom field groups are always placed under your Experience Cloud Org identifier.
“_techmarketingdemos” is replaced with your Org’s unique value.
Here is how you would construct and send the XDM object in the app.
let stateName = "luma: content: ios: us: en: orderconfirmation"
let currencyCode = "USD"
let orderTotal = "79.99"
let paymentType = "Visa Credit Card"
let orderId = "298234720"
let paymentTransactionId = "847361"
var xdmData: [String: Any] = [
"eventType": "commerce.purchases",
"commerce": [
"purchases": [
"value": 1
],
"order": [
"currencyCode": currencyCode,
"priceTotal": orderTotal,
"purchaseID": orderId,
"purchaseOrderNumber": orderId,
"payments": [ //Assuming only 1 payment type is used
[
"currencyCode": currencyCode,
"paymentAmount": orderTotal,
"paymentType": paymentType,
"transactionID": paymentTransactionId
]
]
]
],
"productListItems": [
[
"name": "Yoga Mat",
"SKU": "5829",
"priceTotal": "49.99",
"quantity": 1
],
[
"name": "Water Bottle",
"SKU": "9841",
"priceTotal": "30.00",
"quantity": 3
]
]
]
//Custom field group
xdmData["_techmarketingdemos"] = [
"appInformation": [
"appStateDetails": [
"screenType": "App",
"screenName": stateName,
"screenView": [
"value": 1
]
]
]
]
let experienceEvent = ExperienceEvent(xdm: xdmData)
Edge.sendEvent(experienceEvent: experienceEvent)
For clarity, all the values are hardcoded. In a real-world situation, the values would be populated dynamically.
You should have all the tools to start adding data collection to the Luma sample app. Below are a list of hypothetical tracking requirements that you can follow.
Review the fully implemented app for more examples.
Review the setup instructions section and connect your simulator or device to Assurance.
Perform the action and look for the hitReceived
event from the com.adobe.edge.konductor
vendor.
Select the event and review the XDM data in the messages
object.
Now that you have collected the events and sent them to Platform Edge Network, they will be sent to the applications and services configured in your datastream. In later lessons you will map this data to Adobe Analytics and Adobe Experience Platform.
Next: WebViews
Thank you for investing your time in learning about Adobe Experience Platform Mobile SDK. If you have questions, want to share general feedback, or have suggestions on future content, please share them on this Experience League Community discussion post