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.

  • Imported the Assurance SDK.

    import AEPAssurance
    
  • Registered the Assurance extension as described in the previous lesson.

Learning objectives

In this lesson, you will:

  • Add lifecycle field group to the schema.
  • 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.

Add lifecycle field group to schema

The Consumer Experience Event field group you added in the previous lesson already contains the lifecycle fields, so you can skip this step. If you don’t use Consumer Experience Event field group in your own app, you can add the lifecycle fields by doing the following:

  1. Navigate to the schema interface as described in the previous lesson.
  2. Open the “Luma App” schema and select Add.
    select add
  3. In the search bar, enter “lifecycle”.
  4. Select the checkbox next to AEP Mobile Lifecycle Details.
  5. Select Add field groups.
    add field group
  6. Select Save.
    save

Implementation changes

Now you can update AppDelegate.swift to register the lifecycle events:

  1. When launched, if your app is resuming from a background state, iOS might call your applicationWillEnterForeground: delegate method. Add lifecycleStart:

    MobileCore.lifecycleStart(additionalContextData: nil)
    
  2. When the app enters the background, pause Lifecycle data collection from your app’s applicationDidEnterBackground: delegate method.

    MobileCore.lifecyclePause()
    
NOTE

For iOS 13 and later, please review the documentation for slightly different code.

Validate with Assurance

  1. Review the setup instructions section and connect your simulator or device to Assurance.
  2. Launch the app.
  3. Send the app to the background. Check for LifecyclePause.
  4. Bring app to the foreground. Check for LifecycleResume.
    validate lifecycle

Forward data to Platform Edge Network

The previous exercise dispatches the foreground and background events to Mobile SDK. To send these events to Platform Edge Network, follow the steps listed here. Once the events are sent to Platform Edge Network, they will be forwarded to other applications and services according to your datastream configuration.

Once you have added the rule to send the lifecyle events to Platform Edge Network, you should see Application Close (Background) and Application Launch (Foreground) events containing XDM data in Assurance.

validate lifecycle sent to Platform Edge

Next: Track events

NOTE

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

On this page