開始使用

根據 Google 歐盟地區使用者同意聲明 政策,您必須 向歐洲經濟區境內的使用者揭露特定資訊 取得使用 Cookie 或其他本機儲存空間的同意聲明。 並根據法律要求使用個人資料 (如 AdID) 放送廣告。 本政策是配合《歐盟地區電子通訊隱私指令》和 《一般資料保護規則》(GDPR) 規定)。

為了協助發布商根據這項政策履行自身職責,Google 提供 User Messaging Platform (UMP) SDK。UMP SDK 已更新,現已支援 符合最新的 IAB 標準這些設定現在都很方便 處理 AdMob 隱私權與傳送訊息

必要條件

建立訊息類型

使用以下其中一則文字建立使用者訊息: 可用的使用者訊息類型 中,隱私權與訊息分頁 AdMob 。 讓他們使用服務帳戶UMP SDK 會嘗試顯示 透過應用程式 ID AdMob 建立的使用者訊息 您在專案中設定的內容如果未設定應用程式訊息,則 SDK 傳回錯誤。

詳情請參閱 關於隱私權與訊息

新增應用程式 ID

您可以在「 AdMob UI: 將身分證件新增至 替換為下列程式碼片段:

在每個應用程式中,應要求使用者更新同意聲明資訊 使用 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 (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.
}

視需要載入並顯示同意聲明表單

收到最新的同意聲明狀態後,請致電 LoadAndShowConsentFormIfRequired()ConsentForm 類別,載入同意聲明表單。如果 SDK 載入表單並立即顯示 Action<FormError> callback 關閉表單後,系統就會呼叫 已完成。如果不需要同意聲明, Action<FormError> callback 將立即

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

您需要在使用者做出選擇或關閉廣告後執行任何動作 請將該邏輯放在 Action<FormError> callback中 。

請求廣告

在應用程式中請求廣告前,請確認您已取得同意聲明 透過 CanRequestAds()存取。這裡共有兩個 收集同意聲明時的檢查地點:

  1. 從目前的工作階段中收集到同意聲明後,
  2. 呼叫 Update()後立即執行。 您可能已在上一個工作階段取得同意聲明。一段延遲時間 最佳做法,建議您不要等待回呼完成 在應用程式啟動後盡快載入廣告。

如果在收集同意聲明的過程中發生錯誤, 請求廣告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.
            });
        }
    });
    
}

隱私權選項

部分同意聲明表單會要求使用者隨時修改同意聲明。滿足 以下的步驟,視需要導入隱私權選項按鈕。

為了達到這個目的:

  1. 實作 UI 元素,例如應用程式設定頁面中的按鈕。 觸發隱私權選項表單
  2. 完成後 LoadAndShowConsentFormIfRequired() 請查看 PrivacyOptionsRequirementStatus 會決定是否要顯示 可顯示隱私權選項表單的 UI 元素。
  3. 當使用者與 UI 元素互動時, ShowPrivacyOptionsForm() 顯示表單,方便使用者 隨時更新自己的隱私權選項。

下列範例示範如何顯示隱私權選項表單, Button

[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.
        if (_privacyButton != null)
        {
            _privacyButton.interactable =
                ConsentInformation.PrivacyOptionsRequirementStatus ==
                PrivacyOptionsRequirementStatus.Required;
        }
    });
}

測試

如要在開發過程中測試應用程式內整合功能,請按照下列步驟操作: 這些步驟以程式輔助方式註冊測試裝置。請務必移除 程式碼,在發布應用程式前設定測試裝置 ID。

  1. 呼叫 Update()
  2. 查看記錄輸出中是否有類似以下範例的訊息, 顯示您的裝置 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]
    
  3. 將測試裝置 ID 複製到剪貼簿。

  4. 修改程式碼以 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 可讓您測試應用程式行為,就像測試裝置 地址在歐洲經濟區或英國境內,並使用 the DebugGeography field on ConsentDebugSettings。請注意, 偵錯設定僅適用於測試裝置。

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 上的範例