تحت خطمشی رضایت کاربر اتحادیه اروپا Google، شما باید اطلاعات مشخصی را برای کاربران خود در منطقه اقتصادی اروپا (EEA) همراه با بریتانیا انجام دهید و رضایت آنها را برای استفاده از کوکیها یا سایر فضای ذخیرهسازی محلی، در صورت نیاز قانونی، و استفاده از دادههای شخصی کسب کنید ( مانند AdID) برای ارائه تبلیغات. این سیاست منعکس کننده الزامات دستورالعمل حریم خصوصی الکترونیک اتحادیه اروپا و مقررات عمومی حفاظت از داده ها (GDPR) است.
برای حمایت از ناشران در انجام وظایف خود تحت این خطمشی، Google پلتفرم پیامرسانی کاربر (UMP) SDK را ارائه میدهد. UMP SDK برای پشتیبانی از آخرین استانداردهای IAB به روز شده است. همه این پیکربندیها اکنون میتوانند به راحتی در حریم خصوصی و پیامرسانی AdMob مدیریت شوند.
پیش نیازها
- راهنمای شروع را کامل کنید
- Android API سطح 21 یا بالاتر
- اگر روی الزامات مربوط به GDPR کار می کنید،چگونه الزامات IAB بر پیام های رضایت اتحادیه اروپا تأثیر می گذاردچگونه الزامات IAB بر پیام های رضایت اتحادیه اروپا تأثیر می گذارد
یک نوع پیام ایجاد کنید
پیامهای کاربری را با یکی از انواع پیام کاربرموجوددر برگه حریم خصوصی و پیامرسانیAdMobAd Manager108 خود ایجاد کنید. UMP SDK سعی می کند یک پیام کاربر ایجاد شده از شناسه برنامه AdMob را در پروژه شما نمایش دهد. اگر هیچ پیامی برای برنامه شما پیکربندی نشده باشد، SDK یک خطا برمیگرداند.
برای جزئیات بیشتر،درباره حریم خصوصی و پیامرسانی را ببینید.
با Gradle نصب کنید
وابستگی Google User Messaging Platform SDK را به فایل Gradle سطح برنامه ماژول خود اضافه کنید، معمولا app/build.gradle
:
dependencies {
implementation 'com.google.android.ump:user-messaging-platform:2.1.0'
}
پس از ایجاد تغییرات در build.gradle
برنامه خود، حتما پروژه خود را با فایل های Gradle همگام کنید.
درخواست اطلاعات رضایت
باید در هر راهاندازی برنامه، با استفاده از requestConsentInfoUpdate()
درخواست بهروزرسانی اطلاعات رضایت کاربر را بدهید. این تعیین می کند که آیا کاربر شما باید رضایت خود را ارائه دهد، اگر قبلاً این کار را نکرده است یا اینکه رضایت او منقضی شده است.
در اینجا مثالی از نحوه بررسی وضعیت از MainActivity
در متد onCreate()
آورده شده است.
جاوا
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()));
});
}
}
کاتلین
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()))
})
}
}
در صورت نیاز فرم رضایت را بارگیری و نمایش دهید
مهم: API های زیر با UMP SDK نسخه 2.1.0 یا بالاتر سازگار هستند. پس از دریافت به روزترین وضعیت رضایت، باloadAndShowConsentFormIfRequired()
در کلاسConsentForm
تماس بگیرید تا فرم رضایت بارگیری شود. اگر وضعیت رضایت مورد نیاز باشد، SDK فرمی را بارگیری میکند و بلافاصله آن را از activityارائه شده ارائه میکند. callbackپس از رد شدن فرم نامیده می شود. اگر رضایت لازم نباشد، callbackبلافاصله نامیده می شود.
جاوا
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()));
});
}
}
کاتلین
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()
دریافت کرده اید یا خیر. هنگام جمع آوری رضایت دو مکان برای بررسی وجود دارد:
- هنگامی که رضایت در جلسه جاری جمع آوری شد.
- بلافاصله پس از تماس با
requestConsentInfoUpdate()
. امکان دارد در جلسه قبل رضایت گرفته شده باشد. بهعنوان بهترین روش تأخیر، توصیه میکنیم منتظر تکمیل تماس نمانید تا بتوانید در اسرع وقت پس از راهاندازی برنامه، بارگیری تبلیغات را شروع کنید.
اگر در فرآیند جمعآوری رضایت خطایی رخ داد، همچنان باید سعی کنید تبلیغات را درخواست کنید. UMP SDK از وضعیت رضایت جلسه قبل استفاده می کند.
جاوا
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(...);
}
}
کاتلین
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.getAndSet(true)) {
return
}
// Initialize the Google Mobile Ads SDK.
MobileAds.initialize(this)
// TODO: Request an ad.
// InterstitialAd.load(...)
}
}
گزینه های حفظ حریم خصوصی
برخی از فرمهای رضایت از کاربر میخواهند که رضایت خود را در هر زمانی تغییر دهد. برای اجرای دکمه گزینه های حریم خصوصی در صورت لزوم، مراحل زیر را رعایت کنید.
برای انجام این کار:
- یک عنصر رابط کاربری، مانند دکمهای در صفحه تنظیمات برنامهتان، که میتواند فرم گزینههای حریم خصوصی را راهاندازی کند، پیادهسازی کنید.
- هنگامی که
loadAndShowConsentFormIfRequired()
کامل شد،privacyOptionsRequirementStatus()
بررسی کنید تا مشخص شود که آیا عنصر UI که می تواند فرم گزینه های حریم خصوصی را ارائه دهد، نمایش داده شود. - هنگامی که کاربر با عنصر UI شما تعامل می کند، با
showPrivacyOptionsForm()
تماس بگیرید تا فرم را نشان دهد تا کاربر بتواند گزینه های حریم خصوصی خود را در هر زمانی به روز کند.
مثال زیر نحوه ارائه فرم گزینه های حریم خصوصی را از یک MenuItem
نشان می دهد.
جاوا
private final ConsentInformation consentInformation;
// Show a privacy options button if required.
public boolean isPrivacyOptionsRequired() {
return consentInformation.getPrivacyOptionsRequirementStatus()
== PrivacyOptionsRequirementStatus.REQUIRED;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
(OnConsentInfoUpdateSuccessListener) () -> {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this,
(OnConsentFormDismissedListener) loadAndShowError -> {
// ...
// Consent has been gathered.
if (isPrivacyOptionsRequired()) {
// Regenerate the options menu to include a privacy setting.
invalidateOptionsMenu();
}
}
)
}
// ...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_menu, menu);
MenuItem moreMenu = menu.findItem(R.id.action_more);
moreMenu.setVisible(isPrivacyOptionsRequired());
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// ...
popup.setOnMenuItemClickListener(
popupMenuItem -> {
if (popupMenuItem.getItemId() == R.id.privacy_settings) {
// Present the privacy options form when a user interacts with
// the privacy settings button.
UserMessagingPlatform.showPrivacyOptionsForm(
this,
formError -> {
if (formError != null) {
// Handle the error.
}
}
);
return true;
}
return false;
});
return super.onOptionsItemSelected(item);
}
کاتلین
private val consentInformation: ConsentInformation =
UserMessagingPlatform.getConsentInformation(context)
// Show a privacy options button if required.
val isPrivacyOptionsRequired: Boolean
get() =
consentInformation.privacyOptionsRequirementStatus ==
ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED
override fun onCreate(savedInstanceState: Bundle?) {
...
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(
this,
params,
ConsentInformation.OnConsentInfoUpdateSuccessListener {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this@MainActivity,
ConsentForm.OnConsentFormDismissedListener {
// ...
// Consent has been gathered.
if (isPrivacyOptionsRequired) {
// Regenerate the options menu to include a privacy setting.
invalidateOptionsMenu();
}
}
)
}
// ...
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.action_menu, menu)
menu?.findItem(R.id.action_more)?.apply {
isVisible = isPrivacyOptionsRequired
}
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// ...
popup.setOnMenuItemClickListener { popupMenuItem ->
when (popupMenuItem.itemId) {
R.id.privacy_settings -> {
// Present the privacy options form when a user interacts with
// the privacy settings button.
UserMessagingPlatform.showPrivacyOptionsForm(this) { formError ->
formError?.let {
// Handle the error.
}
}
true
}
else -> false
}
}
return super.onOptionsItemSelected(item)
}
آزمایش کردن
اگر میخواهید یکپارچهسازی برنامه خود را در حین توسعه آزمایش کنید، مراحل زیر را دنبال کنید تا دستگاه آزمایشی خود را به صورت برنامهنویسی ثبت کنید.
- با
requestConsentInfoUpdate()
تماس بگیرید. خروجی گزارش را برای پیامی مانند پیام زیر بررسی کنید، که شناسه دستگاه شما و نحوه افزودن آن را به عنوان یک دستگاه آزمایشی به شما نشان میدهد:
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
شناسه دستگاه آزمایشی خود را در کلیپ بورد خود کپی کنید.
کد خود را بهبا
ConsentDebugSettings.Builder().addTestDeviceHashedId()
تماس بگیرید و لیستی از شناسه های دستگاه آزمایشی خود را درارسال کنید.
جاوا
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,
...
);
کاتلین
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 راهی برای آزمایش رفتار برنامه شما ارائه میکند که گویی دستگاه در منطقه اقتصادی اروپا یا بریتانیا با استفاده از the setDebugGeography()
method which takes a DebugGeography
on ConsentDebugSettings.Builder
واقع شده است. توجه داشته باشید که تنظیمات اشکال زدایی فقط در دستگاه های آزمایشی کار می کند.
جاوا
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,
...
);
کاتلین
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()
را برای انجام این کار ارائه می دهد.
جاوا
consentInformation.reset();
کاتلین
consentInformation.reset()
نمونه هایی در GitHub
نمونه های ادغامنمونه های ادغام UMP SDK: Java | Kotlin