Google User Messaging Platform(UMP)SDK は、プライバシーに関するユーザー設定の管理に役立つプライバシーとメッセージに関するツールです。詳しくは、プライバシーとメッセージについてをご覧ください。
メッセージ タイプを作成する
Ad Manager アカウントの [プライバシーとメッセージ] タブで、利用可能なユーザー向けメッセージの種類のいずれかを使用してユーザー向けメッセージを作成していること。UMP SDK は、プロジェクトで設定されたアド マネージャー アプリケーション ID から作成されたプライバシー メッセージを表示しようとします。
詳しくは、プライバシーとメッセージについてをご覧ください。
ユーザーの同意情報を取得する
Update() を使用して、アプリの起動ごとにユーザーの同意情報の更新をリクエストする必要があります。このリクエストは、次のことを確認します。
- 同意が必要かどうか。たとえば、同意が初めて必要になった場合や、以前の同意の決定の有効期限が切れた場合などです。
- プライバシー オプションのエントリ ポイントが必要かどうか。一部のプライバシー メッセージでは、アプリでユーザーがいつでもプライバシー オプションを変更できるようにする必要があります。
void Start()
{
    // Create a ConsentRequestParameters object.
    ConsentRequestParameters request = new ConsentRequestParameters();
    // Check the current consent information status.
    ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
    // If the error is null, the consent information state was updated.
    if (consentError != null)
    {
        // Handle the error.
        UnityEngine.Debug.LogError(consentError);
        return;
    }
}
プライバシー メッセージ フォームを読み込んで表示する
最新の同意ステータスを取得したら、LoadAndShowConsentFormIfRequired() を呼び出して、ユーザーの同意を得るために必要なフォームを読み込みます。読み込み後、フォームがすぐに表示されます。
void Start()
{
    // Create a ConsentRequestParameters object.
    ConsentRequestParameters request = new ConsentRequestParameters();
    // Check the current consent information status.
    ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
    if (consentError != null)
    {
        // Handle the error.
        UnityEngine.Debug.LogError(consentError);
        return;
    }
    // If the error is null, the consent information state was updated.
    // You are now ready to check if a form is available.
    ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
    {
        if (formError != null)
        {
            // Consent gathering failed.
            UnityEngine.Debug.LogError(consentError);
            return;
        }
        // Consent has been gathered.
    });
}
プライバシー オプション
一部のプライバシー メッセージ フォームは、パブリッシャーがレンダリングしたプライバシー オプションのエントリ ポイントから表示され、ユーザーはいつでもプライバシー オプションを管理できます。プライバシー オプションのエントリ ポイントでユーザーに表示されるメッセージについて詳しくは、利用可能なユーザー メッセージ タイプをご覧ください。
プライバシー オプションのエントリ ポイントを実装するには、次の手順を行います。
- Update()を呼び出した後、- PrivacyOptionsRequirementStatusをチェックして、プライバシー オプションのエントリ ポイントが必要かどうかを判断します。
- 必要に応じて、プライバシー オプションのエントリ ポイントとして機能する、可視で操作可能な UI 要素をアプリに追加します。プライバシー エントリ ポイントが不要な場合は、UI 要素が表示されず、操作できないように構成します。
- ShowPrivacyOptionsForm()を使用してプライバシー オプション フォームを表示します。
次のコード例は、これらの手順を示しています。
[SerializeField, Tooltip("Button to show the privacy options form.")]
private Button _privacyButton;
private void Start()
{
  // Enable the privacy settings button.
  if (_privacyButton != null)
  {
      _privacyButton.onClick.AddListener(UpdatePrivacyButton);
      // Disable the privacy settings button by default.
      _privacyButton.interactable = false;
  }
}
/// <summary>
/// Shows the privacy options form to the user.
/// </summary>
public void ShowPrivacyOptionsForm()
{
    Debug.Log("Showing privacy options form.");
    ConsentForm.ShowPrivacyOptionsForm((FormError showError) =>
    {
        if (showError != null)
        {
            Debug.LogError("Error showing privacy options form with error: " + showError.Message);
        }
        // Enable the privacy settings button.
        UpdatePrivacyButton();
    });
}
/// <summary>
/// Updates the privacy buttons visual state based on the consent information.
/// </summary>
void UpdatePrivacyButton()
{
    if (_privacyButton != null)
    {
        _privacyButton.interactable =
            ConsentInformation.PrivacyOptionsRequirementStatus ==
                PrivacyOptionsRequirementStatus.Required;
    }
}
ユーザーの同意を得て広告をリクエストする
広告をリクエストする前に、
CanRequestAds() を使用してユーザーの同意を得ているかどうかを確認します。
同意を取得しながら広告をリクエストできるかどうかを確認する場所は次のとおりです。
- UMP SDK が現在のセッションで同意を収集した後。
- Update()を呼び出した直後。UMP SDK は、前のアプリ セッションで同意を取得している可能性があります。
同意取得プロセス中にエラーが発生した場合は、広告をリクエストできるかどうかを確認します。UMP SDK は、前回のアプリ セッションの同意ステータスを使用します。
void Start()
{
    // Create a ConsentRequestParameters object.
    ConsentRequestParameters request = new ConsentRequestParameters();
    // Check the current consent information status.
    ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
    if (consentError != null)
    {
        // Handle the error.
        UnityEngine.Debug.LogError(consentError);
        return;
    }
    // If the error is null, the consent information state was updated.
    // You are now ready to check if a form is available.
    ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
    {
        if (formError != null)
        {
            // Consent gathering failed.
            UnityEngine.Debug.LogError(consentError);
            return;
        }
        // Consent has been gathered.
        if (ConsentInformation.CanRequestAds())
        {
            MobileAds.Initialize((InitializationStatus initstatus) =>
            {
              // TODO: Request an ad.
            });
        }
    });
    
}
テスト
開発中のアプリで統合をテストする場合は、次の手順に沿ってプログラムでテストデバイスを登録します。アプリをリリースする前に、テストデバイス ID を設定するコードを必ず削除してください。
- Update()までお電話ください。
- ログ出力で次のようなメッセージを確認します。ここには、デバイス ID とテストデバイスとしてデバイスを追加する方法が示されています。 - Android- Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.- iOS- <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
- テストデバイスの ID をクリップボードにコピーします。 
- コードを変更して - DebugGeography.TestDeviceHashedIdsを呼び出し、テストデバイス ID のリストを渡します。- void Start() { var debugSettings = new ConsentDebugSettings { TestDeviceHashedIds = new List<string> { "TEST-DEVICE-HASHED-ID" } }; // Create a ConsentRequestParameters object. ConsentRequestParameters request = new ConsentRequestParameters { ConsentDebugSettings = debugSettings, }; // Check the current consent information status. ConsentInformation.Update(request, OnConsentInfoUpdated); }
地域を強制的に適用する
UMP SDK では、DebugGeography を使用して、デバイスが EEA や英国などのさまざまな地域にあるかのようにアプリの動作をテストできます。デバッグ設定はテスト用デバイスでのみ機能します。
void Start()
{
    var debugSettings = new ConsentDebugSettings
    {
        // Geography appears as in EEA for debug devices.
        DebugGeography = DebugGeography.EEA,
        TestDeviceHashedIds = new List<string>
        {
            "TEST-DEVICE-HASHED-ID"
        }
    };
    // Create a ConsentRequestParameters object.
    ConsentRequestParameters request = new ConsentRequestParameters
    {
        ConsentDebugSettings = debugSettings,
    };
    // Check the current consent information status.
    ConsentInformation.Update(request, OnConsentInfoUpdated);
}
同意ステータスをリセットする
UMP SDK でアプリをテストする際、ユーザーの初回インストール エクスペリエンスをシミュレーションできるように、SDK の状態をリセットすると便利な場合があります。SDK には、これを行う Reset() メソッドが用意されています。
ConsentInformation.Reset();
GitHub の例
このページで説明する UMP SDK 統合例の全文については、HelloWorld をご覧ください。