Collect lifecycle data
Learn how to collect lifecycle data in a mobile app.
The Adobe Experience Platform Mobile SDK Lifecycle extension enables the collection lifecycle data from your mobile app. The Adobe Experience Platform Edge Network extension sends this lifecycle data to the Platform Edge Network where it is then forwarded to other applications and services according to your datastream configuration. Learn more about the Lifecycle extension in the product documentation.
Prerequisites
- Successfully built and run app with SDKs installed and configured. As part of this lesson, you started lifecycle monitoring already. See Install SDKs - Update AppDelegate to review.
- Registered the Assurance extension as described in the previous lesson.
Learning objectives
In this lesson, you will:
- Enable accurate lifecycle metrics by correctly starting/pausing as the app moves between foreground and background.
- Send data from the app to Platform Edge Network.
- Validate in Assurance.
Implementation changes
Now you can update your project to register the lifecycle events.
-
Navigate to Luma > Luma > SceneDelegate in the Xcode Project navigator.
-
When launched, if your app is resuming from a background state, iOS might call your
sceneWillEnterForeground:
delegate method and this is where you want to trigger a lifecycle start event. Add this code tofunc sceneWillEnterForeground(_ scene: UIScene)
:code language-swift // When in foreground start lifecycle data collection MobileCore.lifecycleStart(additionalContextData: nil)
-
When the app enters the background, you want to pause lifecycle data collection from your app’s
sceneDidEnterBackground:
delegate method. Add this code tofunc sceneDidEnterBackground(_ scene: UIScene)
:code language-swift // When in background pause lifecycle data collection MobileCore.lifecyclePause()
Validate with Assurance
- Review the setup instructions section to connect your simulator or device to Assurance.
- Send the app to the background. Check for LifecyclePause events in the Assurance UI.
- Bring app to the foreground. Check for LifecycleResume events in the Assurance UI.
Forward data to Platform Edge Network
The previous exercise dispatches the foreground and background events to Adobe Experience Platform Mobile SDK. To forward these events to Platform Edge Network:
-
Select Rules in the Tags property.
-
Select Initial Build as the library to use.
-
Select Create New Rule.
-
In the Create Rule screen, enter
Application Status
for Name. -
Select Add below EVENTS.
-
In the Event Configuration step:
- Select Mobile Core as the Extension.
- Select Foreground as the Event Type.
- Select Keep Changes.
-
Back in the Create Rule screen, select Add next to Mobile Core - Foreground.
-
In the Event Configuration step:
- Select Mobile Core as the Extension.
- Select Background as the Event Type.
- Select Keep Changes.
-
Back in the Create Rule screen, select Add underneath ACTIONS.
-
In the Action Configuration step:
- Select Adobe Experience Edge Network as the Extension.
- Select Forward event to Edge Network as the Action Type.
- Select Keep Changes.
-
Select Save to Library.
-
Select Build to rebuild the library.
Once you have successfully built the property, the events are sent to Platform Edge Network, and the events are forwarded to other applications and services according to your datastream configuration.
You should see Application Close (Background) and Application Launch (Foreground) events containing XDM data in Assurance.
Next: Track event data