瞭解如何在移動應用中實施同意。
當使用Adobe Experience Platform移動軟體開發工具包和邊緣網路擴展時,「Adobe Experience Platform同意」移動擴展啟用從移動應用收集同意首選項。 瞭解有關 同意延期中。
在本課中,您將:
如果您從頭開始學習本教程,您將記得 預設同意級別 到「掛起」。 要開始收集資料,必須獲得用戶的同意。 在本教程中,您只需在真實應用程式中發出警報,即可獲得同意,您需要參考您所在區域的同意最佳實踐。
您只想詢問用戶一次。 一種簡單的管理方法是 UserDefaults
。
導航到 Home.swift
。
將下列程式碼新增至 viewDidLoad()
.
let defaults = UserDefaults.standard
let consentKey = "askForConsentYet"
let hidePopUp = defaults.bool(forKey: consentKey)
如果用戶以前未看到警報,則顯示警報並根據其響應更新同意。 將下列程式碼新增至 viewDidLoad()
.
if(hidePopUp == false){
//Consent Alert
let alert = UIAlertController(title: "Allow Data Collection?", message: "Selecting Yes will begin data collection", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { action in
//Update Consent -> "yes"
let collectConsent = ["collect": ["val": "y"]]
let currentConsents = ["consents": collectConsent]
Consent.update(with: currentConsents)
defaults.set(true, forKey: consentKey)
}))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: { action in
//Update Consent -> "no"
let collectConsent = ["collect": ["val": "n"]]
let currentConsents = ["consents": collectConsent]
Consent.update(with: currentConsents)
defaults.set(true, forKey: consentKey)
}))
self.present(alert, animated: true)
}
「同意」移動擴展將根據當前同意值自動取消/暫停/允許跟蹤。 您也可以自己訪問當前的同意狀態:
Home.swift
。viewDidLoad()
.Consent.getConsents{ consents, error in
guard error == nil, let consents = consents else { return }
guard let jsonData = try? JSONSerialization.data(withJSONObject: consents, options: .prettyPrinted) else { return }
guard let jsonStr = String(data: jsonData, encoding: .utf8) else { return }
print("Consent getConsents: ",jsonStr)
}
在上例中,您只需將同意狀態打印到控制台。 在現實場景中,您可以使用它修改向用戶顯示的菜單或選項。
下一個: 收集生命週期資料
感謝您花時間學習Adobe Experience Platform移動軟體開發工具包。 如果您有問題、想要共用一般反饋或對未來內容有建議,請就此共用 Experience League社區討論帖子