Repository navigation
Bid selector for winner override - #1276
mdanylov-sigma wants to merge 2 commits into
Conversation
|
|
||
|
|
||
| /// A publisher-supplied strategy for choosing the winning bid. See `PrebidBidSelecting`. | ||
| public var bidSelector: PrebidBidSelecting? |
There was a problem hiding this comment.
Should this feature be enabled for original ad units as well?
| /// Standard winner-marker keys (see `Bid.isWinning`). These specifically identify "the" winner, | ||
| /// so they must never be attributed to a bid that isn't the (possibly selector-chosen) winner -- | ||
| /// otherwise `targetingInfo` could still point at a different bid than `winningBid` does. | ||
| private static let winningBidMarkerKeys: Set<String> = ["hb_pb", "hb_bidder", "hb_cache_id"] |
There was a problem hiding this comment.
these markers are duplicated throughout the SDK, consider consolidating them into a single source
|
@mdanylov-sigma Is there a community approved spec or proposal describing the way SDK should provide bid selection logic? |
@YuriyVelichkoPI no, there wasn’t a community approved spec or proposal for this. The PrebidBidSelecting protocol / bidSelector design here is my own proposal for how to satisfy that ask - not something reviewed or signed off on beforehand. My fault. If this doesn’t match what the maintainers/community have in mind, let's close the PR and working out the actual design together first. |
|
Let's make PRs as draft. Then - create a shared docoment with the implementation proposal (feature specification). Once it ready and approved for we'll return back to implementation according to that spec. Because for now, without approved requirements, it's hard to review the PR. |
|
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. |
dbdf451 to
f6120d9
Compare
f6120d9 to
e78a1a8
Compare
e78a1a8 to
0471b3b
Compare
Aligns the bid selector with Part I of the API proposal linked from #950: - The selector is a plugin: PrebidBidSelecting gains pluginInfo, selectBid(from:context:) and optional onRegister/onUnregister, and is registered with Prebid.register(_:as: .bidSelector). At most one is active. The per-ad-unit bidSelector properties are gone, so the selector also covers the Original API ad units. - Eligibility first: with filterOutUncachedBids, Original API offers only cached bids. Rendering API gets no new cache requirement. - The selector is called once, on the main thread. A nil or foreign result ends the auction with no winner; there is no fallback to the server's winner, to forceSdkToChooseWinner 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 hb_pb/hb_bidder (and hb_cache_id with cache reporting) for the selected bid, the request ends with the new ResultCode.prebidDemandInvalidTargeting. Standalone Rendering ad units don't need the keys. - The hb_* key literals now come from one TargetingKey enum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
Summary
Implements the bid selector from Part I of the API proposal linked from #950 (part 2 of the issue: let the publisher override the SDK's winner).
The selector is a plugin. Register it once and it applies to every ad unit of the Original, Rendering and Mediation APIs:
Workflow (proposal 1.4.1)
With no selector registered, nothing changes. With one registered, for each auction the SDK:
filterOutUncachedBids, the Original API offers only bids with a Prebid Cache entry. The Rendering API gets no new cache requirement.selectBid(from:context:)once, on the main thread.contextgives the ad unit'sconfigIdandadFormats, since one selector now serves all ad units.nil, or an object that isn't one of the given bids (logged), ends the auction with no winner:.prebidDemandNoBids, no keywords, no rendering, no winner tracking. There is no fallback to the server's winner, toforceSdkToChooseWinner, or to the cached-bid promotion from PS bid caching failures v2: align with reviewed design doc #1327.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 ownhb_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 adds the generic keys to the selected bid'stargetingInfotoo, so the code that reads the winning bid directly (mediation interstitials, win notifier, SKOverlay) sees the same set.hb_pbandhb_bidder(plushb_cache_idwith cache reporting), the request ends with the newResultCode.prebidDemandInvalidTargetingand nothing is attached. Standalone Rendering ad units render the bid's markup, so they don't need the keys.Changes since the first version of this PR
fetchDemandBidInfoto the Mediation API ad units #1426'sMediationNativeAdUnitTest.swift, and with the video controls properties from Add video banner configuration #1430).bidSelectorproperties onAdUnitConfig,PrebidRequest,BannerView, the interstitial/rewarded ad units and the Mediation ad units are removed in favour ofPrebid.register(_:as: .bidSelector)(proposal 1.4.2). Because the selector is global, this also answers the review question about Original API ad units: they are covered.hb_pb/hb_bidder/hb_cache_idwere stripped from them, so a runner-up pick still left the server winner's other generic keys (hb_size,hb_deal, ...) in the targeting.hb_*key literals (Bid.isWinning,AdUnit,WinNotifierImpl, SKOverlay, SKAdNetwork) now come from one internalTargetingKeyenum, per the review comment.Public API
PrebidBidSelecting:pluginInfo,selectBid(from:context:)(selectBidFrom:context:in Objective-C), optionalonRegister()/onUnregister().BidSelectionContext:configId,adFormats.PluginCapability.bidSelector: at most one selector is registered. A second registration is ignored with a warning.ResultCode.prebidDemandInvalidTargeting = 12.Open points for review
BidSelectionContextis where per-impression data, such as an impression ID, would go later.Targeting.forceSdkToChooseWinneryet: what replaces it should be agreed first.Test plan
BidSelectorTests(25): registration and the one-selector limit, default path unchanged, selection, main thread, nil and foreign results, eligibility with and withoutfilterOutUncachedBids,forceSdkToChooseWinnerprecedence, targeting validation, standalone rendering, and the key mapping (aliases, truncation, other key families, ambiguity).PrebidBidSelectingObjCTest(2): an Objective-C selector registers and unregisters, and the capability and result code are visible from Objective-C.PrebidMobilePRTests) on CI🤖 Generated with Claude Code