Collect profile data

Learn how to collect profile data in a mobile app.

You can use the Profile extension to store attributes about your user on the client. This information can be used later to target and personalize messages during online or offline scenarios, without having to connect to a server for optimal performance. The Profile extension manages the Client-Side Operation Profile (CSOP), provides a way to react to APIs, updates user profile attributes, and shares the user profile attributes with the rest of the system as a generated event.

The Profile data is used by other extensions to perform profile-related actions. An example is the Rules Engine extension that consumes the profile data and runs rules based on the profile data. Learn more about the Profile extension in the documentation

IMPORTANT
The Profile functionality described in this lesson is separate from the Real-Time Customer Profile functionality in Adobe Experience Platform and Platform-based applications.

Prerequisites

  • Successfully built and run app with SDKs installed and configured.

Learning objectives

In this lesson, you will:

  • Set or update user attributes.
  • Retrieve user attributes.

Set and update user attributes

It would be helpful for targeting and / or personalization in the app to quickly know if a user has made a purchase in the past or recently. Let’s set that up in the Luma app.

  1. Navigate to Luma > Luma > Utils > MobileSDK in the Xcode Project navigator and find the func updateUserAttribute(attributeName: String, attributeValue: String) function. Add the following code:

    code language-swift
    // Create a profile map, add attributes to the map and update profile using the map
    var profileMap = [String: Any]()
    profileMap[attributeName] = attributeValue
    UserProfile.updateUserAttributes(attributeDict: profileMap)
    

    This code:

    1. Sets up an empty dictionary named profileMap.

    2. Adds an element to the dictionary using attributeName (for example isPaidUser), and attributeValue (for example yes).

    3. Uses the profileMap dictionary as a value to the attributeDict parameter of the UserProfile.updateUserAttributes API call.

  2. Navigate to Luma > Luma > Views > Products > ProductView in the Xcode Project navigator and find the call to updateUserAttributes (within the code for the Purchases {width="15/"} button). Add the following code:

    code language-swift
    // Update attributes
    MobileSDK.shared.updateUserAttribute(attributeName: "isPaidUser", attributeValue: "yes")
    

Get user attributes

Once you have updated a user’s attribute, it is available to other Adobe SDKs but you can also retrieve attributes explicitly, to let your app behave the way you want.

  1. Navigate to Luma > Luma > Views > General > HomeView in the Xcode Project navigator and find the .onAppear modifier. Add the following code:

    code language-swift
    // Get attributes
    UserProfile.getUserAttributes(attributeNames: ["isPaidUser"]) { attributes, error in
        if attributes?.count ?? 0 > 0 {
            if attributes?["isPaidUser"] as? String == "yes" {
                showBadgeForUser = true
            }
            else {
                showBadgeForUser = false
            }
        }
    }
    

    This code:

    1. Calls the UserProfile.getUserAttributes API with the isPaidUser attribute name as single element in the attributeNames array.

    2. Then checks for the value of the isPaidUser attribute and when yes, places a badge on the

      {width="20/"}

      icon in the toolbar at the top right.

Additional documentation can be found here.

Validate with Assurance

  1. Review the setup instructions section to connect your simulator or device to Assurance.

  2. Run the app to log in and interact with a product.

    1. Move the Assurance icon to the left.

    2. Select Home in the tab bar.

    3. To open the Login sheet, select the {width="15/"} button.

      {width="300"}

    4. To insert a random email and customer id, select the {width="15/"} button .

    5. Select Login.

      {width="300"}

    6. Select Products in the tab bar.

    7. Select one product.

    8. Select {width="15/"}.

    9. Select {width="20/"}.

    10. Select {width="15/"}.

      {width="300"}

    11. Return back to Home screen. You should see that a badge has been added {width="15/"}.

      {width="300"}

  3. In the Assurance UI, you should see a UserProfileUpdate and getUserAttributes events with the updated profileMap value.
    validate profile

SUCCESS
You have now set up your app to update attributes of profiles in the Edge Network and (when set up) with Adobe Experience Platform.
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: Use Places

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