收集設定檔資料

瞭解如何在行動應用程式中收集設定檔資料。

您可以使用設定檔擴充功能在使用者端上儲存使用者的相關屬性。 此資訊稍後可用於線上上或離線情況下目標定位和個人化訊息,不必連線至伺服器以獲得最佳效能。 設定檔擴充功能可管理使用者端作業設定檔(CSOP)、提供對API做出反應的方式、更新使用者設定檔屬性,以及將使用者設定檔屬性作為已產生的事件與系統其他部分共用。

其他擴充功能會使用設定檔資料來執行設定檔相關動作。 規則引擎擴充功能即是一例,它會使用設定檔資料,並根據設定檔資料執行規則。 進一步瞭解 設定檔副檔名 在檔案中

IMPORTANT
本課程中所述的設定檔功能與Adobe Experience Platform和平台型應用程式中的即時客戶設定檔功能不同。

先決條件

  • 成功建立並執行應用程式,且已安裝並設定SDK。

學習目標

在本課程中,您將會:

  • 設定或更新使用者屬性。
  • 擷取使用者屬性。

設定和更新使用者屬性

快速知道使用者過去或最近是否曾經購買過產品,將有助於應用程式中的目標定位和/或個人化。 讓我們在Luma應用程式中設定它。

  1. 瀏覽至 Luma > Luma > Utils > MobileSDK 在Xcode專案導覽器中,並找到 func updateUserAttribute(attributeName: String, attributeValue: String) 函式。 新增下列程式碼:

    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)
    

    此程式碼:

    1. 設定空的字典,名為 profileMap.

    2. 使用將元素新增至字典 attributeName (例如 isPaidUser),以及 attributeValue (例如 yes)。

    3. 使用 profileMap 字典作為值 attributeDict 的引數 UserProfile.updateUserAttributes API呼叫。

  2. 瀏覽至 Luma > Luma > Views > Products > ProductView 在Xcode專案導覽器中,尋找呼叫 updateUserAttributes (在購買程式碼內)+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+按鈕)。 新增下列程式碼:

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

取得使用者屬性

更新使用者的屬性後,其他AdobeSDK即可使用該屬性,但您也可以明確擷取屬性,讓應用程式依您想要的方式運作。

  1. 瀏覽至 Luma > Luma > Views > General > HomeView 在Xcode專案導覽器中,並找到 .onAppear 修飾元。 新增下列程式碼:

    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
            }
        }
    }
    

    此程式碼:

    1. 呼叫 UserProfile.getUserAttributes 具有的API isPaidUser 屬性名稱,作為中的單一元素 attributeNames 陣列。

    2. 然後檢查的值 isPaidUser 屬性與時間 yes,在網站上放置徽章

      img-md
      w-20

      圖示加以調整。

可找到其他檔案 此處.

使用保證進行驗證

  1. 檢閱 設定指示 區段來將您的模擬器或裝置連線到Assurance。

  2. 執行應用程式以登入並與產品互動。

    1. 將「保證」圖示移至左側。

    2. 選取 首頁 標籤列中的。

    3. 若要開啟「登入」工作表,請選取+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+按鈕。

      img-md
      w-300
    4. 若要插入隨機電子郵件和客戶ID,請選取+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+按鈕。

    5. 選取 登入.

      img-md
      w-300
    6. 選取 Products 標籤列中的。

    7. 選取一個產品。

    8. 選擇+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+。

    9. 選擇+-------------+ | img-md | +=============+ | w-20 | +-------------+ | | +-------------+。

    10. 選擇+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+。

      img-md
      w-300
    11. 返回至 首頁 畫面。 您應該會看到徽章已新增+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+。

      img-md
      w-300
  3. 在Assurance UI中,您應該會看到 UserProfileUpdategetuserattributes 具有已更新內容的事件 profileMap 值。
    驗證設定檔

SUCCESS
您現在已設定應用程式,以更新Edge Network和(設定時) Adobe Experience Platform中設定檔的屬性。
感謝您花時間學習Adobe Experience Platform Mobile SDK。 如果您有疑問、想要分享一般意見或有關於未來內容的建議,請在此分享這些內容 Experience League社群討論貼文.

下一步: 使用地標

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