Mulai

Berdasarkan Kebijakan Izin Pengguna Uni Eropa Google, Anda harus membuat pengungkapan tertentu kepada pengguna di Wilayah Ekonomi Eropa (EEA) bersama dengan Inggris Raya dan mendapatkan izin dari mereka untuk menggunakan cookie atau penyimpanan lokal lainnya, jika diwajibkan secara hukum, dan untuk menggunakan data pribadi (seperti AdID) guna 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 diupdate untuk mendukung standar IAB terbaru. Semua konfigurasi ini sekarang dapat ditangani dengan mudah dalam Ad Manager privasi & pesan.

Prasyarat

Jenis pesan pengguna

Lihat Jenis pesan pengguna untuk mengetahui daftar lengkap pesan yang didukung. Untuk petunjuk spesifik cara menerapkan setiap jenis pesan, lihat menu navigasi sebelah kiri.

Mengimpor SDK

CocoaPods (lebih disukai)

UMP SDK disertakan sebagai dependensi Google Mobile Ads SDK Pod mulai dari Google Mobile Ads SDK 7.64.0.

Cara termudah untuk mengimpor SDK ke dalam project iOS adalah dengan menggunakan CocoaPods. Buka Podfile project Anda lalu tambahkan baris ini ke target aplikasi Anda:

pod 'Google-Mobile-Ads-SDK'

Lalu, jalankan perintah berikut:

pod install --repo-update

Jika Anda baru menggunakan CocoaPods, lihat Menggunakan CocoaPods untuk mengetahui detail tentang cara membuat dan menggunakan Podfile.

Download manual

Cara lain untuk mengimpor SDK adalah melakukannya secara manual.

Mendownload SDK

Kemudian, tarik framework ke project Xcode, dan pastikan Anda memilih Salin item jika diperlukan.

Kemudian, Anda dapat menyertakan framework dalam file yang diperlukan menggunakan:

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

Memperbarui Info.plist Anda

Dapatkan ID aplikasi Anda dari bagian Aplikasi seluler Ad Manager:

dan tambahkan ke Info.plist Anda:

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>

Menentukan apakah pesan perlu ditampilkan

Anda harus meminta pembaruan informasi izin pengguna di setiap peluncuran aplikasi, menggunakan requestConsentInfoUpdateWithParameters:completionHandler: sebelum memuat formulir. Hal ini dapat menentukan apakah pengguna perlu memberikan izin jika belum melakukannya atau sudah berakhir.

Jika diperlukan, Anda dapat mempresentasikan formulir di lain waktu.

Berikut adalah contoh cara memeriksa status saat aplikasi dimulai:

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.
                           }
                         }];
}

Memuat formulir jika tersedia

Sebelum menampilkan formulir, pertama-tama Anda harus menentukan apakah formulir tersedia. Formulir yang tidak tersedia dapat disebabkan oleh pengguna yang mengaktifkan pelacakan iklan terbatas atau jika Anda telah memberinya tag sebagai di bawah usia dewasa.

Untuk memeriksa ketersediaan formulir, gunakan the formStatus property on the UMPConsentInformation instance yang Anda buat sebelumnya.

Kemudian, tambahkan metode wrapper untuk memuat formulir:

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 {

}

Untuk memuat formulir, gunakan 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
        }
      }];
}

Presentasikan formulir jika diperlukan

Setelah Anda menentukan ketersediaan formulir dan memuatnya, gunakan metode presentFromViewController:completionHandler: pada instanceUMPConsentForm untuk menyajikan formulir.

Gunakan objek UMPConsentInformation dari sebelumnya untuk memeriksa consent status dan mengupdate metodeloadForm Anda:

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.
      }
    }
  }];
}

Jika Anda perlu melakukan tindakan setelah pengguna membuat pilihan atau menutup formulir, tempatkan logika tersebut di pengendali penyelesaian atau callback untuk formulir Anda.

Pengujian

Memaksa geografi

UMP SDK menyediakan cara untuk menguji perilaku aplikasi Anda seolah-olah perangkat berada di EEA atau Inggris Raya menggunakan the debugGeography property of type UMPDebugGeography on UMPDebugSettings.

Anda harus memberikan ID yang di-hash perangkat pengujian di setelan debug aplikasi untuk menggunakan fungsi debug. Jika Anda memanggilrequestConsentInfoUpdateWithParameters:completionHandler: tanpa menetapkan nilai ini, aplikasi Anda akan mencatat hash ID yang diperlukan saat berjalan.

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){
                           ...
}];

Dengan UMPDebugGeography, Anda memiliki opsi untuk memaksa geografi ke salah satu opsi ini:

DebugGeografi Deskripsi
UMPDebugGeographyDisabled Debug geografi dinonaktifkan.
UMPDebugGeographyEEA Geografi muncul seperti di EEA untuk perangkat debug.
UMPDebugGeographyNotEEA Geografi muncul sebagai tidak berada di EEA untuk perangkat debug.

Perhatikan bahwa setelan debug hanya berfungsi pada perangkat pengujian. Emulator tidak perlu ditambahkan ke daftar ID perangkat Anda karena pengujian sudah diaktifkan secara default.

Dalam menguji aplikasi dengan UMP SDK, sebaiknya reset status SDK agar Anda dapat menyimulasikan pengalaman penginstalan pertama pengguna. SDK menyediakan reset metode untuk melakukannya.

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

Anda juga harus memanggil reset jika memutuskan untuk menghapus UMP SDK sepenuhnya dari project Anda.