Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging from master #40

Merged
merged 3 commits into from
Jul 6, 2023
Merged
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
11 changes: 10 additions & 1 deletion adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ type pubmaticBidExtVideo struct {
Duration *int `json:"duration,omitempty"`
}

type pubmaticContext struct {
Data json.RawMessage `json:"data"`
}

type ExtImpBidderPubmatic struct {
adapters.ExtImpBidder
Data json.RawMessage `json:"data,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Context pubmaticContext `json:"context"`
}

type ExtAdServer struct {
Expand Down Expand Up @@ -305,6 +310,10 @@ func parseImpressionObject(imp *openrtb2.Imp, extractWrapperExtFromImp, extractP
populateFirstPartyDataImpAttributes(bidderExt.Data, extMap)
}

if len(bidderExt.Context.Data) > 0 {
populateFirstPartyDataImpAttributes(bidderExt.Context.Data, extMap)
}

imp.Ext = nil
if len(extMap) > 0 {
ext, err := json.Marshal(extMap)
Expand Down
11 changes: 7 additions & 4 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,12 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog
liveAdapters []openrtb_ext.BidderName
)

if len(r.StoredAuctionResponses) > 0 {
adapterBids, fledge, liveAdapters, err = buildStoredAuctionResponse(r.StoredAuctionResponses)
shouldMspBackfillBids := mspUpdateStoredAuctionResponse(r)
if len(r.StoredAuctionResponses) > 0 && !shouldMspBackfillBids {
adapterBids, fledge, liveAdapters, err, anyBidsReturned = mspApplyStoredAuctionResponse(r)
if err != nil {
return nil, err
}
anyBidsReturned = true

} else {
// List of bidders we have requests for.
liveAdapters = listBiddersWithRequests(bidderRequests)
Expand All @@ -367,6 +366,10 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog
alternateBidderCodes = *r.Account.AlternateBidderCodes
}
adapterBids, adapterExtra, fledge, anyBidsReturned = e.getAllBids(auctionCtx, bidderRequests, bidAdjustmentFactors, conversions, accountDebugAllow, r.GlobalPrivacyControlHeader, debugLog.DebugOverride, alternateBidderCodes, requestExtLegacy.Prebid.Experiment, r.HookExecutor, r.StartTime, bidAdjustmentRules)
adapterBids, fledge, liveAdapters, err, anyBidsReturned = mspPostProcessAuction(r, liveAdapters, adapterBids, adapterExtra, fledge, anyBidsReturned, shouldMspBackfillBids)
if err != nil {
return nil, err
}
r.MakeBidsTimeInfo = buildMakeBidsTimeInfoMap(adapterExtra)
}

Expand Down
62 changes: 62 additions & 0 deletions exchange/msp_exchange.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package exchange

import (
"encoding/json"
"time"

"github.com/prebid/openrtb/v19/openrtb2"
"github.com/prebid/prebid-server/exchange/entities"
"github.com/prebid/prebid-server/openrtb_ext"
)

const (
MSP_SEAT_IN_HOUSE = "msp-in-house"
)

func mspUpdateStoredAuctionResponse(r *AuctionRequest) bool {
if len(r.StoredAuctionResponses) > 0 {
if rawSeatBid, ok := r.StoredAuctionResponses[r.BidRequestWrapper.Imp[0].ID]; ok {
var seatBids []openrtb2.SeatBid

err := json.Unmarshal(rawSeatBid, &seatBids)
if err == nil && len(seatBids) > 0 && seatBids[0].Seat == MSP_SEAT_IN_HOUSE {
// when price is the same, randomly choose one
swapIdx := time.Now().Second() % len(seatBids[0].Bid)
seatBids[0].Bid[0], seatBids[0].Bid[swapIdx] = seatBids[0].Bid[swapIdx], seatBids[0].Bid[0]
updatedJson, _ := json.Marshal(seatBids)
r.StoredAuctionResponses[r.BidRequestWrapper.Imp[0].ID] = updatedJson
return true
}
}
}

return false
}

func mspApplyStoredAuctionResponse(r *AuctionRequest) (map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid,
*openrtb_ext.Fledge,
[]openrtb_ext.BidderName,
error, bool) {
adapterBids, fledge, liveAdapters, err := buildStoredAuctionResponse(r.StoredAuctionResponses)
return adapterBids, fledge, liveAdapters, err, err == nil
}

func mspPostProcessAuction(
r *AuctionRequest,
liveAdapters []openrtb_ext.BidderName,
adapterBids map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid,
adapterExtra map[openrtb_ext.BidderName]*seatResponseExtra,
fledge *openrtb_ext.Fledge,
anyBidsReturned bool,
shouldMspBackfillBids bool) (map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid,
*openrtb_ext.Fledge,
[]openrtb_ext.BidderName,
error, bool) {
// TODO: freqcap, blocking

if shouldMspBackfillBids && !anyBidsReturned {
return mspApplyStoredAuctionResponse(r)
}

return adapterBids, fledge, liveAdapters, nil, anyBidsReturned
}