SDK สำหรับ User Messaging Platform (UMP) ของ Google เป็นเครื่องมือด้านความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้เพื่อช่วยคุณจัดการตัวเลือกความเป็นส่วนตัว ดูข้อมูลเพิ่มเติมได้ที่ เกี่ยวกับความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้
สร้างประเภทข้อความ
สร้างข้อความสำหรับผู้ใช้ด้วยประเภทข้อความสำหรับผู้ใช้ที่ใช้ได้ ในแท็บความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้ของบัญชี AdMob UMP SDK พยายามแสดง ข้อความแจ้งเรื่องความเป็นส่วนตัวที่สร้างจากรหัสแอปพลิเคชัน AdMob ที่ตั้งค่าไว้ในโปรเจ็กต์
ดูรายละเอียดเพิ่มเติมได้ที่ เกี่ยวกับความเป็นส่วนตัวและการรับส่งข้อความ
รับข้อมูลความยินยอมของผู้ใช้
คุณควรร้องขอการอัปเดตข้อมูลความยินยอมของผู้ใช้ทุกครั้งที่เปิดแอปโดยใช้ 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.
            });
        }
    });
    
}
การทดสอบ
หากต้องการทดสอบการผสานรวมในแอปขณะพัฒนา ให้ทำตามขั้นตอนเหล่านี้เพื่อลงทะเบียนอุปกรณ์ทดสอบโดยอัตโนมัติ อย่าลืมนำโค้ดที่ตั้งค่ารหัสอุปกรณ์ทดสอบเหล่านี้ออกก่อนเผยแพร่แอป
- โทรมาที่ Update()
- ตรวจสอบเอาต์พุตของบันทึกเพื่อหาข้อความที่คล้ายกับตัวอย่างต่อไปนี้ ซึ่ง แสดงรหัสอุปกรณ์และวิธีเพิ่มรหัสเป็นอุปกรณ์ทดสอบ - 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]
- คัดลอกรหัสอุปกรณ์ทดสอบไปยังคลิปบอร์ด 
- แก้ไขโค้ดเพื่อเรียกใช้ - DebugGeography.TestDeviceHashedIdsและส่ง รายการรหัสอุปกรณ์ทดสอบ- 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 มีวิธีทดสอบลักษณะการทำงานของแอปเสมือนว่าอุปกรณ์
อยู่ในภูมิภาคต่างๆ เช่น EEA หรือสหราชอาณาจักร โดยใช้
DebugGeography โปรดทราบว่าการตั้งค่าการแก้ไขข้อบกพร่องจะใช้ได้เฉพาะในอุปกรณ์ทดสอบเท่านั้น
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