ภายใต้นโยบายความยินยอมของผู้ใช้ EU ของ Google คุณต้องเปิดเผยข้อมูลบางอย่างต่อผู้ใช้ในเขตเศรษฐกิจยุโรป (EEA) ร่วมกับสหราชอาณาจักร และต้องได้รับคำยินยอมเพื่อใช้คุกกี้หรือพื้นที่เก็บข้อมูลอื่นในเครื่องหากกฎหมายกำหนดไว้ และใช้ข้อมูลส่วนตัว (เช่น AdID) เพื่อแสดงโฆษณา นโยบายนี้เป็นผลมาจากข้อกำหนดด้าน ePrivacy และกฎระเบียบให้ความคุ้มครองข้อมูลส่วนบุคคลของผู้บริโภค (GDPR) ของสหภาพยุโรป
Google มี SDK สำหรับ User Messaging Platform (UMP) เพื่อสนับสนุนผู้เผยแพร่โฆษณาให้ปฏิบัติตามหน้าที่ของตนภายใต้นโยบายนี้ UMP SDK ได้รับการอัปเดตเพื่อรองรับมาตรฐาน IAB ล่าสุด ตอนนี้การกำหนดค่าทั้งหมดนี้จัดการได้อย่างสะดวกใน AdMob ความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้
ข้อกำหนดเบื้องต้น
- ทำตามคู่มือเริ่มต้นใช้งาน
- Android API ระดับ 21 ขึ้นไป
- หากคุณกําลังปรับปรุงข้อกําหนดที่เกี่ยวข้องกับ GDPR โปรดอ่าน ข้อกําหนดของ IAB ส่งผลต่อข้อความขอความยินยอมในสหภาพยุโรปอย่างไร
สร้างประเภทข้อความ
สร้างข้อความสำหรับผู้ใช้ด้วย ประเภทข้อความสำหรับผู้ใช้ที่ใช้ได้ ในแท็บความเป็นส่วนตัวและการรับส่งข้อความของ AdMob บัญชีของคุณ UMP SDK จะพยายามแสดงข้อความสำหรับผู้ใช้ที่สร้างขึ้นจาก AdMob รหัสแอปพลิเคชันที่ตั้งไว้ในโปรเจ็กต์ หากไม่มีการกำหนดค่าข้อความสำหรับแอปพลิเคชันของคุณ SDK จะแสดงข้อผิดพลาด
ดูรายละเอียดเพิ่มเติมได้ที่ เกี่ยวกับความเป็นส่วนตัวและการรับส่งข้อความ
ติดตั้งด้วย Gradle
เพิ่มทรัพยากร Dependency สำหรับ SDK สำหรับ User Messaging Platform ของ Google ไปยังไฟล์ Gradle ระดับแอปของโมดูล โดยปกติจะมี app/build.gradle
ดังนี้
dependencies {
implementation 'com.google.android.ump:user-messaging-platform:2.1.0'
}
หลังจากเปลี่ยนแปลง build.gradle
ของแอปแล้ว อย่าลืมซิงค์โปรเจ็กต์ของคุณกับไฟล์ Gradle
การขอข้อมูลความยินยอม
คุณควรส่งคำขออัปเดตข้อมูลความยินยอมของผู้ใช้ทุกครั้งที่เปิดแอป โดยใช้ requestConsentInfoUpdate()
การดำเนินการนี้จะกำหนดว่าผู้ใช้ต้องให้ความยินยอมในกรณีที่ยังไม่ได้ดำเนินการ หรือเมื่อความยินยอมหมดอายุแล้ว
ตัวอย่างวิธีตรวจสอบสถานะจาก MainActivity
ในเมธอด onCreate()
Java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
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;
@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
// of consent.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
(OnConsentInfoUpdateSuccessListener) () -> {
// TODO: Load and show the consent form.
},
(OnConsentInfoUpdateFailureListener) requestConsentError -> {
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
requestConsentError.getErrorCode(),
requestConsentError.getMessage()));
});
}
}
Kotlin
package com.example.myapplication
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
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
// of consent.
val params = ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(
this,
params,
ConsentInformation.OnConsentInfoUpdateSuccessListener {
// TODO: Load and show the consent form.
},
ConsentInformation.OnConsentInfoUpdateFailureListener {
requestConsentError ->
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
requestConsentError.errorCode(),
requestConsentError.message()))
})
}
}
โหลดและแสดงแบบฟอร์มความยินยอม หากจำเป็น
หลังจากได้รับสถานะความยินยอมเวอร์ชันล่าสุดแล้ว โปรดโทรหาloadAndShowConsentFormIfRequired()
ในConsentForm
ชั้นเรียนเพื่อโหลดแบบฟอร์มความยินยอม หากต้องมีสถานะความยินยอม SDK จะโหลดแบบฟอร์มและแสดงทันที จาก activityที่ให้ไว้ ระบบจะเรียกใช้ callback
หลังจากปิดแบบฟอร์มแล้ว หากไม่จำเป็นต้องได้รับความยินยอม ระบบจะเรียกใช้ callbackทันที
Java
public class MainActivity extends AppCompatActivity {
private ConsentInformation consentInformation;
@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
// of consent.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
(OnConsentInfoUpdateSuccessListener) () -> {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this,
(OnConsentFormDismissedListener) loadAndShowError -> {
if (loadAndShowError != null) {
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
loadAndShowError.getErrorCode(),
loadAndShowError.getMessage()));
}
// Consent has been gathered.
}
)
},
(OnConsentInfoUpdateFailureListener) requestConsentError -> {
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
requestConsentError.getErrorCode(),
requestConsentError.getMessage()));
});
}
}
Kotlin
class MainActivity : AppCompatActivity() {
private lateinit var consentInformation: ConsentInformation
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
// of consent.
val params = ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(
this,
params,
ConsentInformation.OnConsentInfoUpdateSuccessListener {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this@MainActivity,
ConsentForm.OnConsentFormDismissedListener {
loadAndShowError ->
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
loadAndShowError.errorCode(),
loadAndShowError.message()))
// Consent has been gathered.
}
)
},
ConsentInformation.OnConsentInfoUpdateFailureListener {
requestConsentError ->
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
requestConsentError.errorCode(),
requestConsentError.message()))
})
}
}
หากต้องการดำเนินการใดๆ หลังจากที่ผู้ใช้เลือกหรือปิดแบบฟอร์มแล้ว ให้ใส่ตรรกะนั้นใน callbackของแบบฟอร์ม
ส่งคำขอแสดงโฆษณา
ก่อนที่จะขอโฆษณาในแอป โปรดตรวจสอบว่าคุณได้รับความยินยอมจากผู้ใช้โดยใช้ canRequestAds()
หรือไม่ ขณะที่รวบรวมความยินยอม
คุณจะมี 2 ส่วนคือ
- เมื่อระบบรวบรวมความยินยอมในเซสชันปัจจุบันแล้ว
- ทันทีที่คุณโทรหา
requestConsentInfoUpdate()
เป็นไปได้ว่าได้รับความยินยอมแล้วในเซสชันก่อนหน้านี้ ตามแนวทางปฏิบัติแนะนำสำหรับเวลาในการตอบสนอง เราไม่แนะนำให้รอการโทรกลับเสร็จสมบูรณ์ เพื่อที่คุณจะได้เริ่มโหลดโฆษณาได้ทันทีหลังจากที่แอปเปิดตัวแล้ว
หากเกิดข้อผิดพลาดขึ้นระหว่างขั้นตอนการรวบรวมความยินยอม ก็ควรพยายามขอโฆษณาอยู่ UMP SDK ใช้สถานะความยินยอมจากเซสชันก่อนหน้า
Java
public class MainActivity extends AppCompatActivity {
private ConsentInformation consentInformation;
// Use an atomic boolean to initialize the Google Mobile Ads SDK and load ads once.
private final AtomicBoolean isMobileAdsInitializeCalled = new AtomicBoolean(false);
@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
// of consent.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
(OnConsentInfoUpdateSuccessListener) () -> {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this,
(OnConsentFormDismissedListener) loadAndShowError -> {
if (loadAndShowError != null) {
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
loadAndShowError.getErrorCode(),
loadAndShowError.getMessage()));
}
// Consent has been gathered.
if (consentInformation.canRequestAds) {
initializeMobileAdsSdk();
}
}
)
},
(OnConsentInfoUpdateFailureListener) requestConsentError -> {
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
requestConsentError.getErrorCode(),
requestConsentError.getMessage()));
});
// 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 (consentInformation.canRequestAds) {
initializeMobileAdsSdk();
}
}
private void initializeMobileAdsSdk() {
if (isMobileAdsInitializeCalled.getAndSet(true)) {
return;
}
// Initialize the Google Mobile Ads SDK.
MobileAds.initialize(this);
// TODO: Request an ad.
// InterstitialAd.load(...);
}
}
Kotlin
class MainActivity : AppCompatActivity() {
private lateinit var consentInformation: ConsentInformation
// Use an atomic boolean to initialize the Google Mobile Ads SDK and load ads once.
private var isMobileAdsInitializeCalled = AtomicBoolean(false)
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
// of consent.
val params = ConsentRequestParameters
.Builder()
.setTagForUnderAgeOfConsent(false)
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(
this,
params,
ConsentInformation.OnConsentInfoUpdateSuccessListener {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this@MainActivity,
ConsentForm.OnConsentFormDismissedListener {
loadAndShowError ->
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
loadAndShowError.errorCode(),
loadAndShowError.message()))
// Consent has been gathered.
if (consentInformation.canRequestAds) {
initializeMobileAdsSdk()
}
}
)
},
ConsentInformation.OnConsentInfoUpdateFailureListener {
requestConsentError ->
// Consent gathering failed.
Log.w(TAG, String.format("%s: %s",
requestConsentError.errorCode(),
requestConsentError.message()))
})
// 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 (consentInformation.canRequestAds) {
initializeMobileAdsSdk()
}
}
private fun initializeMobileAdsSdk() {
if (isMobileAdsInitializeCalled.get()) {
return
}
isMobileAdsInitializeCalled.set(true)
// Initialize the Google Mobile Ads SDK.
MobileAds.initialize(this)
// TODO: Request an ad.
// InterstitialAd.load(...)
}
}
การทดสอบ
หากต้องการทดสอบการผสานรวมในแอปขณะที่กำลังพัฒนา ให้ทำตามขั้นตอนด้านล่างเพื่อลงทะเบียนอุปกรณ์ทดสอบแบบเป็นโปรแกรม
- โทร
requestConsentInfoUpdate()
ตรวจสอบเอาต์พุตบันทึกเพื่อหาข้อความที่คล้ายกับด้านล่าง ซึ่งแสดงให้เห็นรหัสอุปกรณ์และวิธีเพิ่มเป็นอุปกรณ์ทดสอบ ดังนี้
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
คัดลอกรหัสอุปกรณ์ทดสอบไปยังคลิปบอร์ด
แก้ไขโค้ดเพื่อเรียกใช้
ConsentDebugSettings.Builder().addTestDeviceHashedId()
และส่งในรายการรหัสอุปกรณ์ทดสอบ
Java
ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
.build();
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.setConsentDebugSettings(debugSettings)
.build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
// Include the ConsentRequestParameters in your consent request.
consentInformation.requestConsentInfoUpdate(
this,
params,
...
);
Kotlin
val debugSettings = ConsentDebugSettings.Builder(this)
.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
.build()
val params = ConsentRequestParameters
.Builder()
.setConsentDebugSettings(debugSettings)
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
// Include the ConsentRequestParameters in your consent request.
consentInformation.requestConsentInfoUpdate(
this,
params,
...
)
บังคับภูมิศาสตร์
UMP SDK มีวิธีทดสอบลักษณะการทำงานของแอปเสมือนว่าอุปกรณ์อยู่ใน EEA หรือสหราชอาณาจักรโดยใช้ the setDebugGeography()
method which takes a DebugGeography
on ConsentDebugSettings.Builder
โปรดทราบว่าการตั้งค่าการแก้ไขข้อบกพร่องจะใช้ได้กับอุปกรณ์ทดสอบเท่านั้น
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);
// Include the ConsentRequestParameters in your consent request.
consentInformation.requestConsentInfoUpdate(
this,
params,
...
);
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)
// Include the ConsentRequestParameters in your consent request.
consentInformation.requestConsentInfoUpdate(
this,
params,
...
)
รีเซ็ตสถานะความยินยอม
ในการทดสอบแอปด้วย UMP SDK การรีเซ็ตสถานะของ SDK นั้นอาจเป็นประโยชน์สำหรับคุณ เพื่อให้สามารถจำลองประสบการณ์การติดตั้งครั้งแรกของผู้ใช้ได้
SDK จะมี reset()
เมธอดในการดำเนินการดังกล่าว
Java
consentInformation.reset();
Kotlin
consentInformation.reset()