Skip to content

Bid selector for winner override - #964

Draft
mdanylov-sigma wants to merge 2 commits into
masterfrom
feature/950-bid-selector
Draft

mdanylov-sigma wants to merge 2 commits into
masterfrom
feature/950-bid-selector

Conversation

@mdanylov-sigma

@mdanylov-sigma mdanylov-sigma commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements the bid selector from Part I of the API proposal linked from prebid/prebid-mobile-ios#950 (part 2 of the issue: let the publisher override the SDK's winner). It's the Android twin of prebid/prebid-mobile-ios#1276 and has the same public shape.

The selector is a plugin. Register it once and it applies to every ad unit of the Original, Rendering and Mediation APIs:

public class HighestPriceSelector implements PrebidBidSelecting {

    private final PrebidPluginInfo pluginInfo = new PrebidPluginInfo("com.example.highest-price", "1.0");

    @Override
    public PrebidPluginInfo getPluginInfo() {
        return pluginInfo;
    }

    @Override
    public Bid selectBid(List<Bid> bids, BidSelectionContext context) {
        Bid best = null;
        for (Bid bid : bids) {
            if (best == null || bid.getPrice() > best.getPrice()) {
                best = bid;
            }
        }
        return best;
    }
}

PrebidMobile.registerPlugin(new HighestPriceSelector(), PluginCapability.BID_SELECTOR);

Workflow (proposal 1.4.1)

With no selector registered, nothing changes. With one registered, BidLoader runs the selection right after parsing the response:

  1. Prepares the eligible bids. With setFilterOutUncachedBids(true), the Original API offers only bids with a Prebid Cache entry (they are already filtered while parsing). The Rendering API gets no new cache requirement.
  2. Calls selectBid(bids, context) once, on the main thread (the network task delivers the response there). context gives the ad unit's config ID and ad formats, since one selector now serves all ad units.
  3. Validates the result by identity. null, or an object that isn't one of the given bids (logged), ends the auction with no winner: NO_BIDS, no keywords, no rendering, no winner tracking. There is no fallback to the server's winner or to the cached-bid promotion.
  4. Builds targeting from the selected bid alone. It keeps the bid's own keys and fills in the generic keys (hb_pb, hb_bidder, hb_size, hb_format, hb_deal, hb_cache_id, hb_uuid, hb_cache_host, hb_cache_path, hb_env) from its bidder-specific keys. The bidder code comes from the bid's own hb_bidder_<code>, so aliases work, and keys that Prebid Server truncated are matched by prefix. If a key could match more than one entry, the targeting is invalid rather than guessed. Missing optional keys stay missing, and no other bid's keys are merged. The SDK writes the result to the selected bid's targeting too, so the code that reads the winning bid directly (GAM event handlers, win notifier) sees the same set.
  5. Validates the targeting. If an ad server integration (Original API, GAM Rendering, Mediation) can't get hb_pb and hb_bidder (plus hb_cache_id when the cache is used, as for the default winner), the auction ends with the new ResultCode.INVALID_TARGETING / FetchDemandResult.INVALID_TARGETING and nothing is attached. Standalone Rendering ad units render the bid's markup, so they don't need the keys.
  6. Commits and completes once. A "no winner" outcome reaches every API as an error, so the Original API also clears the previous refresh's keywords, as for any failed fetch.

Changes since the first version of this PR

  • Rebased onto master, 46 commits ahead (conflicts in the Mediation ad units, BaseInterstitialAdUnit and BidResponse). The selector now uses the plugin registry from Add the plugin registry and PrebidMobile.registerPlugin (plugin system, step 1) #1054.
  • setBidSelector on AdUnitConfiguration, PrebidRequest, BannerView, the interstitial/rewarded ad units and the Mediation ad units is removed in favour of PrebidMobile.registerPlugin(selector, PluginCapability.BID_SELECTOR) (proposal 1.4.2).
  • The selection moved out of the BidResponse constructor into BidLoader, after the response is parsed and filtered. hasBidSelectorRejectedAllBids() and the per-ad-unit NO_BIDS checks are gone: a rejection is a load error.
  • Losing bids' keys are no longer merged. Before, only hb_pb/hb_bidder/hb_cache_id were stripped from them, so a runner-up pick still left the server winner's other generic keys in the targeting.
  • The hb_* key literals (BidResponse, WinNotifier, AdUnit) now come from one restricted TargetingKey class.

Public API

  • PrebidBidSelecting: getPluginInfo(), selectBid(List<Bid>, BidSelectionContext), default onRegister() / onUnregister().
  • BidSelectionContext: getConfigId(), getAdFormats().
  • PluginCapability.BID_SELECTOR: at most one selector is registered. A second registration is ignored with a warning.
  • ResultCode.INVALID_TARGETING, FetchDemandResult.INVALID_TARGETING.

Open points for review

  • The proposal leaves the API shape (1.4.2) open, and multi-impression support still has to be designed. BidSelectionContext is where per-impression data, such as an impression ID, would go later.
  • Goal 1.2 also asks to deprecate the current levers in favour of the new API. This PR deprecates nothing yet: what replaces them should be agreed first.

Test plan

  • BidSelectorTest (23): registration and the one-selector limit, default path unchanged, selection, main thread, null and foreign results, eligibility with and without setFilterOutUncachedBids, targeting validation (including hb_cache_id when the cache is used), standalone rendering ad units, and the key mapping (aliases, truncation, other key families, ambiguity).
  • AdUnitConfigurationTest: the copy constructor keeps the new rendersWithoutAdServer flag.
  • Unit tests on CI

🤖 Generated with Claude Code

@mdanylov-sigma

mdanylov-sigma commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

I put together a full proposal: problem statement, API shape (shown as pseudocode), design rationale for each non-obvious decision, alternatives considered, and open questions for maintainers. Posting it for review before this PR goes further.

Full doc, Part I.

mdanylov-sigma and others added 2 commits November 11, 2026 21:54
Aligns the bid selector with Part I of the API proposal linked from
prebid/prebid-mobile-ios#950, the same way as prebid/prebid-mobile-ios#1276:

- The selector is a plugin: PrebidBidSelecting gains getPluginInfo(),
  selectBid(bids, context) and default onRegister/onUnregister, and is
  registered with PrebidMobile.registerPlugin(selector,
  PluginCapability.BID_SELECTOR). At most one is active. The per-ad-unit
  setBidSelector methods are gone.
- The selection runs in BidLoader after the response is parsed, once, on
  the main thread, over the eligible bids: with filterOutUncachedBids the
  Original API offers only cached bids. Rendering gets no new cache
  requirement.
- A null or foreign result is a load error with no winner; there is no
  fallback to the server's winner or to the cached-bid promotion.
- Targeting comes from the selected bid alone. Generic keys are filled in
  from its bidder-specific keys, resolving aliases and truncated keys; no
  other bid's keys are merged.
- If an ad server integration can't get the winner keys for the selected
  bid, the load fails with the new ResultCode/FetchDemandResult
  INVALID_TARGETING. Standalone Rendering ad units don't need the keys.
- The hb_* key literals now come from one TargetingKey class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdanylov-sigma
mdanylov-sigma force-pushed the feature/950-bid-selector branch from ecc3ca3 to b814ae7 Compare November 11, 2026 20:09

This branch has not been deployed

No deployments
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.

1 participant