Obowiązujące w Google zgoda użytkownika z UE , musisz udzielać odpowiednich informacji użytkownikom z Europejskiego Obszaru Gospodarczego (EOG) oraz z Wielką Brytanią i uzyskać ich zgodę na używanie plików cookie lub innych sposobów lokalnego przechowywania informacji, jeśli wymaga tego prawo, oraz wykorzystywać dane osobowe (np. AdID) do wyświetlania reklam. Polityka ta odzwierciedla wymagania UE zawarte w dyrektywie o prywatności i łączności elektronicznej Ogólnego rozporządzenia o ochronie danych (RODO).
Aby pomóc wydawcom w wypełnieniu obowiązków, jakie nakłada na nich ta polityka, Google oferuje pakiet SDK User Messaging Platform (UMP). Pakiet UMP SDK obsługuje teraz zgodne z najnowszymi standardami IAB. Wszystkie te konfiguracje można teraz w wygodny sposób obsługiwane w Ad Manager ustawieniach prywatności i wysyłanie wiadomości.
Wymagania wstępne
- Zapoznaj się z przewodnikiem dla początkujących.
- Interfejs API Androida na poziomie 21 lub wyższym
- Jeśli pracujesz nad wymaganiami związanymi z RODO, przeczytaj Jak wymagania IAB wpływają na zgodę użytkowników z UE wiadomości
Tworzenie typu wiadomości
Utwórz wiadomości dla użytkowników za pomocą jednej z tych metod: dostępne typy wiadomości dla użytkowników w sekcji Prywatność na karcie „Wiadomości” Ad Manager koncie. Pakiet UMP SDK próbuje wyświetlić wiadomość dla użytkownika utworzona Ad Manager na podstawie identyfikatora aplikacji ustawione w projekcie. Jeśli dla aplikacji nie jest skonfigurowany żaden komunikat, pakiet SDK zwraca błąd.
Więcej informacji: Prywatność i wyświetlanie wiadomości
Instalowanie za pomocą Gradle
Dodaj zależność z pakietem SDK User Messaging Platform od Google do modułu
plik Gradle na poziomie aplikacji, zwykle app/build.gradle
:
dependencies {
implementation("com.google.android.ump:user-messaging-platform:2.2.0")
}
Po wprowadzeniu zmian w usłudze build.gradle
aplikacji zsynchronizuj
projektu z plikami Gradle.
Dodaj identyfikator aplikacji
Identyfikator aplikacji znajdziesz w
Interfejs Ad Managera.
Dodaj dokument tożsamości do
AndroidManifest.xml
z następującym fragmentem kodu:
<manifest>
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
Prośba o informacje dotyczące zgody
Informacje o zgodzie użytkownika należy wysyłać w każdej aplikacji
za pomocą funkcji requestConsentInfoUpdate()
. Określa to
czy użytkownik musi wyrazić zgodę, jeśli jeszcze tego nie zrobił;
czy ich zgoda wygasła.
Oto przykład, jak sprawdzić stan elementu MainActivity
w
Metoda 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);
// Create a ConsentRequestParameters object.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.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)
// Create a ConsentRequestParameters object.
val params = ConsentRequestParameters
.Builder()
.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, "${requestConsentError.errorCode}: ${requestConsentError.message}")
})
}
}
W razie potrzeby wczytaj i wyświetl formularz zgody
Po uzyskaniu najbardziej aktualnego stanu zgody zadzwoń pod numer
loadAndShowConsentFormIfRequired()
w
ConsentForm
klasy, aby wczytać formularz zgody. Jeśli
jest wymagany stan zgody użytkownika, pakiet SDK wczytuje formularz i od razu go wyświetla
z podanego activity. callback
jest wywoływany po zamknięciu formularza. Jeśli zgoda nie jest wymagana, callback
jest wywoływany natychmiast.
Java
public class MainActivity extends AppCompatActivity {
private ConsentInformation consentInformation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a ConsentRequestParameters object.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.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)
// Create a ConsentRequestParameters object.
val params = ConsentRequestParameters
.Builder()
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(
this,
params,
ConsentInformation.OnConsentInfoUpdateSuccessListener {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this@MainActivity,
ConsentForm.OnConsentFormDismissedListener {
loadAndShowError ->
if (loadAndShowError != null) {
// Consent gathering failed.
Log.w(TAG, "${loadAndShowError.errorCode}: ${loadAndShowError.message}")
}
// Consent has been gathered.
}
)
},
ConsentInformation.OnConsentInfoUpdateFailureListener {
requestConsentError ->
// Consent gathering failed.
Log.w(TAG, "${requestConsentError.errorCode}: ${requestConsentError.message}")
})
}
}
Jeśli musisz wykonać jakieś działania po dokonaniu wyboru lub odrzuceniu go przez użytkownika umieść tę logikę w elemencie callback dla swojego formularza.
Wyślij żądanie
Zanim wyślesz prośbę o reklamy w aplikacji, sprawdź, czy masz jej zgodę
od użytkownika za pomocą funkcji canRequestAds()
. Dostępne są 2
które sprawdzić podczas uzyskiwania zgody użytkowników:
- Po uzyskaniu zgody użytkownika w bieżącej sesji.
- Zaraz po nawiązaniu połączenia z firmą
requestConsentInfoUpdate()
. Możliwe, że w poprzedniej sesji użytkownik wyraził zgodę. Jako opóźnienie zgodnie ze sprawdzoną metodą, nie czekaj na zakończenie połączenia, ponieważ będzie można ładowanie reklam od razu po uruchomieniu aplikacji.
Jeśli w trakcie procesu uzyskiwania zgody użytkowników wystąpi błąd, żądania reklam. Pakiet UMP SDK używa stanu zgody z poprzedniej wersji .
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);
// Create a ConsentRequestParameters object.
ConsentRequestParameters params = new ConsentRequestParameters
.Builder()
.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;
}
new Thread(
() -> {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(this, initializationStatus -> {});
runOnUiThread(
() -> {
// TODO: Request an ad.
// loadInterstitialAd();
});
})
.start();
}
}
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)
// Create a ConsentRequestParameters object.
val params = ConsentRequestParameters
.Builder()
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(
this,
params,
ConsentInformation.OnConsentInfoUpdateSuccessListener {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this@MainActivity,
ConsentForm.OnConsentFormDismissedListener {
loadAndShowError ->
if (loadAndShowError != null) {
// Consent gathering failed.
Log.w(TAG, "${loadAndShowError.errorCode}: ${loadAndShowError.message}")
}
// Consent has been gathered.
if (consentInformation.canRequestAds()) {
initializeMobileAdsSdk()
}
}
)
},
ConsentInformation.OnConsentInfoUpdateFailureListener {
requestConsentError ->
// Consent gathering failed.
Log.w(TAG, "${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
}
val backgroundScope = CoroutineScope(Dispatchers.IO)
backgroundScope.launch {
MobileAds.initialize(this@MainActivity) {}
runOnUiThread {
// TODO: Request an ad.
// loadInterstitialAd()
}
}
}
}
Opcje prywatności
Niektóre formularze zgody wymagają od użytkownika zmiany zgody w dowolnym momencie. Stosowanie wykonaj poniższe kroki, by w razie potrzeby zaimplementować przycisk opcji prywatności.
W tym celu:
- Zaimplementuj element interfejsu, np. przycisk na stronie ustawień aplikacji, które może wyświetlić formularz opcji prywatności.
- Po
loadAndShowConsentFormIfRequired()
zakończeniu sprawdź,privacyOptionsRequirementStatus()
, aby określić, czy element interfejsu, który może wyświetlać formularz opcji prywatności. - Gdy użytkownik wejdzie w interakcję z elementem interfejsu, wywołaj
showPrivacyOptionsForm()
aby wyświetlić formularz, aktualizować swoje opcje prywatności w dowolnym momencie.
Przykład poniżej pokazuje, jak wyświetlić formularz opcji prywatności
MenuItem
.
Java
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);
}
Kotlin
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)
}
Testowanie
Jeśli chcesz przetestować integrację w aplikacji w trakcie jej tworzenia, postępuj zgodnie z instrukcjami te kroki, by automatycznie zarejestrować urządzenie testowe. Pamiętaj, aby usunąć który będzie ustawiać te identyfikatory urządzeń testowych przed opublikowaniem aplikacji.
- Zadzwoń pod numer
requestConsentInfoUpdate()
. Sprawdź, czy w danych wyjściowych dziennika znajduje się komunikat podobny do poniższego przykładu, który pokazuje identyfikator Twojego urządzenia i jak dodać je jako urządzenie testowe:
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
Skopiuj identyfikator urządzenia testowego do schowka.
Zmodyfikuj swój kod, aby połączenia
DebugGeography.TestDeviceHashedIds
i przekaż listę identyfikatorów urządzeń testowych.
Wymuś użycie lokalizacji geograficznej
Pakiet UMP SDK umożliwia przetestowanie działania aplikacji w taki sposób, jakby urządzenie
przebywających w Europejskim Obszarze Gospodarczym lub Wielkiej Brytanii za pomocą usługi the setDebugGeography
method which takes a DebugGeography
on ConsentDebugSettings.Builder
. Pamiętaj, że
ustawienia debugowania działają tylko na urządzeniach testowych.
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,
...
)
Zresetuj stan zgody użytkownika
Podczas testowania aplikacji za pomocą pakietu SDK UMP pomocne może być zresetowanie pliku
pakietu SDK, co pozwala symulować pierwszą instalację u użytkownika.
Pakiet SDK udostępnia metodę reset()
.
Java
consentInformation.reset();
Kotlin
consentInformation.reset()