Sampaikan masukan Anda dan bantu menyempurnakan rencana pengembangan Google Mobile Ads SDK. Ikuti Survei Tahunan Google Mobile Ads SDK untuk tahun 2023 sebelum ditutup pada tanggal 5 Mei 2023.

Mulai

Tetap teratur dengan koleksi Simpan dan kategorikan konten berdasarkan preferensi Anda.

Menurut 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 AdID) guna menayangkan iklan. Kebijakan ini mencerminkan persyaratan dalam ePrivacy Directive dan General Data Protection Regulation (GDPR) Uni Eropa.

Untuk mendukung penayang agar 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 di AdMob privasi & amp; pesan.

Prasyarat

Jenis pesan pengguna

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

Mengimpor SDK

CocoaPods (disarankan)

UMP SDK disertakan sebagai dependensi Pod Google Mobile Ads SDK yang dimulai dengan Google Mobile Ads SDK 7.64.0.

Cara termudah untuk mengimpor SDK ke dalam project iOS adalah dengan menggunakan CocoaPods. Buka Podfile project 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.

Mendownload SDK

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

Selanjutnya Anda dapat menyertakan framework tersebut di file mana pun yang diperlukan menggunakan:

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

Memperbarui Info.plist Anda

Menemukan ID aplikasi lalu tambahkan ke Info.plist:

<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 mereka belum melakukannya atau apakah izin mereka telah habis masa berlakunya.

Jika diperlukan, Anda dapat mempresentasikan formulir nanti.

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, Anda harus menentukan terlebih dahulu apakah formulir tersedia. Formulir yang tidak tersedia dapat disebabkan karena pengguna mengaktifkan pelacakan iklan terbatas atau jika Anda telah menandainya 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 metodepresentFromViewController:completionHandler: pada instanceUMPConsentForm untuk mempresentasikan 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 apa pun 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 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 berikut:

DebugGeografi Deskripsi
UMPDebugGeographyDisabled Geografi debug 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 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 metode reset 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.