根據 Google 的《歐盟地區使用者同意授權政策》規定,您必須向歐洲經濟區 (EEA) 和英國境內的使用者揭露特定資訊,且依據法規要求,若您要使用 Cookie 或其他本機儲存空間來放送廣告,或是根據個人資料 (例如 AdID) 來放送廣告。 本政策是配合《歐盟地區電子通訊隱私指令》和《一般資料保護規則》(GDPR) 而製定。
為了協助發布商根據這項政策履行自身義務,Google 提供 User Messaging Platform (UMP) SDK。UMP SDK 已更新為可支援最新的 IAB 標準。上述所有設定現在都能輕鬆地透過 AdMob 隱私權與訊息進行處理。
必要條件
- 完整閱讀入門指南
- 在AdMob 帳戶的「隱私權與訊息」分頁中設定訊息。詳情請參閱關於隱私權與訊息、
- 如果您已處理 GDPR 相關規定,請參閱 IAB 規定對歐盟地區同意授權訊息的影響。
使用者訊息類型
如需完整的支援訊息清單,請參閱 使用者訊息類型 。如需各類型訊息的具體操作說明,請參閱左側的導覽列。
匯入 SDK
CocoaPods (建議)
UMP SDK 包含在 Google Mobile Ads SDK 7.64.0 中,做為 Google Mobile Ads SDK Pod 的依附元件。
如要將 SDK 匯入 iOS 專案,最簡單的方法是使用 CocoaPods。開啟專案的 Podfile,然後在應用程式目標中新增這一行:
pod 'Google-Mobile-Ads-SDK'
接著,執行下列指令:
pod install --repo-update
如果您是第一次使用 CocoaPods,請參閱使用 CocoaPods 一文,進一步瞭解如何建立及使用 Podfile。
手動下載
匯入 SDK 的另一個方式是手動執行。
接著,將架構拖曳至 Xcode 專案,確保選取「Copy itemss if needed」。
接著,您就可以在任何需要的檔案中加入這個架構:
Swift
import UserMessagingPlatform
Objective-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
更新 Info.plist
找出應用程式 ID 並將其新增至Info.plist
:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>
判斷是否需要顯示訊息
每次載入應用程式時,你都應使用 requestConsentInfoUpdateWithParameters:completionHandler:
載入表單,藉此更新使用者同意聲明資訊。這可用來判斷使用者是否需要提供同意聲明,以及是否取得同意聲明。
以下範例說明如何檢查應用程式開始的狀態:
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Create a UMPRequestParameters object. let parameters = UMPRequestParameters() // Set tag for under age of consent. Here false means users are not under age. parameters.tagForUnderAgeOfConsent = false // Request an update to the consent information. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate( with: parameters, completionHandler: { error in if error != nil { // Handle the error. } else { // The consent information state was updated. // You are now ready to check if a form is // available. } }) }
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Create a UMPRequestParameters object. UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; // Set tag for under age of consent. Here NO means users are not under age. parameters.tagForUnderAgeOfConsent = NO; // Request an update to the consent information. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError *_Nullable error) { if (error) { // Handle the error. } else { // The consent information state was updated. // You are now ready to check if a form is // available. } }]; }
載入表單 (如果有的話)
顯示表單前,您必須先判斷是否有這類表單可用。 無法使用的表單可能是因使用者啟用受限制的廣告追蹤,或是您已標示為未滿規定年齡。
如要查看表單的可用性,請使用先前建立的the formStatus
property on the UMPConsentInformation
instance 。
接著,新增包裝函式方法來載入表單:
Swift
// Request an update to the consent information. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate( withParameters: parameters, completionHandler: { [self] error in // The consent information has updated. if error != nil { // Handle the error. } else { // The consent information state was updated. // You are now ready to see if a form is available. let formStatus = UMPConsentInformation.sharedInstance.formStatus if formStatus == UMPFormStatus.available { loadForm() } } }) ... func loadForm() { }
Objective-C
// Request an update to the consent information. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError* _Nullable error) { // The consent information has updated. if (error) { // Handle the error. } else { // The consent information state was updated. // You are now ready to see if a form is available. UMPFormStatus formStatus = UMPConsentInformation.sharedInstance .formStatus; if (formStatus == UMPFormStatusAvailable) { [self loadForm]; } } }]; ... - (void) loadForm { }
如要載入表單,請使用 the static loadWithCompletionHandler:
method on the UMPConsentForm
class。
Swift
func loadForm() { // Loads a consent form. Must be called on the main thread. UMPConsentForm.load( withCompletionHandler: { form, loadError in if loadError != nil { // Handle the error } else { // Present the form } }) }
Objective-C
- (void)loadForm { [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { if (loadError) { // Handle the error } else { // Present the form } }]; }
必要時顯示表單
決定表單的可用性並載入後,請使用UMPConsentForm
執行個體上的presentFromViewController:completionHandler:
方法呈現表單。
使用較舊的UMPConsentInformation
物件檢查consent status ,並更新loadForm
方法:
Swift
func loadForm() { UMPConsentForm.load(withCompletionHandler: { form, loadError in if loadError != nil { // Handle the error. } else { // Present the form. You can also hold on to the reference to present // later. if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required { form?.present( from: self, completionHandler: { dismissError in if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained { // App can start requesting ads. } // Handle dismissal by reloading form. loadForm(); }) } else { // Keep the form available for changes to user consent. } } }) }
Objective-C
- (void)loadForm { [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { if (loadError) { // Handle the error. } else { // Present the form. You can also hold on to the reference to present // later. if (UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatusRequired) { [form presentFromViewController:self completionHandler:^(NSError *_Nullable dismissError) { if (UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatusObtained) { // App can start requesting ads. } // Handle dismissal by reloading form. [self loadForm]; }]; } else { // Keep the form available for changes to user consent. } } }]; }
如果您在使用者選擇或關閉表單之後需要執行任何動作,請將該邏輯放入表單的處理常式或回呼中。
測試
強制執行地理位置
UMP SDK 可讓您使用 the debugGeography
property of type UMPDebugGeography
on UMPDebugSettings
測試應用程式的行為,就像裝置位於歐洲經濟區或英國一樣。
您必須在應用程式的偵錯設定中提供測試裝置的雜湊 ID,才能使用偵錯功能。如果呼叫requestConsentInfoUpdateWithParameters:completionHandler:
時並未設定這個值,應用程式會在執行時記錄必要的 ID 雜湊。
Swift
let parameters = UMPRequestParameters() let debugSettings = UMPDebugSettings() debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"] debugSettings.geography = UMPDebugGeography.EEA parameters.debugSettings = debugSettings UMPConsentInformation.sharedInstance.requestConsentInfoUpdate( with: parameters, completionHandler: { error in ... })
Objective-C
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ]; debugSettings.geography = UMPDebugGeographyEEA; parameters.debugSettings = debugSettings; [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError *_Nullable error){ ... }];
使用 UMPDebugGeography
時,您可以選擇將地理位置強制設為下列其中一個選項:
偵錯地理位置 | 說明 |
---|---|
UMPDebugGeographyDisabled |
偵錯地理位置已停用。 |
UMPDebugGeographyEEA |
偵錯裝置的地理位置在歐洲經濟區內。 |
UMPDebugGeographyNotEEA |
偵錯裝置的地理位置在歐洲經濟區內。 |
請注意,偵錯設定僅適用於測試裝置。由於模擬器預設為啟用測試功能,因此無需在裝置 ID 清單中加入模擬器。
重設同意聲明狀態
使用 UMP SDK 測試應用程式時,建議您重設 SDK 的狀態,以便模擬使用者的初次安裝體驗。SDK 會提供 reset
方法來完成這項作業。
Swift
UMPConsentInformation.sharedInstance.reset()
Objective-C
[UMPConsentInformation.sharedInstance reset];
如果您決定將 UMP SDK 從專案中完全移除,也應該呼叫 reset
。