تحت خطمشی رضایت کاربر اتحادیه اروپا Google، شما باید اطلاعات مشخصی را برای کاربران خود در منطقه اقتصادی اروپا (EEA) همراه با بریتانیا انجام دهید و رضایت آنها را برای استفاده از کوکیها یا سایر فضای ذخیرهسازی محلی، در صورت نیاز قانونی، و استفاده از دادههای شخصی کسب کنید ( مانند AdID) برای ارائه تبلیغات. این سیاست منعکس کننده الزامات دستورالعمل حریم خصوصی الکترونیک اتحادیه اروپا و مقررات عمومی حفاظت از داده ها (GDPR) است.
برای حمایت از ناشران در انجام وظایف خود تحت این خطمشی، Google پلتفرم پیامرسانی کاربر (UMP) SDK را ارائه میدهد. UMP SDK برای پشتیبانی از آخرین استانداردهای IAB به روز شده است. همه این پیکربندیها اکنون میتوانند به راحتی در حریم خصوصی و پیامرسانی AdMob مدیریت شوند.
پیش نیازها
- راهنمای شروع را کامل کنید.
- پیام های خود را در برگه Privacy & Messaging حسابAdMob خود پیکربندی کنید. برای جزئیات بیشتر،درباره حریم خصوصی و پیامرسانی ،
- اگر روی الزامات مربوط به GDPR کار میکنید،چگونه الزامات IAB بر پیامهای رضایت اتحادیه اروپا تأثیر میگذارد را بخوانید.
انواع پیام کاربر
انواع پیام های کاربررا برای لیست کامل پیام های پشتیبانی شده ببینید. برای دستورالعملهای خاص در مورد اجرای هر نوع پیام، نوار پیمایش سمت چپ را ببینید.
با Gradle نصب کنید
اگر از Google Mobile Ads SDK نسخه 19.8.0 یا بالاتر استفاده میکنید، میتوانید این مرحله نصب Gradle را رد کنید. در غیر این صورت، UMP SDK را به صورت زیر در build.gradle
برنامه خود قرار دهید:
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'
}
پس از ایجاد تغییرات در build.gradle
برنامه خود، حتما پروژه خود را با فایل های Gradle همگام کنید.
مانیفست را به روز کنید
سپس،شناسه برنامه خود را پیدا کنید.و آن را به AndroidManifest.xml
خود اضافه کنید:
<?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>
تعیین کنید که آیا یک پیام باید نمایش داده شود
قبل از بارگیری فرم، باید در هر راه اندازی برنامه با استفاده از requestConsentInfoUpdate()
درخواست به روز رسانی اطلاعات رضایت کاربر را بدهید. این میتواند تعیین کند که آیا کاربر شما نیاز به ارائه رضایت دارد یا خیر، اگر قبلاً این کار را انجام نداده باشد یا اینکه رضایت او منقضی شده باشد.
consentInformation
هنگام ارائه فرم در صورت لزوم استفاده کنید.در اینجا مثالی از نحوه بررسی وضعیت در شروع برنامه آورده شده است:
جاوا
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. } }); } }
کاتلین
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. }) } }
در صورت موجود بودن فرم را بارگیری کنید
قبل از نمایش فرم، ابتدا باید مشخص کنید که آیا فرم موجود است یا خیر. فرمهای در دسترس نمیتواند به دلیل فعال کردن ردیابی تبلیغات محدود توسط کاربر باشد یا اینکه شما آنها را بهعنوان زیر سن رضایت برچسبگذاری کردهاید.
برای بررسی در دسترس بودن یک فرم، ازthe isConsentFormAvailable()
method on the ConsentInformation
instance که قبلا ایجاد کردید استفاده کنید.
سپس، یک متد wrapper برای بارگیری فرم اضافه کنید:
جاوا
... 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() { } }
کاتلین
... 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() { } }
برای بارگیری فرم، از the static loadConsentForm()
method on the UserMessagingPlatform
classاستفاده کنید.
جاوا
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. } } ); }
کاتلین
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. } ) }
در صورت نیاز فرم را ارائه دهید
پس از تعیین در دسترس بودن فرم و بارگیری آن، از روشshow()
در نمونهConsentForm
برای ارائه فرم استفاده کنید.
از شیconsentInformation
قبلی استفاده کنید تاconsent status بررسی کنید و روشloadForm()
خود را به روز کنید:
جاوا
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. } } ); }
کاتلین
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. } ) }
اگر پس از انتخاب کاربر یا رد کردن فرم، نیاز به انجام هر کاری دارید، آن منطق را در کنترل کننده تکمیل یا پاسخ تماس برای فرم خود قرار دهید.
آزمایش کردن
جغرافی اجباری
UMP SDK راهی برای آزمایش رفتار برنامه شما ارائه می دهد که گویی دستگاه با استفاده از the setDebugGeography
method on ConsentDebugSettings.Builder
در منطقه اقتصادی اروپا یا بریتانیا قرار دارد.
برای استفاده از قابلیت اشکالزدایی، باید شناسه هش شده دستگاه آزمایشی خود را در تنظیمات اشکالزدایی برنامه خود ارائه دهید. اگر بدون تنظیم این مقدارrequestConsentInfoUpdate()
را فراخوانی کنید، برنامه شما هنگام اجرا هش شناسه مورد نیاز را ثبت میکند.
جاوا
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. } });
کاتلین
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. }) }
با DebugGeography
، میتوانید موقعیت جغرافیایی را به یکی از این گزینهها وادار کنید:
DebugGeography | شرح |
---|---|
DEBUG_GEOGRAPHY_DISABLED | اشکالزدایی جغرافیایی غیرفعال است. |
DEBUG_GEOGRAPHY_EEA | جغرافیا مانند EEA برای دستگاه های اشکال زدایی ظاهر می شود. |
DEBUG_GEOGRAPHY_NOT_EEA | به نظر می رسد جغرافیا برای دستگاه های اشکال زدایی در EEA نیست. |
توجه داشته باشید که تنظیمات اشکال زدایی فقط در دستگاه های آزمایشی کار می کند. شبیه سازها نیازی به اضافه شدن به لیست شناسه دستگاه شما ندارند، زیرا آنها قبلاً آزمایش را به طور پیش فرض فعال کرده اند.
وضعیت رضایت را بازنشانی کنید
در آزمایش برنامه خود با UMP SDK، ممکن است بازنشانی وضعیت SDK برای شما مفید باشد تا بتوانید اولین تجربه نصب کاربر را شبیه سازی کنید. SDK روش reset()
را برای انجام این کار ارائه می دهد.
جاوا
consentInformation.reset();
کاتلین
consentInformation.reset()
همچنین اگر تصمیم دارید UMP SDK را به طور کامل از پروژه خود حذف کنید، باید با reset()
تماس بگیرید.