Prerequisites
IAB の要件が EU ユーザー向け同意メッセージに与える影響をご覧ください。
はじめに
Google の EU ユーザーの同意ポリシーに基づき、欧州経済領域(EEA)のユーザーには英国に加えて特定の開示を行い、法的に必要な場合は Cookie などのローカル ストレージを使用することと、広告配信に個人データ(AdID など)を使用することに同意する必要があります。このポリシーには、EU の e プライバシー指令と一般データ保護規則(GDPR)の要件が反映されています。
Google は、パブリッシャー様がこのポリシーで定められた義務を果たすために、これまでのオープンソースの Consent SDK に代わる、User Messaging Platform(UMP)SDK を提供しています。UMP SDK は、最新の IAB 標準をサポートするように更新されています。また、同意フォームの設定と広告パートナーのリスティング手続きも簡素化されました。これらの設定はすべて、AdMob の「プライバシーとメッセージ」で手軽に処理できるようになりました。
同意が不要ではないと判断した場合でも、ユーザーがアプリを起動するたびにフォームを読み込むことをおすすめします。これにより、ユーザーが同意設定の変更を希望している場合でも、フォームをすぐに表示できるようになります。
このガイドでは、SDK のインストール、IAB ソリューションの実装、テスト機能の有効化について説明します。
Gradle を使用してインストールする
アプリの build.gradle にこのライブラリを含めます。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.ump:user-messaging-platform:2.0.0'
}
完了したら、Gradle の同期を忘れないでください。
アプリ ID を AndroidManifest.xmlに追加
ヘルプセンターに記載されている手順に沿ってアプリ ID を取得します。
アプリ ID を 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">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR-APP-ID"/>
<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>
SDK の使用
SDK は、直線的に使用できるように設計されています。SDK を使用する手順は次のとおりです。
- 最新の同意情報をリクエストします。
- 同意が必要かどうかを確認します。
- 利用可能なフォームがあるかどうかを確認し、ある場合はそのフォームを読み込みます。
- フォームを表示します。
- ユーザーが同意を変更できる方法を提供する。
最新の同意情報をリクエストする
アプリを起動するたびに同意情報の更新をリクエストすることをおすすめします。これにより、ユーザーが同意する必要があるかどうかを判断できます。
Java
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 underage of consent. Here false means users are not underage. 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
import android.os.Bundle import com.google.android.ump.* class MainActivity : AppCompactActivity() { private lateinit var consentInformation: ConsentInformation private var consentForm: ConsentForm? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Set tag for underage of consent. Here false means users are not underage. val params = ConsentRequestParameters.Builder() .setTagForUnderAgeOfConsent(false) .build() consentInformation = UserMessagingPlatform.getConsentInformation(this) consentInformation.requestConsentInfoUpdate( this, params, { // The consent information state was updated. // You are now ready to check if a form is available. }, { formError -> // Handle the error. } ) } }
利用可能な場合はフォームを読み込む
ユーザーの同意をユーザーに求めた後、フォームが利用可能かどうかを判断します。
フォームを利用できない場合は、次のようなさまざまな理由が考えられます。
- ユーザーの広告トラッキングが制限されています。
- 同意年齢に満たないユーザーとしてタグ付けしました。
フォームが利用可能かどうかを確認するには、ConsentInformation
インスタンスで isConsentFormAvailable()
メソッドを使用します。フォームを読み込むラッパー メソッドを追加します。
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, { // The consent information state was updated. // You are now ready to check if a form is available. if (consentInformation.isConsentFormAvailable) { loadForm() } }, { formError -> // Handle the error. } ) } private fun loadForm() { }
フォームを読み込むには、UserMessagingPlatform
クラスの静的 loadConsentForm()
メソッドを使用します。このメソッドは、メインスレッドからのみ呼び出す必要があります。loadForm()
メソッドを次のように変更します。
Java
public void loadForm() { 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
private fun loadForm() { UserMessagingPlatform.loadConsentForm( this, { consentForm -> this.consentForm = consentForm }, { formError -> // Handle the error. } ) }
必要に応じてフォームを提示します。
フォームを提示するには、ConsentForm
インスタンスで show()
メソッドを使用します。ユーザーがフォームを提示する前に同意が必要かどうかを判断する必要があります。同意が必要かどうかを確認するには、ConsentInformation
オブジェクトの getConsentStatus()
メソッドを確認します。このメソッドは、ConsentInformation.ConsentStatus
型の列挙型を返します。次の 4 つの値があります。
ConsentStatus.UNKNOWN
: 不明な同意ステータス。ConsentStatus.REQUIRED
: ユーザーの同意が必要ですが、まだ取得されていません。ConsentStatus.NOT_REQUIRED
: ユーザーの同意は不要です。たとえば、ユーザーが EEA または英国に居住していないとします。ConsentStatus.OBTAINED
: ユーザーの同意を得ました。パーソナライズが定義されていません。
loadForm()
メソッドを次のように変更します。
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 the error. } }); }
Kotlin
private fun loadForm() { UserMessagingPlatform.loadConsentForm( this, { consentForm -> this.consentForm = consentForm if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.REQUIRED) { consentForm.show(this) { formError -> // Handle dismissal by reloading form. loadForm() } } }, { formError -> // Handle the error. } ) }
同意が必要ない場合は、フォームへの参照を保持して、ユーザーが同意ステータスを変更できるようにします。
テスト
強制的に地域を適用する
UMP SDK を使用すると、ConsentDebugSettings.Builder
の setDebugGeography()
メソッドを使用して、デバイスが EEA にあるかのように、アプリの動作をテストできます。
デバッグ機能を使用するには、アプリのデバッグ設定でテストデバイスのハッシュ ID を指定する必要があります。この値を設定せずに requestConsentInfoUpdate()
を呼び出すと、アプリは実行時に必要な ID ハッシュをログに記録します。
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, { // The consent information state was updated. // You are now ready to check if a form is available. }, { formError -> // Handle the error. } )
SDK でデバイスが EEA または英国にないものとして扱われるようにするには、DebugGeography.DEBUG_GEOGRAPHY_NOT_EEA
を使用します。デバッグ設定はテストデバイスでのみ機能します。テストはデフォルトで有効になっているため、エミュレータをデバイス ID リストに追加する必要はありません。
同意ステータスをリセットする
UMP SDK を使用してアプリをテストする際は、SDK の状態をリセットして、ユーザーの初回インストール シミュレーションをシミュレートすると便利な場合があります。SDK には、これを行うための reset
メソッドが用意されています。
Java
consentInformation.reset();
Kotlin
consentInformation.reset()
アプリ測定の遅延(省略可)
デフォルトでは、Google Mobile Ads SDK によってアプリの測定が初期化され、アプリの起動時にユーザーレベルのイベントデータが Google に送信されるようになります。 この初期化動作により、コードをさらに変更することなく、AdMob のユーザー指標を有効にできます。
ただし、これらのイベントを送信する前にアプリでユーザーの同意が必要な場合は、明示的に Mobile Ads SDK を初期化するか、広告を読み込むまで、アプリの測定を遅らせることができます。
アプリの測定を遅らせるには、AndroidManifest.xml
に次の <meta-data>
タグを追加します。
<manifest> <application> <!-- Delay app measurement until MobileAds.initialize() is called. --> <meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT" android:value="true"/> </application> </manifest>
メディエーション
メディエーションを使用する場合は、アプリで使用する同意フレームワークに応じて、メディエーション パートナーの同意を処理する必要があります。Google は IAB Consent Framework をサポートしていますが、独自のカスタム同意ソリューションを利用することもできます。以下に、これらの各オプションによるメディエーションの処理方法の詳細を示します。 同意取得ソリューションの詳細
IAB 同意フレームワークとメディエーション
UMP SDK も Mobile Ads SDK も、同意情報をメディエーション パートナーに転送しません。IAB ソリューションを使用する際は、UMP SDK が同意ステータス情報をローカル ストレージに書き込むため、各メディエーション パートナーの SDK が適切なキーを読み取る必要があります。各第三者ネットワークが IAB ソリューションに対応しているかどうかは、各ネットワークに問い合わせて確認してください。
カスタム同意ソリューションとメディエーション
カスタムの同意ソリューションを使用する場合は、アプリの同意ステータスをサードパーティの SDK に通知していただく必要があります。同意の情報を関係する第三者に渡す方法については、実装の詳細について、各メディエーション パートナーの統合ガイドをご覧ください。
Google Mobile Ads SDK に同意を転送する
ここで示すコードは、Google Mobile Ads SDK のどのバージョンでも使用できます。また、同意の取得に Consent SDK を使ったかどうかにかかわらず使用できます。
Google Mobile Ads SDK のデフォルトの動作では、パーソナライズド広告が配信されます。
パーソナライズされていない広告の配信に限ってユーザーが同意した場合には、AdRequest
オブジェクトを設定し、パーソナライズされていない広告だけをリクエストするように指定できます。次のコードでは、ユーザーが欧州経済領域にいるかどうかにかかわらず、パーソナライズされていない広告がリクエストされます。
Bundle extras = new Bundle();
extras.putString("npa", "1");
AdRequest request = new AdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class, extras)
.build();
現在のところ、パーソナライズされていない広告をリクエストした場合、その広告リクエストの URL には &npa=1
が含まれます。ただし、この情報は Google Mobile Ads SDK に関する内部の実装情報であり、変更される可能性があります。