收集設定檔資料
瞭解如何在行動應用程式中收集設定檔資料。
您可以使用設定檔擴充功能在使用者端上儲存使用者的相關屬性。 此資訊稍後可用於線上上或離線情況下目標定位和個人化訊息,不必連線至伺服器以獲得最佳效能。 設定檔擴充功能可管理使用者端作業設定檔(CSOP)、提供對API做出反應的方式、更新使用者設定檔屬性,以及將使用者設定檔屬性作為已產生的事件與系統其他部分共用。
其他擴充功能會使用設定檔資料來執行設定檔相關動作。 規則引擎擴充功能即是一例,它會使用設定檔資料,並根據設定檔資料執行規則。 進一步瞭解 設定檔副檔名 在檔案中
先決條件
- 成功建立並執行應用程式,且已安裝並設定SDK。
學習目標
在本課程中,您將會:
- 設定或更新使用者屬性。
- 擷取使用者屬性。
設定和更新使用者屬性
快速知道使用者過去或最近是否曾經購買過產品,將有助於應用程式中的目標定位和/或個人化。 讓我們在Luma應用程式中設定它。
-
瀏覽至 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)
此程式碼:
-
設定空的字典,名為
profileMap
. -
使用將元素新增至字典
attributeName
(例如isPaidUser
),以及attributeValue
(例如yes
)。 -
使用
profileMap
字典作為值attributeDict
的引數UserProfile.updateUserAttributes
API呼叫。
-
-
瀏覽至 Luma > Luma > Views > Products > ProductView 在Xcode專案導覽器中,尋找呼叫
updateUserAttributes
(在購買程式碼內)+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+按鈕)。 新增下列程式碼:code language-swift // Update attributes MobileSDK.shared.updateUserAttribute(attributeName: "isPaidUser", attributeValue: "yes")
取得使用者屬性
更新使用者的屬性後,其他AdobeSDK即可使用該屬性,但您也可以明確擷取屬性,讓應用程式依您想要的方式運作。
-
瀏覽至 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 } } }
此程式碼:
-
呼叫
UserProfile.getUserAttributes
具有的APIisPaidUser
屬性名稱,作為中的單一元素attributeNames
陣列。 -
然後檢查的值
isPaidUser
屬性與時間yes
,在網站上放置徽章img-md w-20 圖示加以調整。
-
可找到其他檔案 此處.
使用保證進行驗證
-
檢閱 設定指示 區段來將您的模擬器或裝置連線到Assurance。
-
執行應用程式以登入並與產品互動。
-
將「保證」圖示移至左側。
-
選取 首頁 標籤列中的。
-
若要開啟「登入」工作表,請選取+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+按鈕。
img-md w-300 -
若要插入隨機電子郵件和客戶ID,請選取+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+按鈕。
-
選取 登入.
img-md w-300 -
選取 Products 標籤列中的。
-
選取一個產品。
-
選擇+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+。
-
選擇+-------------+ | img-md | +=============+ | w-20 | +-------------+ | | +-------------+。
-
選擇+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+。
img-md w-300 -
返回至 首頁 畫面。 您應該會看到徽章已新增+-------------+ | img-md | +=============+ | w-15 | +-------------+ | | +-------------+。
img-md w-300
-
-
在Assurance UI中,您應該會看到 UserProfileUpdate 和 getuserattributes 具有已更新內容的事件
profileMap
值。
下一步: 使用地標