Skip to content

Surface winning-bid economics on the original (GAM) API - #1035

Merged
mdanylov-sigma merged 1 commit into
masterfrom
feature/original-api-winning-bid-economics
Oct 28, 2026
Merged

mdanylov-sigma merged 1 commit into
masterfrom
feature/original-api-winning-bid-economics

Conversation

@mdanylov-sigma

Copy link
Copy Markdown
Collaborator

Android counterpart of prebid/prebid-mobile-ios#1321.

Summary

On the original (GAM) API, Prebid exposes only the bucketed hb_pb keyword. This adds a way to read the exact economics of the bid whose targeting was attached, without switching to the Rendering API or running a second auction. Purely additive: no existing public API changes.

  • BidInfo: new getters, set in BidInfo.create() from the bid response:

    • getPrice(): the bid's exact net price (ORTB Bid.price), as a Double.
    • getCurrency(): the response's cur, forwarded as sent. null when the response omits it; the SDK does not substitute the ORTB default.
    • getCreativeId(): the creative id (crid).
    • getAdId(): the ad id (adid).
    • getRequestId(): the ORTB BidResponse.id, the per-request UUID the SDK generates. It's response-level.

    getPrice(), getCurrency(), getCreativeId() and getAdId() describe the bid whose targeting was attached to the ad object, and are null unless a bid was designated. A null price does not mean a zero-price win. When isTopBidFiltered() is true, they describe the promoted cached runner-up.

  • AdUnit.fetchDemandBidInfo(Object adObject, OnFetchDemandResult listener): like fetchDemand(adObject, listener), it applies the targeting keywords to adObject, but returns the full BidInfo. PrebidAdUnit already returns a BidInfo, so its users get the new fields without a new method.

  • Bid.hasPrice(): whether the bid JSON had a numeric price. Bid.getPrice() is unchanged and still returns 0 for a missing price.

Notes for reviewers

  • Same names and semantics as the iOS PR after its latest review round: price rather than cpm, requestId rather than auctionId, and no "USD" fallback. The iOS PR is still in review; if its API changes again, I'll update this one to match.
  • Why a new method name instead of a fetchDemand overload: next to fetchDemand(Object, OnCompleteListener), an overload fetchDemand(Object, OnFetchDemandResult) makes existing calls such as fetchDemand(adObject, resultCode -> ...) fail with "reference to fetchDemand is ambiguous", because an implicitly typed lambda fits both interfaces (checked with javac). It would also break PrebidAdUnit, which passes an OnCompleteListenerImpl, a class that implements both interfaces.
  • Unlike iOS, fetchDemand(adObject, OnCompleteListener) does not forward to the new method. On iOS that kept the main-queue dispatch in one place; on Android it would add BidInfo.create()'s native caching to every existing NativeAdUnit call.
  • Price precision: org.json parses price as a double, so 3.14 comes back as exactly 3.14. The Float narrowing the iOS PR had to avoid does not exist here.
  • BidResponse reads a missing cur or id as "". BidInfo reports both as null, matching iOS. BidResponse.getCur() and getId() are unchanged.
  • On NativeAdUnit, fetchDemandBidInfo caches the winning bid twice: once in NativeAdUnit's bid listener and once in BidInfo.create(). The ad object ends up with the second cache id, which is the one BidInfo.getNativeCacheId() reports. The existing fetchDemand(OnFetchDemandResult) already caches twice the same way; I left that as is.
  • Docs: not updated yet. I'll add the new getters and method to the Android original API docs on prebid.github.io once the API is settled.

Test plan

  • BidInfoTest: 7 new tests, parsing a response from JSON text with distinct crid, adid and response id. Exact 3.14 price; "EUR" forwarded as sent; missing cur gives null, not ""; missing price gives null, not 0.0; a response with bids but no designated winner gives null bid fields and the response's request id; a promoted runner-up (filterOutUncachedBids) reports its own price 0.10; no response gives all null.
  • AdUnitTest (new): fetchDemandBidInfo passes the ad object through and returns the economics on success, returns the result code without economics on error, saves the BidInfo native cache id to a NativeAdUnit ad object, and does nothing with a null listener.
  • With BidInfo.create() mutated (price read without hasPrice(), raw cur, crid and adid swapped), 4 of the new tests fail, one for each mutation.
  • :PrebidMobile-core:testDebugUnitTest: 1469 tests, 1 failure: MraidInternalBrowserActionTest.handleInternalBrowserActionFollowUrlSuccessAndIsMraid_StartActionViewActivity, which also fails on master (it expects no intent flags in debug builds, but the debug unit-test build gets FLAG_ACTIVITY_NEW_TASK).
  • :PrebidMobile-admobAdapters:testDebugUnitTest: 54 tests, 0 failures. :PrebidMobile-maxAdapters:testDebugUnitTest: 122 tests, 0 failures.

🤖 Generated with Claude Code

On the original API, Prebid exposes only the bucketed hb_pb keyword.
BidInfo now also carries the exact price, currency, creative id and ad
id of the bid whose targeting was attached, and the response-level
request id. The new AdUnit.fetchDemandBidInfo(adObject, listener)
applies the targeting keywords to the ad object like
fetchDemand(adObject, listener), but returns the full BidInfo.

Bid.hasPrice() tells a missing price apart from 0, so
BidInfo.getPrice() is null rather than 0.0 when the bid has no price.
BidResponse reads a missing cur or id as "", and BidInfo reports both
as null: the SDK forwards cur as sent and does not apply the ORTB
default.

Android counterpart of prebid/prebid-mobile-ios#1321.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with follow up for 4.0
prebid/prebid-mobile-ios#1423

@mdanylov-sigma
mdanylov-sigma merged commit d862cc9 into master Oct 28, 2026
12 checks passed
@mdanylov-sigma
mdanylov-sigma deleted the feature/original-api-winning-bid-economics branch October 28, 2026 20:59
mdanylov-sigma added a commit that referenced this pull request Nov 14, 2026
- AdUnit kept the previous response until the next network callback, so a
  fetch that failed validation (no network, empty account id) returned the
  earlier response's keywords, price and request id with the failure code.
  fetchDemand now clears it first.
- BidInfo.getRequestId documented the id as set whenever a response was
  received, but NO_BIDS and NO_CACHED_BIDS are reported without the
  response, including a parsed one that filterOutUncachedBids emptied. The
  doc now states it is set for SUCCESS and null otherwise.

Follow-up to #1035. The native double cache save this branch also fixed
landed on master with #1047.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mdanylov-sigma added a commit that referenced this pull request Nov 30, 2026
- AdUnit kept the previous response until the next network callback, so a
  fetch that failed validation (no network, empty account id) returned the
  earlier response's keywords, price and request id with the failure code.
  fetchDemand now clears it first.
- BidInfo.getRequestId documented the id as set whenever a response was
  received, but NO_BIDS and NO_CACHED_BIDS are reported without the
  response, including a parsed one that filterOutUncachedBids emptied. The
  doc now states it is set for SUCCESS and null otherwise.

Follow-up to #1035. The native double cache save this branch also fixed
landed on master with #1047.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mdanylov-sigma added a commit that referenced this pull request Nov 30, 2026
- AdUnit kept the previous response until the next network callback, so a
  fetch that failed validation (no network, empty account id) returned the
  earlier response's keywords, price and request id with the failure code.
  fetchDemand now clears it first.
- BidInfo.getRequestId documented the id as set whenever a response was
  received, but NO_BIDS and NO_CACHED_BIDS are reported without the
  response, including a parsed one that filterOutUncachedBids emptied. The
  doc now states it is set for SUCCESS and null otherwise.

Follow-up to #1035. The native double cache save this branch also fixed
landed on master with #1047.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants