Jetzt loslegen

Gemäß der Richtlinie zur EU-Nutzereinwilligung von Google müssen Sie Ihren Nutzern im Europäischen Wirtschaftsraum (EWR) zusammen mit dem Vereinigten Königreich bestimmte Informationen offenlegen und ihre Einwilligung zu folgenden Aktivitäten einholen: Einsatz von Cookies oder anderen Formen der lokalen Speicherung, falls die Einholung der Einwilligung dafür gesetzlich vorgeschrieben ist, sowie die Verwendung personenbezogener Daten (z. B. AdID) zur Auslieferung von Anzeigen. Die Richtlinie entspricht den Anforderungen der EU-Datenschutzrichtlinie für elektronische Kommunikation und der EU-Datenschutz-Grundverordnung (DSGVO).

Google bietet das SDK für User Messaging Platform (UMP) an, um Publisher bei der Umsetzung dieser Richtlinie zu unterstützen. Das UMP SDK wurde aktualisiert und unterstützt die neuesten IAB-Standards. Alle diese Konfigurationen können jetzt bequem in AdMob Datenschutz und Mitteilungen verarbeitet werden.

Voraussetzungen

Arten von Nutzernachrichten

Eine vollständige Liste der unterstützten Nachrichten finden Sie unter Arten von Nutzernachrichten.. Eine genaue Anleitung zur Implementierung der einzelnen Nachrichtentypen finden Sie in der linken Navigationsleiste.

Mit Gradle installieren

Wenn Sie das Google Mobile Ads SDK 19.8.0 oder höher verwenden, können Sie diesen Gradle-Installationsschritt überspringen. Fügen Sie andernfalls das UMP SDK so in den build.gradle Ihrer App ein:

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'
}

Nachdem Sie die build.gradle Ihrer App geändert haben, müssen Sie Ihr Projekt mit Gradle-Dateien synchronisieren.

Manifest aktualisieren

Rufen Sie als Nächstes die App-ID auf. hinzufügen und zu AndroidManifest.xml hinzufügen:

<?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>

Festlegen, ob eine Nachricht angezeigt werden muss

Du solltest vor dem Laden eines Formulars mit jedem requestConsentInfoUpdate() App-Start eine Aktualisierung der Einwilligungserklärung anfordern. So lässt sich feststellen, ob ein Nutzer seine Einwilligung erteilen muss, falls er dies noch nicht getan hat oder seine Einwilligung abgelaufen ist.

Verwenden Sie die im consentInformation-Objekt gespeicherten Informationen, wenn Sie das Formular einblenden.

Hier ein Beispiel für die Prüfung des Status beim Start der App:

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

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.
        })
  }
}

Formular laden, wenn verfügbar

Bevor ein Formular angezeigt wird, müssen Sie prüfen, ob eines verfügbar ist. Nicht verfügbare Formulare können darauf zurückzuführen sein, dass Nutzer das eingeschränkte Anzeigen-Tracking aktiviert haben oder du das Tag als minderjährig gekennzeichnet hast.

Mitthe isConsentFormAvailable() method on the ConsentInformation instance können Sie die Verfügbarkeit eines Formulars prüfen.

Fügen Sie dann eine Wrapper-Methode hinzu, um das Formular zu laden:

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

...
    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() {

  }
}

Zum Laden des Formulars verwenden Sie 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

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.
      }
  )
}

Formular bei Bedarf präsentieren

Nachdem Sie die Verfügbarkeit des Formulars ermittelt und geladen haben, können Sie das Formular mit der Methodeshow() in der InstanzConsentForm präsentieren.

Verwenden Sie dasconsentInformation -Objekt aus der vorherigen Phase, um dieconsent status zu prüfen und dieloadForm() -Methode zu aktualisieren:

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;
          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.
        }
      }
  );
}

Kotlin

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.
      }
  )
}

Wenn Sie Aktionen ausführen müssen, nachdem der Nutzer eine Auswahl getroffen oder das Formular geschlossen hat, platzieren Sie diese Logik im Vervollständigungs-Handler oder Callback für Ihr Formular.

Testen

Geografie erzwingen

Mit dem UMP SDK können Sie das Verhalten Ihrer App so testen, als ob sich das Gerät im EWR oder im Vereinigten Königreich befinden würde, und zwar mit the setDebugGeography method on ConsentDebugSettings.Builder.

Damit Sie die Fehlerbehebungsfunktion verwenden können, müssen Sie die Hash-ID Ihres Testgeräts in den Fehlerbehebungseinstellungen Ihrer App angeben. Wenn SierequestConsentInfoUpdate() aufrufen, ohne diesen Wert festzulegen, protokolliert Ihre Anwendung beim Ausführen den erforderlichen ID-Hash.

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

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.
        })
}

Mit DebugGeographykönnen Sie die Geografie auf eine der folgenden Optionen erzwingen:

DebugGeografie Beschreibung
DEBUG_GEOGRAPHY_DISABLED Region für die Fehlerbehebung deaktiviert.
DEBUG_GEOGRAPHY_EEA Für Geräte zur Fehlerbehebung wird eine Region wie im EWR angezeigt.
DEBUG_GEOGRAPHY_NOT_EEA Bei Geräten zur Fehlerbehebung wird die Region nicht im EWR angezeigt.

Die Einstellungen zur Fehlerbehebung funktionieren nur auf Testgeräten. Sie müssen Ihrer Geräte-ID-Liste keine Emulatoren hinzufügen, da für sie bereits Tests standardmäßig aktiviert sind.

Beim Testen Ihrer App mit dem UMP SDK kann es hilfreich sein, den Status des SDKs zurückzusetzen, um die Erstinstallation eines Nutzers zu simulieren. Das SDK bietet die Methode reset() dafür.

Java

consentInformation.reset();

Kotlin

consentInformation.reset()

Du solltest dich auch reset() anmelden, wenn du das UMP SDK vollständig aus deinem Projekt entfernen möchtest.