Skip to content

Commit

Permalink
Adjust imp.BidFloor using BidAdjustment (#3063)
Browse files Browse the repository at this point in the history
* BidAdjustment for imp.BidFloor

* Adding function to check if adjustForBidAdjustment is enabled

* Adding check for empty bidAdjustmentFactors
  • Loading branch information
Pubmatic-Dhruv-Sonone authored Sep 12, 2023
1 parent 4ec839e commit 2e056bf
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 18 deletions.
4 changes: 4 additions & 0 deletions config/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (pf *AccountPriceFloors) validate(errs []error) []error {
return errs
}

func (pf *AccountPriceFloors) IsAdjustForBidAdjustmentEnabled() bool {
return pf.AdjustForBidAdjustment
}

// EnabledForChannelType indicates whether CCPA is turned on at the account level for the specified channel type
// by using the channel type setting if defined or the general CCPA setting if defined; otherwise it returns nil
func (a *AccountCCPA) EnabledForChannelType(channelType ChannelType) *bool {
Expand Down
2 changes: 1 addition & 1 deletion exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (e *exchange) HoldAuction(ctx context.Context, r *AuctionRequest, debugLog
Prebid: *requestExtPrebid,
SChain: requestExt.GetSChain(),
}
bidderRequests, privacyLabels, errs := e.requestSplitter.cleanOpenRTBRequests(ctx, *r, requestExtLegacy, gdprDefaultValue)
bidderRequests, privacyLabels, errs := e.requestSplitter.cleanOpenRTBRequests(ctx, *r, requestExtLegacy, gdprDefaultValue, bidAdjustmentFactors)
errs = append(errs, floorErrs...)

mergedBidAdj, err := bidadjustment.Merge(r.BidRequestWrapper, r.Account.BidAdjustments)
Expand Down
29 changes: 28 additions & 1 deletion exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type requestSplitter struct {
func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
auctionReq AuctionRequest,
requestExt *openrtb_ext.ExtRequest,
gdprDefaultValue gdpr.Signal,
gdprDefaultValue gdpr.Signal, bidAdjustmentFactors map[string]float64,
) (allowedBidderRequests []BidderRequest, privacyLabels metrics.PrivacyLabels, errs []error) {

req := auctionReq.BidRequestWrapper
Expand Down Expand Up @@ -93,6 +93,11 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,
}
}

if auctionReq.Account.PriceFloors.IsAdjustForBidAdjustmentEnabled() {
//Apply BidAdjustmentFactor to imp.BidFloor
applyBidAdjustmentToFloor(allBidderRequests, bidAdjustmentFactors)
}

gdprSignal, err := getGDPR(req)
if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -1071,3 +1076,25 @@ func getPrebidMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
Message: errMsg,
}
}

func applyBidAdjustmentToFloor(allBidderRequests []BidderRequest, bidAdjustmentFactors map[string]float64) {

if len(bidAdjustmentFactors) == 0 {
return
}

for _, bidderRequest := range allBidderRequests {
bidAdjustment := 1.0

if bidAdjustemntValue, ok := bidAdjustmentFactors[string(bidderRequest.BidderName)]; ok {
bidAdjustment = bidAdjustemntValue
}

if bidAdjustment != 1.0 {
for index, imp := range bidderRequest.BidRequest.Imp {
imp.BidFloor = imp.BidFloor / bidAdjustment
bidderRequest.BidRequest.Imp[index] = imp
}
}
}
}
Loading

0 comments on commit 2e056bf

Please sign in to comment.