android / privacy-sandbox-samples

Apache License 2.0
130 stars 52 forks source link

Ad Selection does not return renderUri or return empty renderUri #86

Closed pm-vishal-chougule closed 6 months ago

pm-vishal-chougule commented 10 months ago

I have created a custom audience and registered it custom audience manager through the APIs mentioned below: https://developer.android.com/design-for-safety/privacy-sandbox/guides/protected-audience?version=beta#handle-joincustomaudience() I am able to join the custom audience successfully as I am receiving onResult() callback. After that, I tried out the Protected Audience Ad selection API but it is always returning empty renderUri. by following https://developer.android.com/design-for-safety/privacy-sandbox/guides/protected-audience?version=beta#run-ad I tried couple approaches by setting up

  1. render url in ad object inside app code with joining custom audience
  2. and also explicitly providing ad object with render URL in the generateBid() function.

Can anyone help me resolve this issue? Note: I am using the latest protected audience APIs and preview versions.

cshmerling commented 10 months ago

Usually this means something is stopping the auction from actually running- in my experience it means the device is not in the right state with the various permissions required/device configuration.

Can you confirm that you ran all the commands from the README:

adb shell device_config put adservices ppapi_app_allow_list \"*\"
adb shell device_config put adservices ppapi_app_signature_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 fledge_js_isolate_enforce_max_heap_size false
adb shell device_config put adservices global_kill_switch false
adb shell setprop debug.adservices.disable_fledge_enrollment_check true
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 fledge_auction_server_kill_switch false
adb shell device_config put adservices fledge_fetch_custom_audience_enabled true

And toggled the setting after running

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

(I suspect it might be the last command that is missing, it seems that it isn't in the README)

pm-vishal-chougule commented 10 months ago

thanks for the update, let me try this at my end.

pm-vishal-chougule commented 9 months ago

Hi @cshmerling , I tried all the recommended steps and also disabling app "Use Remote Overrides", ad selection works but not able to get renderUrl. Is anyone able to get renderUrl after running the ad selection API. Is there any other process for the same to work this feature end to end?

cshmerling commented 9 months ago

In that case, I suspect what might be happening is that the custom audience or ads are getting filtered due to some issue, so no valid bids/winner is returned. This can be due to a few things, mostly related to the bidding logic having issues or some of the validation that is run on a custom audience.

Can you enable verbose logging with

adb shell setprop log.tag.adservices.fledge VERBOSE

Run the auction, look at logcat for any adservices logs, and share them? (Or, you can try to read them yourself but it can be hard to find what you're looking for (= )

And for some additional information, which version of the SDK and device images are you using?

pm-vishal-chougule commented 8 months ago

Hi @cshmerling,

It is working for me now, I can get the valid renderUri in AdSelectionOutcome object. Seems like Ads is a mandatory parameter but the developer guide to join the custom audience suggest it as a optional parameter. Earlier I was not setting up Ads object with render url while joining the custom audience. Can you please confirm the same? Also even if I execute the mentioned adb commands, I was facing the below error java.lang.SecurityException: Caller is not authorized to call this API. Caller is not allowed. Package [package name] is not allowed to call the API so I tried executing this command and then it worked for me. Seems the ad service revokes/resets the access to the app randomly. Can you please check?

Thanks, Vishal

cshmerling commented 8 months ago

Ah, Ads are required for the custom audience to be considered for an auction- else there is nothing to generate a bid for. It is optional at the time of creation because there is a daily fetch that happens that allows you to update some fields (like Ads, Bidding Signal Keys) via a response from a server you own.

The device does reset its configuration periodically, which does override all the flags you set via adb. However, the command

adb shell device_config set_sync_disabled_for_tests persistent

should prevent that from happening. I thought this was included in the READMEs for this project, but it was not. Will update them with the command.

pm-vishal-chougule commented 8 months ago

Hi @cshmerling , I tried providing the ad details in generateBid() function of BiddingLogic js and providing the similar ad details at the daily update url, but it did not work for me.

Am i missing anything here?

cshmerling commented 8 months ago

For development and testing, it's probably easiest to specify the ad list at the time of joining the custom audience, in the object you are passing to the joinCustomAudience call. The other path of relying on the daily update takes 24 hours to work, so is better suited to longer lived custom audiences as opposed to dev testing.

Can you elaborate on what you meant when you tried providing them in generateBid()? The platform will handle passing ads from stored custom audiences to your bidding logic, so I'm curious as to what you meant.

cshmerling commented 6 months ago

Closing this due to inactivity. Please re-open if you still have doubts.