เข้าร่วมการมอบสิทธิ์กลุ่มเป้าหมายที่กำหนดเองด้วย Protected Audience

fetchAndJoinCustomAudience API ช่วยให้ผู้ซื้อมอบสิทธิ์การเข้าร่วมกลุ่มเป้าหมายที่กำหนดเองได้โดยใช้ประโยชน์จากการแสดงตัวตนในอุปกรณ์ของ MMP หรือ SSP ของพาร์ทเนอร์

ภาพรวม

ภาพรวมทั่วไปของวิธีการทำงานคือ โปรแกรมเรียกใช้ในอุปกรณ์ (ไม่ว่าจะเป็น MMP หรือ SSP SDK) จะสร้าง fetchAndJoinCustomAudienceRequest ที่มีลักษณะดังนี้

Kotlin

/**
 * @param fetchUri The URL to retrieve the CA from.
 * (optional)@param name The name of the CA to join.
 * (optional)@param activationTime The time when the CA will activate.
 * (optional)@param expirationTime The time when the CA will expire,
    must be a time in the future otherwise this will fail
 * (optional)@param userBiddingSignals The user bidding signals used at auction.
*/

val request = FetchAndJoinCustomAudienceRequest.Builder(fetchUri)
    .setName(name)
    .setActivationTime(activationTime)
    .setExpirationTime(expirationTime)
    .setUserBiddingSignals(userBiddingSignals)
    .build()

Java

/**
 * @param fetchUri The URL to retrieve the CA from.
 * (optional)@param name The name of the CA to join.
 * (optional)@param activationTime The time when the CA will activate.
 * (optional)@param expirationTime The time when the CA will expire,
    must be a time in the future otherwise this will fail
 * (optional)@param userBiddingSignals The user bidding signals used at auction.
*/

FetchAndJoinCustomAudienceRequest request =
 new FetchAndJoinCustomAudienceRequest.Builder(fetchUri)
  .setName(name) //Optional
  .setActivationTime(activationTime) //Optional
  .setExpirationTime(expirationTime) //Optional
  .setUserBiddingSignals(userBiddingSignals) //Optional
  .build();

หมายเหตุสำคัญเกี่ยวกับพารามิเตอร์ที่ไม่บังคับทั้งหมดคือ หากตั้งค่าพารามิเตอร์ดังกล่าวไว้ภายในคำขอการดึงข้อมูล สิ่งที่ผู้ซื้อส่งคืนมาจะไม่สามารถลบล้างข้อมูลของพารามิเตอร์นั้นๆ ได้ ซึ่งทำให้ผู้โทรในอุปกรณ์สามารถควบคุมกลุ่มเป้าหมายที่กำหนดเองได้มากขึ้นด้วย

fetchUri ควรชี้ไปยังปลายทางเซิร์ฟเวอร์ที่ดำเนินการโดยผู้ซื้อ ซึ่งจะแสดงออบเจ็กต์ JSON ของกลุ่มเป้าหมายที่กำหนดเองที่ตรงกับรูปแบบที่เห็นที่นี่

//Return a 200 response with data matching the format of the following in the body
{
  "daily_update_uri": "https://js.example.com/bidding/daily",
  "bidding_logic_uri": "https://js.example.com/bidding",
  "user_bidding_signals": {
    "valid": true,
    "arbitrary": "yes"
  },
  "trusted_bidding_data": {
    "trusted_bidding_uri": "https://js.example.com/bidding/trusted",
    "trusted_bidding_keys": [
      "key1",
      "key2"
    ]
  },
  "ads": [
    {
      "render_uri": "https://js.example.com/render/fetch_and_join_ad1",
      "metadata": {
        "valid": 1
      }
    },
    {
      "render_uri": "https://js.example.com/render/fetch_and_join_ad2",
      "metadata": {
        "valid": 2
      }
    }
  ]
}

ดูข้อมูลเพิ่มเติมเกี่ยวกับวิธีแก้ไขปัญหานี้ในส่วนของ API ได้ในข้อเสนอการออกแบบเพื่อมอบสิทธิ์ CA สำหรับการเข้าร่วม

การทดสอบ

เมื่อใช้การเรียกการดึงข้อมูลภายในรหัสไคลเอ็นต์และตั้งค่าปลายทางที่ฝั่ง DSP ให้ส่งคืนข้อมูลกลุ่มเป้าหมายที่กำหนดเองแล้ว คุณจะทดสอบการมอบสิทธิ์เข้าร่วมกลุ่มเป้าหมายที่กำหนดเองได้ ก่อนเรียกใช้แอป คุณจะต้องเรียกใช้คำสั่งต่อไปนี้เพื่อเปิด UI เพื่อเปิดใช้ Privacy Sandbox

adb shell am start -n com.google.android.adservices.api/com.android.adservices.ui.settings.activities.AdServicesSettingsMainActivity

เมื่อ UI ปรากฏขึ้น ให้ตรวจสอบว่าได้สลับเพื่อเปิดใช้ Privacy Sandbox แล้ว แล้วเรียกใช้คำสั่ง ADB ต่อไปนี้เพื่อตั้งค่าอุปกรณ์สำหรับการทดสอบให้เสร็จสิ้น

adb shell device_config set_sync_disabled_for_tests persistent
adb shell device_config put adservices ppapi_app_signature_allow_list \"\*\"
adb shell device_config put adservices ppapi_app_allow_list \"\*\"
adb shell device_config put adservices adservice_system_service_enabled true
adb shell device_config put adservices adservice_enabled true
adb shell device_config put adservices adservice_enable_status true
adb shell device_config put adservices global_kill_switch false
adb shell device_config put adservices fledge_js_isolate_enforce_max_heap_size false
adb shell device_config put adservices fledge_custom_audience_service_kill_switch false
adb shell device_config put adservices fledge_select_ads_kill_switch false
adb shell device_config put adservices adid_kill_switch false
adb shell setprop debug.adservices.disable_fledge_enrollment_check true
adb shell device_config put adservices fledge_fetch_custom_audience_enabled true

เมื่อเรียกใช้คำสั่งเหล่านี้แล้ว คุณควรจะเริ่มการเรียกได้สำเร็จโดยใช้ Fetch API

หากต้องการดูตัวอย่างของขั้นตอนนี้ เราได้เพิ่มการเรียกการดึงข้อมูลในสาขาการแสดงตัวอย่างสำหรับนักพัฒนาซอฟต์แวร์ของที่เก็บ Privacy Sandbox Samples ใน GitHub สำหรับนักพัฒนาซอฟต์แวร์