借助 fetchAndJoinCustomAudience
API,买家可以利用其设备端存在的合作伙伴 MMP 或 SSP 来委托加入自定义受众群体。
概览
大致工作原理是,设备端调用方(无论是 MMP SDK 还是 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 端解析,请参阅设计提案以加入自定义受众群体委托。
测试
在客户端代码中实现了 Fetch 调用并在 DSP 端设置了端点以返回自定义受众群体数据后,您就可以测试加入自定义受众群体的委托。在运行应用之前,您需要运行以下命令打开界面以启用 Privacy Sandbox:
adb shell am start -n com.google.android.adservices.api/com.android.adservices.ui.settings.activities.AdServicesSettingsMainActivity
界面弹出后,请务必切换启用 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 成功进行调用了。
我们已将提取调用添加到 GitHub 上 Privacy Sandbox 示例仓库的开发者预览版分支中,您可以将其作为此流程的示例进行参阅。