使ってみる

プラットフォームを選択: Android iOS

Google User Messaging Platform(UMP)SDK は、プライバシー設定の管理に役立つプライバシーとメッセージのツールです。詳しくは、 プライバシーとメッセージについてをご覧ください。 UMP SDK を使用した IMA の実装例については、UMP サンプル アプリをご覧ください。

前提条件

  • Android API レベル 21 以降

メッセージ タイプを作成する

Ad Manager アカウントの [Privacy & messaging] タブで、[Available user message types] を使用してユーザー メッセージを作成します。UMP SDK は、プロジェクトで設定された Interactive Media Ads アプリケーション ID から作成されたプライバシー メッセージを表示しようとします。

詳しくは、 プライバシーとメッセージについてをご覧ください。

Gradle でインストールする

Google User Messaging Platform SDK の依存関係をモジュールの アプリレベルの Gradle ファイル(通常は app/build.gradle)に追加します。

dependencies {
  implementation("com.google.android.ump:user-messaging-platform:4.0.0")
}

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

アプリケーション ID を追加する

アプリケーション ID は アド マネージャーの管理画面で確認できます。次のコード スニペットを使用して、ID を AndroidManifest.xml に追加します。

<manifest>
  <application>
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
  </application>
</manifest>

ユーザーの同意情報を取得する手順は次のとおりです。

ConsentInformation のインスタンスを宣言します。

Java

private final ConsentInformation consentInformation;

Kotlin

private lateinit val consentInformation: ConsentInformation

ConsentInformation インスタンスを初期化します。

Java

consentInformation = UserMessagingPlatform.getConsentInformation(context);

Kotlin

consentInformation = UserMessagingPlatform.getConsentInformation(context)

フォームを読み込む前に requestConsentInfoUpdate() を使用して、アプリの起動ごとにユーザーの同意情報の更新をリクエストする必要があります。このリクエストでは、次の点が確認されます。

  • 同意が必要かどうか 。たとえば、初回の場合や、以前の同意の決定が期限切れになった場合などです。
  • プライバシー オプションのエントリ ポイントが必要かどうか 。一部のプライバシー メッセージでは、ユーザーがいつでもプライバシー オプションを変更できるようにする必要があります。

Java


// Requesting an update to consent information should be called on every app launch.
consentInformation.requestConsentInfoUpdate(
    activity,
    params,
    () -> // Called when consent information is successfully updated.
    requestConsentError -> // Called when there's an error updating consent information.

Kotlin


// Requesting an update to consent information should be called on every app launch.
consentInformation.requestConsentInfoUpdate(
  activity,
  params,
  {
    // Called when consent information is successfully updated.
  },
  { requestConsentError -> // Called when there's an error updating consent information.

}, )

プライバシー メッセージ フォームを読み込んで表示する

最新の同意ステータスを受け取ったら、 loadAndShowConsentFormIfRequired() を呼び出して、ユーザーの同意の収集に必要なフォームを読み込みます。読み込み後、フォームがすぐに表示されます。

Java


UserMessagingPlatform.loadAndShowConsentFormIfRequired(
    activity,
    formError -> {
      // Consent gathering process is complete.
    });

Kotlin


UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity) { formError ->
  // Consent gathering is complete.
}

プライバシー オプション

一部のプライバシー メッセージ フォームは、パブリッシャー レンダリングのプライバシー オプションのエントリ ポイントから表示され、ユーザーはいつでもプライバシー オプションを管理できます。 プライバシー オプションのエントリ ポイントでユーザーに表示されるメッセージについて詳しくは、利用可能なユーザー メッセージ タイプをご覧ください。

プライバシー オプションのエントリ ポイントが必要かどうかを確認する

requestConsentInfoUpdate() を呼び出したら、 getPrivacyOptionsRequirementStatus() を確認して、アプリにプライバシー オプションのエントリ ポイントが必要かどうかを判断します。エントリ ポイントが必要な場合は、プライバシー オプション フォームを表示する、表示可能で操作可能な UI 要素をアプリに追加します。プライバシー エントリ ポイントが不要な場合は、UI 要素が表示されず、操作できないように設定します。

Java


/** Helper function to determine if a privacy options entry point is required. */
public boolean isPrivacyOptionsRequired() {
  return consentInformation.getPrivacyOptionsRequirementStatus()
      == PrivacyOptionsRequirementStatus.REQUIRED;
}

Kotlin


/** Helper variable to determine if the privacy options form is required. */
val isPrivacyOptionsRequired: Boolean
  get() =
    consentInformation.privacyOptionsRequirementStatus ==
      ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED

プライバシー オプションの要件ステータスの完全なリストについては、 ConsentInformation.PrivacyOptionsRequirementStatus をご覧ください。

プライバシー オプション フォームを表示する

ユーザーが要素を操作すると、プライバシー オプション フォームが表示されます。

Java


UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener);

Kotlin


UserMessagingPlatform.showPrivacyOptionsForm(activity, onConsentFormDismissedListener)

ユーザーの同意を得て広告をリクエストする

広告をリクエストする前に、 canRequestAds() を使用して、ユーザーから同意を得ているかどうかを 確認します。

Java

consentInformation.canRequestAds();

Kotlin

consentInformation.canRequestAds()

同意を収集しながら広告をリクエストできるかどうかを確認する場所は次のとおりです。

  • UMP SDK が現在のセッションで同意を収集した後。
  • requestConsentInfoUpdate() を呼び出した直後。UMP SDK は、以前のアプリ セッションで同意を得ている可能性があります。

同意の収集プロセス中にエラーが発生した場合は、広告をリクエストできるかどうかを確認します。UMP SDK は、以前のアプリ セッションの同意ステータスを使用します。

冗長な広告リクエスト作業を回避する

同意を収集した後、 requestConsentInfoUpdate() を呼び出した後に canRequestAds() を確認する場合は、両方のチェックで true が返される可能性のある冗長な広告リクエストを回避するロジックを実装してください。たとえば、ブール変数を使用します。

テスト

開発中のアプリで統合をテストする場合は、次の手順に沿ってプログラムでテストデバイスを登録します。アプリをリリースする前に、テストデバイス ID を設定するコードを必ず削除してください。

  1. requestConsentInfoUpdate() を呼び出します。
  2. ログ出力で次のようなメッセージを確認します。ここには、デバイス ID とテストデバイスとしてデバイスを追加する方法が示されています。

    Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  3. テストデバイスの ID をクリップボードにコピーします。

  4. コードに変更を加え、 ConsentDebugSettings.Builder().addTestDeviceHashedId() を呼び出し、 テストデバイスのデバイス ID のリストに渡します。

    Java

    ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
        .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)
        .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,
        // ...
    )
    

地域を強制的に適用する

DebugGeographyデバッグ設定はテスト用デバイスでのみ機能します。

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

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

Java

consentInformation.reset();

Kotlin

consentInformation.reset()

GitHub の例

このページで説明する UMP SDK 統合例の全文については、 UmpExample をご覧ください。