ÃÛ¶¹ÊÓƵ

Collect lifecycle data

Learn how to collect lifecycle data in a mobile app.

The ÃÛ¶¹ÊÓƵ Experience Platform Mobile SDK Lifecycle extension enables the collection lifecycle data from your mobile app. The ÃÛ¶¹ÊÓƵ 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 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.

  1. Navigate to Luma > Luma > SceneDelegate in the Xcode Project navigator.

  2. 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 to func sceneWillEnterForeground(_ scene: UIScene):

    code language-swift
    // When in foreground start lifecycle data collection
    MobileCore.lifecycleStart(additionalContextData: nil)
    
  3. When the app enters the background, you want to pause lifecycle data collection from your app’s sceneDidEnterBackground: delegate method. Add this code to func sceneDidEnterBackground(_ scene: UIScene):

    code language-swift
    // When in background pause lifecycle data collection
    MobileCore.lifecyclePause()
    

Validate with Assurance

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

Forward data to Platform Edge Network

The previous exercise dispatches the foreground and background events to ÃÛ¶¹ÊÓƵ Experience Platform Mobile SDK. To forward these events to Platform Edge Network:

  1. Select Rules in the Tags property.
    Create Rule

  2. Select Initial Build as the library to use.

  3. Select Create New Rule.
    Create New Rule

  4. In the Create Rule screen, enter Application Status for Name.

  5. Select Add Add below EVENTS.
    Create Rule dialog

  6. In the Event Configuration step:

    1. Select Mobile Core as the Extension.
    2. Select Foreground as the Event Type.
    3. Select Keep Changes.
      Rule Event Configuration
  7. Back in the Create Rule screen, select Add Add next to Mobile Core - Foreground.
    Next event configuration

  8. In the Event Configuration step:

    1. Select Mobile Core as the Extension.
    2. Select Background as the Event Type.
    3. Select Keep Changes.
      Rule Event Configuration
  9. Back in the Create Rule screen, select Add Add underneath ACTIONS.
    Rule Add Action

  10. In the Action Configuration step:

    1. Select ÃÛ¶¹ÊÓƵ Experience Edge Network as the Extension.
    2. Select Forward event to Edge Network as the Action Type.
    3. Select Keep Changes.
      Rule Action Configuration
  11. Select Save to Library.
    Rule - Save to Library

  12. Select Build to rebuild the library.
    Rule - Build

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.

validate lifecycle sent to Platform Edge

SUCCESS
You have now set up your app to send application state (foreground, background) events to the ÃÛ¶¹ÊÓƵ Experience Platform Edge Network and all services you have defined in your datastream.
Thank you for investing your time in learning about ÃÛ¶¹ÊÓƵ Experience Platform Mobile SDK. If you have questions, want to share general feedback, or have suggestions on future content, share them on this

Next: Track event data

recommendation-more-help
9fed61f5-c338-47ad-8005-0b89a5f4af8b