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 AdMob privasi & pesan.
Prasyarat
- Selesaikan panduan Memulai.
- Konfigurasikan pesan Anda pada tab Privasi & pesan di akunAdMob Anda. Untuk mengetahui detail selengkapnya, baca Tentang privasi dan fitur pesan,
- Jika Anda sedang mengerjakan persyaratan terkait GDPR, baca Pengaruh persyaratan IAB terhadap pesan izin Uni Eropa.
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.
Menginstal dengan Gradle
Jika menggunakan Google Mobile Ads SDK versi 19.8.0 atau yang lebih tinggi, Anda dapat melewati langkah penginstalan Gradle ini. Jika tidak, sertakan UMP SDK dalam build.gradle
aplikasi
Anda sebagai berikut:
dependencies {
// This dependency is automatically included by Google Mobile Ads SDK 19.8.0
// or higher.
implementation 'com.google.android.ump:user-messaging-platform:2.0.0'
}
Setelah membuat perubahan pada build.gradle
aplikasi Anda, pastikan untuk menyinkronkan
project dengan file Gradle.
Memperbarui manifes
Berikutnya,
menemukan ID aplikasi Anda
dan tambahkan ke AndroidManifest.xml
Anda:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rewardedinterstitialexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Sample app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Menentukan apakah pesan perlu ditampilkan
Anda harus meminta pembaruan informasi izin pengguna di setiap peluncuran
aplikasi, menggunakan requestConsentInfoUpdate()
sebelum memuat formulir.
Hal ini dapat menentukan apakah pengguna perlu memberikan izin jika
belum melakukannya atau sudah berakhir.
consentInformation
saat Anda mempresentasikan formulir jika diperlukan.
Berikut adalah contoh cara memeriksa status saat aplikasi dimulai:
Java
package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import com.google.android.ump.ConsentForm; import com.google.android.ump.ConsentInformation; import com.google.android.ump.ConsentRequestParameters; import com.google.android.ump.FormError; import com.google.android.ump.UserMessagingPlatform; public class MainActivity extends AppCompatActivity { private ConsentInformation consentInformation; private ConsentForm consentForm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set tag for under age of consent. false means users are not under // age. ConsentRequestParameters params = new ConsentRequestParameters .Builder() .setTagForUnderAgeOfConsent(false) .build(); consentInformation = UserMessagingPlatform.getConsentInformation(this); consentInformation.requestConsentInfoUpdate( this, params, new ConsentInformation.OnConsentInfoUpdateSuccessListener() { @Override public void onConsentInfoUpdateSuccess() { // The consent information state was updated. // You are now ready to check if a form is available. } }, new ConsentInformation.OnConsentInfoUpdateFailureListener() { @Override public void onConsentInfoUpdateFailure(FormError formError) { // Handle the error. } }); } }
Kotlin
package com.example.myapplication import com.google.android.ump.ConsentForm import com.google.android.ump.ConsentInformation import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateFailureListener import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateSuccessListener import com.google.android.ump.ConsentRequestParameters import com.google.android.ump.UserMessagingPlatform class MainActivity : AppCompatActivity() { private lateinit var consentInformation: ConsentInformation private lateinit var consentForm: ConsentForm override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Set tag for under age of consent. false means users are not under // age. val params = ConsentRequestParameters .Builder() .setTagForUnderAgeOfConsent(false) .build() consentInformation = UserMessagingPlatform.getConsentInformation(this) consentInformation.requestConsentInfoUpdate( this, params, OnConsentInfoUpdateSuccessListener { // The consent information state was updated. // You are now ready to check if a form is available. }, OnConsentInfoUpdateFailureListener { // Handle the error. }) } }
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 isConsentFormAvailable()
method on the ConsentInformation
instance yang Anda buat sebelumnya.
Kemudian, tambahkan metode wrapper untuk memuat formulir:
Java
... consentInformation.requestConsentInfoUpdate( this, params, new ConsentInformation.OnConsentInfoUpdateSuccessListener() { @Override public void onConsentInfoUpdateSuccess() { // The consent information state was updated. // You are now ready to check if a form is available. if (consentInformation.isConsentFormAvailable()) { loadForm(); } } }, new ConsentInformation.OnConsentInfoUpdateFailureListener() { @Override public void onConsentInfoUpdateFailure(FormError formError) { // Handle the error. } }); } public void loadForm() { } }
Kotlin
... consentInformation.requestConsentInfoUpdate( this, params, OnConsentInfoUpdateSuccessListener { // The consent information state was updated. // You are now ready to check if a form is available. if (consentInformation.isConsentFormAvailable) { loadForm() } }, OnConsentInfoUpdateFailureListener { // Handle the error. }) } fun loadForm() { } }
Untuk memuat formulir, gunakan the static loadConsentForm()
method on the UserMessagingPlatform
class.
Java
public void loadForm() { // Loads a consent form. Must be called on the main thread. UserMessagingPlatform.loadConsentForm( this, new UserMessagingPlatform.OnConsentFormLoadSuccessListener() { @Override public void onConsentFormLoadSuccess(ConsentForm consentForm) { MainActivity.this.consentForm = consentForm; } }, new UserMessagingPlatform.OnConsentFormLoadFailureListener() { @Override public void onConsentFormLoadFailure(FormError formError) { // Handle the error. } } ); }
Kotlin
fun loadForm() { // Loads a consent form. Must be called on the main thread. UserMessagingPlatform.loadConsentForm( this, UserMessagingPlatform.OnConsentFormLoadSuccessListener { this.consentForm = consentForm }, UserMessagingPlatform.OnConsentFormLoadFailureListener { // Handle the error. } ) }
Presentasikan formulir jika diperlukan
Setelah Anda menentukan ketersediaan formulir dan memuatnya, gunakan metode
show()
pada
instanceConsentForm
untuk menyajikan formulir.
Gunakan objek
consentInformation
dari sebelumnya untuk memeriksa
consent status dan mengupdate
metodeloadForm()
Anda:
Java
public void loadForm() { // Loads a consent form. Must be called on the main thread. UserMessagingPlatform.loadConsentForm( this, new UserMessagingPlatform.OnConsentFormLoadSuccessListener() { @Override public void onConsentFormLoadSuccess(ConsentForm consentForm) { MainActivity.this.consentForm = consentForm; if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) { consentForm.show( MainActivity.this, new ConsentForm.OnConsentFormDismissedListener() { @Override public void onConsentFormDismissed(@Nullable FormError formError) { if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) { // App can start requesting ads. } // Handle dismissal by reloading form. loadForm(); } }); } } }, new UserMessagingPlatform.OnConsentFormLoadFailureListener() { @Override public void onConsentFormLoadFailure(FormError formError) { // Handle Error. } } ); }
Kotlin
fun loadForm() { // Loads a consent form. Must be called on the main thread. UserMessagingPlatform.loadConsentForm( this, UserMessagingPlatform.OnConsentFormLoadSuccessListener { this.consentForm = consentForm if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.REQUIRED) { consentForm.show( this, ConsentForm.OnConsentFormDismissedListener { if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.OBTAINED) { // App can start requesting ads. } // Handle dismissal by reloading form. loadForm() } ) } }, UserMessagingPlatform.OnConsentFormLoadFailureListener { // Handle the error. } ) }
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 setDebugGeography
method on ConsentDebugSettings.Builder
.
Anda harus memberikan ID yang di-hash perangkat pengujian di setelan debug aplikasi untuk
menggunakan fungsi debug. Jika Anda memanggilrequestConsentInfoUpdate()
tanpa menetapkan nilai ini, aplikasi Anda akan mencatat hash ID yang diperlukan saat berjalan.
Java
ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this) .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA) .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID") .build(); ConsentRequestParameters params = new ConsentRequestParameters .Builder() .setConsentDebugSettings(debugSettings) .build(); consentInformation = UserMessagingPlatform.getConsentInformation(this); consentInformation.requestConsentInfoUpdate(this, params, new ConsentInformation.OnConsentInfoUpdateSuccessListener() { @Override public void onConsentInfoUpdateSuccess() { // The consent information state was updated. // You are now ready to check if a form is available. } }, new ConsentInformation.OnConsentInfoUpdateFailureListener() { @Override public void onConsentInfoUpdateFailure(FormError formError) { // Handle the error. } });
Kotlin
val debugSettings = ConsentDebugSettings.Builder(this) .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA) .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID") .build() val params = ConsentRequestParameters .Builder() .setConsentDebugSettings(debugSettings) .build() consentInformation = UserMessagingPlatform.getConsentInformation(this) consentInformation.requestConsentInfoUpdate( this, params, OnConsentInfoUpdateSuccessListener { // The consent information state was updated. // You are now ready to check if a form is available. }, OnConsentInfoUpdateFailureListener { // Handle the error. }) }
Dengan DebugGeography
, Anda memiliki opsi untuk
memaksa geografi ke salah satu opsi ini:
DebugGeografi | Deskripsi |
---|---|
DEBUG_GEOGRAPHY_DISABLED |
Debug geografi dinonaktifkan. |
DEBUG_GEOGRAPHY_EEA |
Geografi muncul seperti di EEA untuk perangkat debug. |
DEBUG_GEOGRAPHY_NOT_EEA |
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.
Reset status izin
Dalam menguji aplikasi dengan UMP SDK, sebaiknya reset
status SDK agar Anda dapat menyimulasikan pengalaman penginstalan pertama pengguna.
SDK menyediakan reset()
metode untuk melakukannya.
Java
consentInformation.reset();
Kotlin
consentInformation.reset()
Anda juga harus memanggil reset()
jika memutuskan untuk menghapus UMP SDK sepenuhnya dari project Anda.