Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion PrebidMobile/Swift/AdUnits/AdUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,21 @@ public class AdUnit: NSObject, DispatcherDelegate {
}
}
}


/// Like `fetchDemand(adObject:completion:)` — it still attaches the Prebid targeting keywords
/// onto `adObject` for ad serving — but returns the full `BidInfo` (including exact winning-bid
/// economics) instead of only the result code.
dynamic public func fetchDemand(
adObject: AnyObject,
completionBidInfo: @escaping(_ bidInfo: BidInfo) -> Void
) {
baseFetchDemand(adObject: adObject) { bidInfo in
DispatchQueue.main.async {
completionBidInfo(bidInfo)
}
}
}

// SDK internal
func baseFetchDemand(
adObject: AnyObject? = nil,
Expand Down
34 changes: 32 additions & 2 deletions PrebidMobile/Swift/AdUnits/MultiformatAdUnit/BidInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ public class BidInfo: NSObject {

/// Events related to the bid
public private(set) var events: [String: String]


// MARK: - Winning-bid economics
// Exact economics of the winning bid, surfaced on the original (GAM) API. Prebid normally
// exposes only the bucketed `hb_pb` keyword; these read the winning bid's real values off the
// (module-internal) ORTB response inside `create(...)`.

/// Winning bid net price (exact CPM), if any.
public private(set) var cpm: Double?

/// Bid currency (ISO-4217), from the ORTB bid response.
public private(set) var currency: String?

/// Winning creative id (`crid`).
public private(set) var creativeId: String?

/// Auction id — the ORTB response id (falls back to the bidder response id `bidid`).
public private(set) var auctionId: String?

/// Winning ad id (`adid`).
public private(set) var adId: String?

/// Initializes a new `BidInfo` instance with the specified parameters.
/// - Parameters:
/// - resultCode: The result code of the bid request.
Expand Down Expand Up @@ -86,7 +106,17 @@ public class BidInfo: NSObject {
if let impURL = bidResponse.winningBid?.events?.win {
bidInfo.addEvent(key: BidInfo.EVENT_IMP, value: impURL)
}


// Surface exact economics of the winning bid (original-API analytics). These read the
// module-internal ORTB objects, which are only reachable here inside PrebidMobile.
if let winningBid = bidResponse.winningBid {
bidInfo.cpm = Double(winningBid.price)
bidInfo.creativeId = winningBid.bid.crid
bidInfo.adId = winningBid.bid.adid
}
bidInfo.currency = bidResponse.rawResponse?.cur
bidInfo.auctionId = bidResponse.rawResponse?.requestID ?? bidResponse.rawResponse?.bidid

return bidInfo
}

Expand Down