Theo Chính sách về sự đồng ý của người dùng ở Liên minh Châu Âu của Google, bạn phải tiết lộ một số thông tin nhất định cho người dùng ở Khu vực kinh tế Châu Âu (EEA) cùng với Vương quốc Anh và lấy sự đồng ý của họ để sử dụng cookie hoặc dữ liệu khác lưu trữ trên thiết bị (khi luật pháp yêu cầu) và sử dụng dữ liệu cá nhân (chẳng hạn như AdID) để phân phát quảng cáo. Chính sách này thể hiện các yêu cầu của Chỉ thị về quyền riêng tư và truyền thông điện tử của Liên minh Châu Âu và Quy định chung về việc bảo vệ dữ liệu (GDPR).
Để hỗ trợ các nhà xuất bản đáp ứng các nghĩa vụ của họ theo chính sách này, Google cung cấp SDK cho nền tảng thông báo cho người dùng (UMP). SDK UMP đã được cập nhật để hỗ trợ các tiêu chuẩn IAB mới nhất. Bạn hiện có thể xử lý tất cả những cấu hình này trong phần AdMob quyền riêng tư và thông báo một cách thuận tiện.
Điều kiện tiên quyết
- Xem hết hướng dẫn Bắt đầu sử dụng.
- Định cấu hình thông báo của bạn trong thẻ Quyền riêng tư và thông báo trong tài khoảnAdMob . Để biết thêm thông tin, hãy xem Giới thiệu về quyền riêng tư và thông báo,
- Nếu bạn đang thực hiện các yêu cầu liên quan đến GDPR, hãy đọc Các yêu cầu của IAB ảnh hưởng như thế nào đến thông báo yêu cầu đồng ý ở Liên minh Châu Âu.
Loại thông báo cho người dùng
Hãy xem Loại thông báo cho người dùng để biết danh sách đầy đủ các thông báo được hỗ trợ. Để biết hướng dẫn cụ thể về cách triển khai từng loại thông báo, hãy xem thanh điều hướng bên trái.
Cài đặt bằng Gradle
Nếu bạn đang sử dụng SDK quảng cáo trên thiết bị di động của Google phiên bản 19.8.0 trở lên, thì SDK UMP đi kèm với gói của bạn. Nếu bạn đang sử dụng phiên bản cũ hơn của SDK quảng cáo trên thiết bị di động, hãy đưa SDK UMP vào build.gradle của ứng dụng như sau:
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'
}
Sau khi thay đổi build.gradle của ứng dụng, hãy nhớ đồng bộ hoá dự án với tệp Gradle.
Tiếp theo,
tìm mã ứng dụng của bạn
và thêm nó vào AndroidManifest.xml
của bạn:
<?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>
Xác định xem có cần hiển thị một thông báo hay không
Bạn nên yêu cầu cập nhật thông tin về sự đồng ý của người dùng ở mỗi lần chạy ứng dụng, bằng cách sử dụng requestConsentInfoUpdate()
trước khi tải biểu mẫu.
Thông tin này có thể xác định xem người dùng có cần phải đồng ý hay không nếu họ chưa làm việc đó hoặc sự đồng ý của họ đã hết hạn.
consentInformation
khi bạn trình bày biểu mẫu khi cần.
Dưới đây là ví dụ về cách kiểm tra trạng thái khi khởi động ứng dụng:
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
Coming soon.
Tải một biểu mẫu (nếu có)
Trước khi hiển thị biểu mẫu, trước tiên bạn cần xác định xem biểu mẫu có sẵn không. Biểu mẫu không có sẵn có thể là do người dùng bật tính năng theo dõi quảng cáo bị hạn chế hoặc nếu bạn đã gắn thẻ các biểu mẫu đó là dưới độ tuổi hợp pháp để tự quản lý tài khoản.
Để kiểm tra phạm vi cung cấp của một biểu mẫu, hãy sử dụng
the isConsentFormAvailable()
method on the ConsentInformation
instance mà bạn đã tạo trước đó.
Sau đó, thêm phương thức trình bao bọc để tải biểu mẫu:
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
Coming soon.
Để tải biểu mẫu, hãy sử dụng 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
Coming soon.
Trình bày biểu mẫu nếu cần
Sau khi bạn xác định tình trạng rảnh/bận của biểu mẫu và tải biểu mẫu này, hãy sử dụng
phương thứcshow()
trên
bản saoConsentForm
để trình bày biểu mẫu.
Sử dụng đối tượngconsentInformation
từ trước đó để kiểm traconsent status và cập nhật phương thứcloadForm()
của bạn:
Java
public void loadForm() { 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) { // Handle dismissal by reloading form. loadForm(); } }); } } }, new UserMessagingPlatform.OnConsentFormLoadFailureListener() { @Override public void onConsentFormLoadFailure(FormError formError) { /// Handle Error. } } ); }
Kotlin
Coming soon.
Nếu bạn cần thực hiện bất kỳ hành động nào sau khi người dùng đã lựa chọn hoặc loại bỏ biểu mẫu, hãy đặt logic đó vào trình xử lý hoàn thành hoặc lệnh gọi lại cho biểu mẫu của bạn.
Kiểm thử
Buộc một khu vực địa lý
SDK UMP cung cấp một cách để kiểm tra hành vi của ứng dụng như thể thiết bị ở
Khu vực kinh tế Châu Âu (EEA) hoặc Vương quốc Anh bằng the setDebugGeography
method on ConsentDebugSettings.Builder
.
Bạn phải cung cấp mã băm của thiết bị kiểm thử trong phần cài đặt gỡ lỗi của ứng dụng để có thể sử dụng chức năng gỡ lỗi. Nếu bạn gọirequestConsentInfoUpdate()
mà không đặt giá trị này, thì ứng dụng của bạn sẽ ghi nhật ký hàm băm mã nhận dạng bắt buộc khi chạy.
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
Coming soon.
Với DebugGeography
, bạn có thể
bắt buộc chỉ định vị trí địa lý cho một trong các tuỳ chọn sau:
Gỡ lỗi địa lý | Mô tả |
---|---|
DEBUG_GEOGRAPHY_DISABLED |
Đã tắt khu vực địa lý gỡ lỗi. |
DEBUG_GEOGRAPHY_EEA |
Khu vực địa lý xuất hiện như ở Khu vực kinh tế Châu Âu (EEA) đối với các thiết bị gỡ lỗi. |
DEBUG_GEOGRAPHY_NOT_EEA |
Vị trí địa lý có vẻ như không ở Khu vực kinh tế Châu Âu (EEA) đối với thiết bị gỡ lỗi. |
Xin lưu ý rằng chế độ cài đặt gỡ lỗi chỉ hoạt động trên thiết bị thử nghiệm. Theo mặc định, bạn không cần thêm trình mô phỏng vào danh sách mã thiết bị.
Đặt lại trạng thái đồng ý
Khi kiểm thử ứng dụng bằng SDK UMP, bạn nên đặt lại trạng thái của SDK để có thể mô phỏng trải nghiệm cài đặt đầu tiên của người dùng.
SDK cung cấp phương thức reset()
để thực hiện việc này.
Java
consentInformation.reset();
Kotlin
consentInformation.reset()
Bạn cũng nên gọi reset()
nếu quyết định xoá hoàn toàn SDK UMP khỏi dự án của mình.