Uỷ quyền đối tượng tuỳ chỉnh bằng Protected Audience

API fetchAndJoinCustomAudience cho phép người mua uỷ quyền tham gia một đối tượng tuỳ chỉnh bằng cách tận dụng sự hiện diện trên thiết bị của MMP hoặc SSP của đối tác.

Tổng quan

Tổng quan chung về cách hoạt động của tính năng này là phương thức gọi trên thiết bị (cho dù là MMP hay SDK SSP) tạo một fetchAndJoinCustomAudienceRequest giống như sau:

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();

Một lưu ý quan trọng về tất cả thông số không bắt buộc là nếu chúng được đặt bên trong yêu cầu tìm nạp, thì dữ liệu của các tham số đó không thể bị ghi đè bằng nội dung trả về từ Người mua, nhờ đó, phương thức gọi trên thiết bị có thêm quyền kiểm soát đối với những đối tượng tuỳ chỉnh đang được duy trì.

fetchUri phải trỏ đến điểm cuối của máy chủ do Người mua điều hành. Điểm cuối này sẽ trả về đối tượng JSON tuỳ chỉnh Đối tượng tuỳ chỉnh khớp với định dạng thấy ở đây:

//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
      }
    }
  ]
}

Bạn có thể tìm thêm thông tin về cách giải quyết vấn đề này ở phía API trong Đề xuất thiết kế dành cho việc tham gia uỷ quyền CA.

Kiểm thử

Sau khi đã triển khai lệnh gọi Tìm nạp bên trong mã ứng dụng và thiết lập một điểm cuối ở phía DSP để trả về Dữ liệu đối tượng tuỳ chỉnh, bạn có thể thử nghiệm việc uỷ quyền tham gia một Đối tượng tuỳ chỉnh. Trước khi chạy ứng dụng, bạn cần chạy lệnh sau để mở giao diện người dùng và bật Hộp cát về quyền riêng tư:

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

Khi giao diện người dùng bật lên, hãy nhớ bật/tắt để bật Hộp cát về quyền riêng tư, sau đó chạy các lệnh ADB sau đây để hoàn tất quá trình thiết lập thiết bị cho mục đích kiểm thử:

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

Sau khi chạy các lệnh này, bạn sẽ có thể bắt đầu thực hiện thành công các lệnh gọi bằng cách sử dụng Fetch API.

Để xem ví dụ về quy trình này, chúng tôi đã thêm các lệnh gọi tìm nạp vào nhánh bản xem trước dành cho nhà phát triển của kho lưu trữ Mẫu hộp cát về quyền riêng tư trên GitHub.