Gemäß der Google-Einwilligung der Nutzer in der EU verwenden, müssen Sie Sie müssen Ihren Nutzern im Europäischen Wirtschaftsraum (EWR) bestimmte Informationen offenlegen, mit dem Vereinigten Königreich und holen ihre Zustimmung zur Verwendung von Cookies oder anderen Formen der lokalen Speicherung ein, sofern dies gesetzlich vorgeschrieben ist, sowie um personenbezogene Daten wie die Werbe-ID (z. B. die Werbe-ID) für die Anzeigenauslieferung zu verwenden. Die Richtlinie entspricht den Anforderungen der EU-Datenschutzrichtlinie für elektronische Kommunikation und der EU-Datenschutz-Grundverordnung (DSGVO) gilt.
Google möchte Publisher bei der Umsetzung dieser Richtlinie unterstützen. das User Messaging Platform (UMP) SDK. Das UMP SDK wurde aktualisiert, um IAB-Standards. All diese Konfigurationen lassen sich in der AdMob Datenschutz- und Messaging.
Vorbereitung
- Arbeiten Sie den Startleitfaden durch.
- Android API-Level 21 oder höher
- Wenn Sie an Anforderungen in Bezug auf die DSGVO arbeiten, lesen Sie Auswirkungen der IAB-Anforderungen auf die EU Mitteilungen zur Einwilligung der Nutzer in der EU
Mitteilungstyp erstellen
Erstellen Sie Nutzermitteilungen mit einer der verfügbare Mitteilungstypen für Nutzer Datenschutz- und Messaging auf Ihrem AdMob Konto. Das UMP SDK versucht, eine Nutzernachricht erstellt aus AdMob Anwendungs-ID die in Ihrem Projekt festgelegt sind. Wenn für Ihre Anwendung keine Meldung konfiguriert ist, gibt einen Fehler zurück.
Weitere Informationen finden Sie unter Datenschutz und Mitteilungen
Mit Gradle installieren
Fügen Sie die Abhängigkeit für das Google User Messaging Platform SDK dem Modul
Gradle-Datei auf App-Ebene, normalerweise app/build.gradle
:
dependencies {
implementation("com.google.android.ump:user-messaging-platform:2.2.0")
}
Nachdem du die Änderungen an der build.gradle
deiner App vorgenommen hast, synchronisiere dein
mit Gradle-Dateien erstellen.
Anwendungs-ID hinzufügen
Ihre Anwendungs-ID finden Sie in der
AdMob-Benutzeroberfläche:
Fügen Sie die ID Ihrem
AndroidManifest.xml
.
mit dem folgenden Code-Snippet:
<manifest>
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
Anfrage zur Einwilligungserklärung
Sie sollten bei jeder App eine Aktualisierung der Einwilligungsinformationen des Nutzers anfordern
mit requestConsentInfoUpdate()
starten. Damit legen Sie fest,
ob Nutzer einwilligen müssen, falls noch nicht geschehen, oder
wenn die Einwilligung abgelaufen ist.
Hier ist ein Beispiel dafür, wie Sie den Status von MainActivity
im
onCreate()
-Methode.
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}")
})
}
}
Einwilligungsformular laden und bei Bedarf einblenden
Nachdem Sie den aktuellen Einwilligungsstatus erhalten haben, rufen Sie
loadAndShowConsentFormIfRequired()
am
ConsentForm
Klasse zum Laden eines Einwilligungsformulars. Wenn die
Einwilligungsstatus erforderlich ist, lädt das SDK ein Formular und zeigt es sofort an.
aus den activityaus. Die callback
wird aufgerufen , nachdem das Formular geschlossen wurde. Wenn keine Einwilligung erforderlich ist, callback
wird sofort aufgerufen.
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}")
})
}
}
Wenn du weitere Aktionen ausführen musst, nachdem der Nutzer eine Auswahl getroffen oder die Anzeige geschlossen hat platziere diese Logik in der callback für Ihr Formular.
Anzeigenanfrage senden
Bevor Sie Anzeigen in Ihrer App anfordern, prüfen Sie, ob Sie die Einwilligung eingeholt haben
vom Nutzer mit canRequestAds()
. Es gibt zwei
sollten Sie beim Einholen der Einwilligung überprüfen:
- Sobald in der aktuellen Sitzung die Einwilligung eingeholt wurde.
- Unmittelbar nach Ihrem Anruf bei
requestConsentInfoUpdate()
Möglicherweise wurde die Einwilligung bereits in der vorherigen Sitzung erteilt. Als Latenz solltet ihr nicht auf den Abschluss des Callbacks warten, Anzeigen so bald wie möglich nach der Einführung Ihrer App zu laden.
Wenn beim Einholen der Einwilligung ein Fehler auftritt, sollten Sie trotzdem Anzeigen anzufordern. Für das UMP SDK wird der Einwilligungsstatus aus dem vorherigen Sitzung.
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()
}
}
}
}
Datenschutzoptionen
Bei einigen Einwilligungsformularen muss der Nutzer seine Einwilligung jederzeit ändern. Einhaltung befolgen Sie die folgenden Schritte, um bei Bedarf eine Schaltfläche für Datenschutzoptionen zu implementieren.
Gehen Sie dazu wie folgt vor:
- Implementieren Sie ein UI-Element, z. B. eine Schaltfläche auf der Einstellungsseite Ihrer App, die ein Formular für Datenschutzoptionen auslösen kann.
- Sobald
loadAndShowConsentFormIfRequired()
der Vorgang abgeschlossen ist, prüfen SieprivacyOptionsRequirementStatus()
um zu bestimmen, ob UI-Element, über das das Formular für Datenschutzoptionen angezeigt werden kann - Wenn ein Nutzer mit Ihrem UI-Element interagiert, rufen Sie
showPrivacyOptionsForm()
um das Formular einzublenden, damit der Nutzer ihre Datenschutzeinstellungen jederzeit aktualisieren.
Das folgende Beispiel zeigt, wie das Formular für Datenschutzoptionen
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)
}
Test
Wenn Sie die Integration in Ihre App während der Entwicklung testen möchten, folgen Sie mit diesen Schritten können Sie Ihr Testgerät programmatisch registrieren. Achten Sie darauf, die Code, mit dem diese Testgeräte-IDs festgelegt werden, bevor Sie Ihre App veröffentlichen.
- Rufen Sie uns unter
requestConsentInfoUpdate()
an. Suchen Sie in der Logausgabe nach einer Nachricht ähnlich dem folgenden Beispiel. Ihre Geräte-ID und wie Sie sie als Testgerät hinzufügen:
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
Kopieren Sie die Testgeräte-ID in die Zwischenablage.
Ändern Sie Ihren Code, Anrufen
ConsentDebugSettings.Builder().addTestDeviceHashedId()
und übergeben Sie eine Liste Ihrer Testgeräte-IDs.
Geografie erzwingen
Mit dem UMP SDK können Sie das Verhalten Ihrer App so testen, als wäre das Gerät
sich im EWR oder Vereinigten Königreich befinden, unter Verwendung von the setDebugGeography()
method which takes a DebugGeography
on ConsentDebugSettings.Builder
. Beachten Sie, dass
Debug-Einstellungen funktionieren nur auf Testgeräten.
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,
...
)
Einwilligungsstatus zurücksetzen
Wenn Sie Ihre App mit dem UMP SDK testen, kann es hilfreich sein, das
Status des SDK, um die erste Installation durch einen Nutzer zu simulieren.
Das SDK bietet dazu die Methode reset()
.
Java
consentInformation.reset();
Kotlin
consentInformation.reset()