Berdasarkan Kebijakan Izin Pengguna Uni Eropa Google, Anda harus membuat pengungkapan tertentu untuk pengguna di Wilayah Ekonomi Eropa (EEA) bersama dengan Inggris Raya dan mendapatkan izin mereka untuk menggunakan cookie atau penyimpanan lokal lainnya, jika diwajibkan secara hukum, dan untuk menggunakan data pribadi (seperti ID iklan) untuk menayangkan iklan. Kebijakan ini mencerminkan persyaratan dalam ePrivacy Directive dan General Data Protection Regulation (GDPR) Uni Eropa.
Untuk mendukung penayang dalam memenuhi kewajibannya berdasarkan kebijakan ini, Google menawarkan User Messaging Platform (UMP) SDK. UMP SDK telah diperbarui untuk mendukung standar IAB terbaru. Semua konfigurasi ini kini dapat ditangani dengan mudah di Ad Manager privasi & pesan.
Prasyarat
- Selesaikan Panduan memulai
- Jika Anda saat ini memenuhi persyaratan terkait GDPR, baca Pengaruh persyaratan IAB terhadap pesan izin Uni Eropa
Membuat jenis pesan
Buat pesan pengguna dengan salah satu dari jenis pesan pengguna yang tersedia di tab Privasi & pesan di akun Ad Manager Anda. UMP SDK akan mencoba menampilkan pesan pengguna yang dibuat dari Ad Manager ID Aplikasi yang ditetapkan dalam project Anda. Jika tidak ada pesan yang dikonfigurasi untuk aplikasi Anda, SDK akan menampilkan error.
Untuk mengetahui detail selengkapnya, lihat Tentang privasi dan pesan.
Mengimpor SDK
CocoaPods (lebih disarankan)
UMP SDK disertakan sebagai dependensi pod Google Mobile Ads SDK, yang dimulai dari Google Mobile Ads SDK 7.64.0.
Cara termudah untuk mengimpor SDK ke project iOS adalah dengan menggunakan CocoaPods. Buka Podfile project Anda dan tambahkan baris ini ke target aplikasi Anda:
pod 'Google-Mobile-Ads-SDK'
Lalu, jalankan perintah berikut:
pod install --repo-update
Jika Anda baru mengenal CocoaPods, lihat Menggunakan CocoaPods untuk mengetahui detail cara membuat dan menggunakan Podfile.
Download manual
Cara lain untuk mengimpor SDK adalah melakukannya secara manual.
Kemudian, tarik framework ke project Xcode dengan memastikan Anda memilih Copy items if needed.
Selanjutnya, Anda dapat menyertakan framework tersebut ke dalam file apa pun yang diperlukan menggunakan:
Swift
import UserMessagingPlatform
Objective-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
Meminta informasi izin
Anda harus meminta pembaruan informasi izin pengguna setiap kali aplikasi diluncurkan, menggunakan requestConsentInfoUpdateWithParameters:completionHandler:
. Langkah ini menentukan apakah pengguna Anda perlu memberikan izin jika belum melakukannya, atau apakah masa berlaku izinnya telah berakhir.
Berikut adalah contoh cara memeriksa status dari UIViewController
dalam
metode viewDidLoad()
.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Create a UMPRequestParameters object.
let parameters = UMPRequestParameters()
// Set tag for under age of consent. false means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
[weak self] requestConsentError in
guard let self else { return }
if let consentError = requestConsentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
// TODO: Load and present the consent form.
}
}
Objective-C
- (void)viewDidLoad {
[super viewDidLoad];
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. NO means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = NO;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable requestConsentError) {
if (requestConsentError) {
// Consent gathering failed.
NSLog(@"Error: %@", requestConsentError.localizedDescription);
return;
}
// TODO: Load and present the consent form.
}];
}
Memuat dan menampilkan formulir izin jika diperlukan
Setelah Anda menerima status izin terbaru, panggil
loadAndPresentIfRequiredFromViewController:completionHandler:
di
classUMPConsentForm
untuk memuat formulir izin. Jika
status izin diperlukan, SDK akan memuat formulir dan langsung menampilkannya
dari view controlleryang disediakan. completion handler
dipanggil setelah formulir ditutup. Jika izin tidak diperlukan, completion handler
akan segera dipanggil.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Create a UMPRequestParameters object.
let parameters = UMPRequestParameters()
// Set tag for under age of consent. false means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
[weak self] requestConsentError in
guard let self else { return }
if let consentError = requestConsentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
UMPConsentForm.loadAndPresentIfRequired(from: self) {
[weak self] loadAndPresentError in
guard let self else { return }
if let consentError = loadAndPresentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
// Consent has been gathered.
}
}
}
Objective-C
- (void)viewDidLoad {
[super viewDidLoad];
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. NO means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = NO;
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable requestConsentError) {
if (requestConsentError) {
// Consent gathering failed.
NSLog(@"Error: %@", requestConsentError.localizedDescription);
return;
}
__strong __typeof__(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
completionHandler:^(NSError *loadAndPresentError) {
if (loadAndPresentError) {
// Consent gathering failed.
NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
return;
}
// Consent has been gathered.
}];
}];
}
Jika Anda perlu melakukan tindakan setelah pengguna membuat pilihan atau menutup formulir, tempatkan logika tersebut dalam completion handler untuk formulir Anda.
Permintaan iklan
Sebelum meminta iklan di aplikasi, periksa apakah Anda telah memperoleh izin dari pengguna
menggunakan UMPConsentInformation.sharedInstance.canRequestAds
. Ada dua tempat yang harus diperiksa saat mengumpulkan izin:
- Setelah izin dikumpulkan di sesi saat ini.
- Segera setelah Anda menelepon
requestConsentInfoUpdateWithParameters:completionHandler:
. Kemungkinan izin telah diperoleh pada sesi sebelumnya. Sebagai praktik terbaik untuk latensi, sebaiknya jangan menunggu callback selesai agar Anda dapat mulai memuat iklan sesegera mungkin setelah aplikasi diluncurkan.
Jika terjadi error selama proses pengumpulan izin, Anda tetap harus mencoba meminta iklan. UMP SDK menggunakan status izin dari sesi sebelumnya.
Swift
class ViewController: UIViewController {
// Use a boolean to initialize the Google Mobile Ads SDK and load ads once.
private var isMobileAdsStartCalled = false
override func viewDidLoad() {
super.viewDidLoad()
// Create a UMPRequestParameters object.
let parameters = UMPRequestParameters()
// Set tag for under age of consent. false means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
[weak self] requestConsentError in
guard let self else { return }
if let consentError = requestConsentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
UMPConsentForm.loadAndPresentIfRequired(from: self) {
[weak self] loadAndPresentError in
guard let self else { return }
if let consentError = loadAndPresentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
// Consent has been gathered.
if UMPConsentInformation.sharedInstance.canRequestAds {
self.startGoogleMobileAdsSDK()
}
}
}
// Check if you can initialize the Google Mobile Ads SDK in parallel
// while checking for new consent information. Consent obtained in
// the previous session can be used to request ads.
if UMPConsentInformation.sharedInstance.canRequestAds {
startGoogleMobileAdsSDK()
}
}
private func startGoogleMobileAdsSDK() {
DispatchQueue.main.async {
guard !self.isMobileAdsStartCalled else { return }
self.isMobileAdsStartCalled = true
// Initialize the Google Mobile Ads SDK.
GADMobileAds.sharedInstance().start()
// TODO: Request an ad.
// GADInterstitialAd.load(...)
}
}
}
Objective-C
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. NO means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = NO;
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable requestConsentError) {
if (requestConsentError) {
// Consent gathering failed.
NSLog(@"Error: %@", requestConsentError.localizedDescription);
return;
}
__strong __typeof__(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
completionHandler:^(NSError *loadAndPresentError) {
if (loadAndPresentError) {
// Consent gathering failed.
NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
return;
}
// Consent has been gathered.
__strong __typeof__(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
if (UMPConsentInformation.sharedInstance.canRequestAds) {
[strongSelf startGoogleMobileAdsSDKOnce];
}
}];
}];
// Check if you can initialize the Google Mobile Ads SDK in parallel
// while checking for new consent information. Consent obtained in
// the previous session can be used to request ads.
if (UMPConsentInformation.sharedInstance.canRequestAds) {
[self startGoogleMobileAdsSDKOnce];
}
}
- (void)startGoogleMobileAdsSDKOnce {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Initialize the Google Mobile Ads SDK.
[GADMobileAds.sharedInstance startWithCompletionHandler:nil];
// TODO: Request an ad.
// [GADInterstitialAd loadWithAdUnitID...];
});
}
Pengujian
Jika Anda ingin menguji integrasi dalam aplikasi saat mengembangkan, ikuti langkah-langkah di bawah untuk mendaftarkan perangkat pengujian secara terprogram.
- Panggil
requestConsentInfoUpdateWithParameters:completionHandler:
. Periksa output log untuk menemukan pesan yang terlihat seperti di bawah ini, yang menunjukkan ID perangkat Anda dan cara menambahkannya sebagai perangkat pengujian:
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
Salin ID perangkat pengujian ke papan klip.
Ubah kode yang akan dipanggil
UMPDebugSettings().testDeviceIdentifiers
dan teruskan daftar ID perangkat pengujian Anda.
Swift
let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
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" ];
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable error){
...
}];
Paksa geografi
UMP SDK menyediakan cara untuk menguji perilaku aplikasi Anda seolah-olah perangkat tersebut
berada di EEA atau Inggris Raya menggunakan the debugGeography
property of type UMPDebugGeography
on UMPDebugSettings
. Perlu diperhatikan bahwa
setelan debug hanya berfungsi pada perangkat pengujian.
Swift
let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = .EEA
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
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;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable error){
...
}];
Mereset status izin
Dalam menguji aplikasi dengan UMP SDK, sebaiknya reset status SDK agar dapat menyimulasikan pengalaman penginstalan pertama pengguna.
SDK menyediakan metode reset
untuk melakukannya.
Swift
UMPConsentInformation.sharedInstance.reset()
Objective-C
[UMPConsentInformation.sharedInstance reset];