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.
appId
.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 that 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.
For the standard field groups, the process looks like:
In your schema, identify the events that you are trying to collect. In this example, you are tracking commerce experience events, for example a product view (productViews) event.
To construct object containing the experience event data in your app, you would use code like:
var xdmData: [String: Any] = [
"eventType": "commerce.productViews",
"commerce": [
"productViews": [
"value": 1
]
]
]
eventType
: Describes the event that occurred, use a known value when possible.commerce.productViews.value
: the numeric or boolean value of the event. If it’s a Boolean (or “Counter” in Adobe Analytics), the value is always set to 1. If it’s a numeric or currency event, the value can be > 1.In your schema, identify any additional data associated with the commerce product view event. In this example, include productListItems which is a standard set of fields used with any commerce-related event:
To add this data, 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
]
]
]
You now can use this data structure to create an ExperienceEvent
:
let productViewEvent = ExperienceEvent(xdm: xdmData)
And send the event and data to Platform Edge Network using the sendEvent
API:
Edge.sendEvent(experienceEvent: productViewEvent)
The Edge.sendEvent
API is the AEP Mobile SDK equivalent to the MobileCore.trackAction
and MobileCore.trackState
API calls. See Migrate from Analytics mobile extension to Adobe Experience Platform Edge Network for more information.
You are now going to actually implement this code in your Xcode project.
You have different commerce product-related actions in your app and you want to send events, based on these actions as performed by the user:
To implement the sending of commerce-related experience events in a reusable way, you use a dedicated function:
Navigate to Luma > Luma > Utils > MobileSDK in Xcode Project navigator, and add the following to the func sendCommerceExperienceEvent(commerceEventType: String, product: Product)
function.
// 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)
This function takes the commerce experience event type and product as parameters and
Edge.sendEvent
API.Navigate to Luma > Luma > Views > Products > ProductView in Xcode Project navigator and add various calls to the sendCommerceExperienceEvent
function:
At the .task
modifier, within the ATTrackingManager.trackingAuthorizationStatus
closure. This .task
modifier is called when product view is initialized and shown, so you want to send a product view event at that specific moment.
// Send productViews commerce experience event
MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "productViews", product: product)
For each of the buttons (,
and
) in the toolbar, add the relevant call within the
ATTrackingManager.trackingAuthorizationStatus == .authorized
closure:
For :
// Send saveForLater commerce experience event
MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "saveForLaters", product: product)
For :
// Send productListAdds commerce experience event
MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "productListAdds", product: product)
For :
// Send purchase commerce experience event
MobileSDK.shared.sendCommerceExperienceEvent(commerceEventType: "purchases", product: product)
In case you are developing for Android™, use Map (java.util.Map
) as the foundational interface to construct your XDM payload.
Imagine you want to track screen views and interactions in the app itself. Remember you have defined a custom field group for this type of events.
In your schema, identify the events you are trying to collect.
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.
For the app interaction event, you would construct an object like:
let xdmData: [String: Any] = [
"eventType": "application.interaction",
"_techmarketingdemos": [
"appInformation": [
"appInteraction": [
"name": "login",
"appAction": [
"value": 1
]
]
]
]
]
For the screen tracking event, you would construct an object like:
var xdmData: [String: Any] = [
"eventType": "application.scene",
"_techmarketingdemos": [
"appInformation": [
"appStateDetails": [
"screenType": "App",
"screenName": "luma: content: ios: us: en: login",
"screenView": [
"value": 1
]
]
]
]
]
You now can use this data structure to create an ExperienceEvent
.
let event = ExperienceEvent(xdm: xdmData)
Send the event and data to Platform Edge Network.
Edge.sendEvent(experienceEvent: event)
Again, lets actually implement this code in your Xcode project.
For convenience, you define two functions in MobileSDK. Navigate to Luma > Luma > Utils > MobileSDK in your Xcode Project navigator.
One for app interactions. Add this code to the func sendAppInteractionEvent(actionName: String)
function:
// 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)
This function uses the action name as a parameter and
Edge.sendEvent
API.And one for screen tracking. Add this code to the func sendTrackScreenEvent(stateName: String)
function:
// 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)
This function uses the state name as a parameter and
Edge.sendEvent
API.Navigate to Luma > Luma > Views > General > LoginSheet.
Add the following highlighted code to the Login button closure:
// Send app interaction event
MobileSDK.shared.sendAppInteractionEvent(actionName: "login")
Add the following highlighted code to onAppear
modifier:
// Send track screen event
MobileSDK.shared.sendTrackScreenEvent(stateName: "luma: content: ios: us: en: login")
Review the setup instructions section to connect your simulator or device with Assurance.
Move the Assurance icon to the left.
Select Home in the tab bar and verify you see an ECID, Email, and CRM ID in the Home screen.
Select Products in the tab bar.
Select a product.
Select .
Select .
Select .
In the Assurance UI, look for the hitReceived events from the com.adobe.edge.konductor vendor.
Select the event and review the XDM data in the messages object. Alternatively, you can use Copy Raw Event and use a text or code editor of your preference to paste and inspect the event.
You should now have all the tools to start adding data collection to your app. You can add more intelligence to how the user interacts with your products in the app and you can add more app interaction and screen tracking calls to the app:
sendAppInteractionEvent
with the appropriate parameter to track other app interactions by the user.sendTrackScreenEvent
with the appropriate parameter to track screens viewed by the user in the app.Review the finished app for more examples.
Now that you have collected the events and sent them to Platform Edge Network, they are sent to the applications and services configured in your datastream. In later lessons, you map this data to Adobe Analytics, Adobe Experience Platform, and other Adobe Experience Cloud solutions like Adobe Target and Adobe Journey Optimizer.
You have now set up your app to track commerce, app interaction, and screen tracking events to the Adobe Experience Platform Edge Network and all services you have defined in your datastream.
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, share them on this Experience League Community discussion post.
Next: Handle WebViews