フィードバックをお寄せください。Google Mobile Ads SDK の改善に役立てさせていただきます。2023 年 Google Mobile Ads SDK 年次アンケートにぜひご協力ください。アンケートの締め切りは 2023 年 5 月 5 日です。

始める

コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。

Google の EU ユーザーの同意ポリシーでは、英国および欧州経済領域(EEA)のユーザーに特定の情報を開示するとともに、Cookie またはその他のローカル ストレージを使用することを法的に義務付けられている場合に、また個人データ(AdID など)を使用して広告を配信することについて、ユーザーの同意を得る必要があります。このポリシーには、EU の e プライバシー指令と一般データ保護規則(GDPR)の要件が反映されています。

パブリッシャー様がこのポリシーで定められた義務を遂行できるよう、Google は User Messaging Platform(UMP)SDK を提供しています。UMP SDK が更新され、最新の IAB 標準をサポートするようになりました。これらの構成はすべて、 Ad Manager プライバシーとメッセージ を使って簡単に処理できます

Prerequisites

ユーザーへのメッセージの種類

ユーザー メッセージ タイプ サポートされているメッセージの一覧については、各メッセージ タイプの実装手順については、左側のナビゲーション バーをご覧ください。

Gradle を使用してインストールする

Google Mobile Ads SDK バージョン 19.8.0 以降を使用している場合、UMP SDK がバンドルに含まれています。以前のバージョンの Mobile Ads SDK を使用している場合は、次のように、アプリの build.gradle に UMP SDK を追加します。

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

アプリの build.gradle を変更したら、必ずプロジェクトを Gradle ファイルと同期してください。

次に、アド マネージャーの [モバイルアプリ] でアプリ 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">
        <!-- 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>

メッセージを表示する必要があるかどうかを判断する

フォームを読み込む前に、 requestConsentInfoUpdate() を使用して、アプリの起動ごとにユーザーの同意情報の更新をリクエストする必要があります。これにより、ユーザーがまだ同意していない場合や同意の有効期限が切れた場合に、同意を提示する必要があるかどうかを判断できます。

必要に応じてフォームを表示する際に、 consentInformationオブジェクトに保存されている情報を使用します。

アプリ起動時のステータスを確認する方法の例を次に示します。

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.

利用可能な場合はフォームを読み込む

フォームを表示する前に、利用可能なフォームがあるかどうかを判断する必要があります。利用できないフォームは、ユーザーが制限付きの広告トラッキングを有効にしているか、同意年齢に満たないタグを設定している可能性があります。

利用可能なフォームをチェックするには、先ほど作成したthe isConsentFormAvailable() method on the ConsentInformation instance を使用します。

次に、フォームを読み込むラッパー メソッドを追加します。

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.

フォームを読み込むには、 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.

必要に応じてフォームを提示します。

フォームが使用可能であることを確認して読み込みが完了したら、ConsentForm インスタンスのshow() メソッドを使用してフォームを表示します。

前述のconsentInformation オブジェクトを使用してconsent status を確認し、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 Error.
            }
        }
   );
}

Kotlin

Coming soon.

ユーザーがフォームを選択または拒否した後になんらかのアクションを行う必要がある場合は、そのロジックをフォームの入力ハンドラまたはコールバックに配置します。

テスト

地域を適用する

UMP SDK を使用すると、 the setDebugGeography method on ConsentDebugSettings.Builderを使用して、デバイスが 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

Coming soon.

DebugGeographyを使用すると、地域を次のいずれかのオプションに強制できます。

Debuggeography 説明
DEBUG_GEOGRAPHY_DISABLED デバッグ対象が無効です。
DEBUG_GEOGRAPHY_EEA デバッグデバイスの場合、地域は EEA で表示されます。
DEBUG_GEOGRAPHY_NOT_EEA デバッグ用デバイスの EEA に地域が表示されないようです。

デバッグ設定はテストデバイスでのみ機能します。エミュレータはデフォルトでテストが有効になっているため、デバイス ID リストに追加する必要はありません。

UMP SDK でアプリをテストする際、ユーザーの初回インストール エクスペリエンスをシミュレートできるように、SDK の状態をリセットすると便利な場合があります。SDK には、そのための reset() メソッドが用意されています。

Java

consentInformation.reset();

Kotlin

consentInformation.reset()

UMP SDK をプロジェクトから完全に削除する場合は、 reset() も呼び出す必要があります。