Skip to content

Commit

Permalink
Send correct multiBidMultiFLoor records to analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
AvinashKapre committed Nov 17, 2024
1 parent 1fb78f7 commit ecd9db4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 18 deletions.
39 changes: 38 additions & 1 deletion adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ func (a *PubmaticAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externa
targets := getTargetingKeys(sb.Ext, string(externalRequest.BidderName))
for i := 0; i < len(sb.Bid); i++ {
bid := sb.Bid[i]
bid.ImpID = trimSuffixWithPattern(bid.ImpID)

//single bidresp => update, requestdata -> bid.ext.mbmf.floor, trim impid
bid.Ext = updateBidExtWithMultiFloor(bid.ImpID, bid.Ext, externalRequest.Body)

bid.Ext = renameTransparencyParamsKey(bid.Ext)
// Copy SeatBid Ext to Bid.Ext
Expand Down Expand Up @@ -881,3 +883,38 @@ func getDisplayManagerAndVer(app *openrtb2.App) (string, string) {
}
return "", ""
}

func updateBidExtWithMultiFloor(bidImpID string, bidExt, reqBody []byte) []byte {
bidExtMap := getMapFromJSON(bidExt)
reqBodyMap := getMapFromJSON(reqBody)

if bidExtMap == nil {
bidExtMap = make(map[string]interface{})
}

if reqBodyMap == nil {
return bidExt
}

if imp, ok := reqBodyMap["imp"]; ok {
impMap := imp.([]interface{})
for _, impObj := range impMap {
impObjMap := impObj.(map[string]interface{})
if reqImpID, ok := impObjMap["id"]; ok && re.MatchString(reqImpID.(string)) {
if floor, ok := impObjMap["bidfloor"]; ok && reqImpID.(string) == bidImpID {
floorValue := floor.(float64)
if floorValue > 0 {
bidExtMap["mbmf"] = append(bidExtMap["mbmf"].([]interface{}), floorValue)
}
trimSuffixWithPattern(reqImpID.(string))
}
}
}
}

bidExt, err := json.Marshal(bidExtMap)
if err != nil {
return bidExt
}
return bidExt
}
4 changes: 4 additions & 0 deletions adapters/pubmatic/pubmatic_ow.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ func renameTransparencyParamsKey(bidExt []byte) []byte {

return bidExt
}

func addFloorInBidExt(bidExt []byte, requestBody []byte) []byte {
return bidExt
}
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/auctionresponsehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ func (m OpenWrap) handleAuctionResponseHook(

rctx.ResponseExt = responseExt
rctx.DefaultBids = m.addDefaultBids(&rctx, payload.BidResponse, responseExt)
rctx.DefaultBids = m.addDefaultBidsForMultiFloorsConfig(&rctx, payload.BidResponse, responseExt)

rctx.Trackers = tracker.CreateTrackers(rctx, payload.BidResponse)

Expand Down
35 changes: 35 additions & 0 deletions modules/pubmatic/openwrap/defaultbids.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,41 @@ func (m *OpenWrap) addDefaultBids(rctx *models.RequestCtx, bidResponse *openrtb2
return defaultBids
}

func (m *OpenWrap) addDefaultBidsForMultiFloorsConfig(rctx *models.RequestCtx, bidResponse *openrtb2.BidResponse, bidResponseExt openrtb_ext.ExtBidResponse) map[string]map[string][]openrtb2.Bid {
defaultBids := rctx.DefaultBids
if rctx.Endpoint != models.EndpointAppLovinMax || !rctx.AppLovinMax.MultiFloorsConfig.Enabled {
return defaultBids
}
seatBidsMultiFloor := make(map[string]int, len(bidResponse.SeatBid))
for _, seatBid := range bidResponse.SeatBid {
if seatBid.Seat == models.BidderPubMatic || seatBid.Seat == models.BidderPubMaticSecondaryAlias {
for _, bid := range seatBid.Bid {
impId, _ := models.GetImpressionID(bid.ImpID)
seatBidsMultiFloor[impId]++
}
}
}

for impID, impCtx := range rctx.ImpBidCtx {
count := len(rctx.AppLovinMax.MultiFloorsConfig.Config[impCtx.TagID]) - seatBidsMultiFloor[impID]
if _, ok := defaultBids[impID][models.BidderPubMatic]; ok {
count = count - len(defaultBids[impID][models.BidderPubMatic])
}
for i := 0; i < count; i++ {
uuid, _ := m.uuidGenerator.Generate()
bidExt := newDefaultBidExt(*rctx, impID, models.BidderPubMatic, bidResponseExt)
bidExtJson, _ := json.Marshal(bidExt)

defaultBids[impID][models.BidderPubMatic] = append(defaultBids[impID][models.BidderPubMatic], openrtb2.Bid{
ID: uuid,
ImpID: impID,
Ext: bidExtJson,
})
}
}
return defaultBids
}

// getNonBRCodeFromBidRespExt maps the error-code present in prebid partner response with standard nonBR code
func getNonBRCodeFromBidRespExt(bidder string, bidResponseExt openrtb_ext.ExtBidResponse) *openrtb3.NoBidReason {
errs := bidResponseExt.Errors[openrtb_ext.BidderName(bidder)]
Expand Down
35 changes: 18 additions & 17 deletions modules/pubmatic/openwrap/models/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ import (
type BidExt struct {
openrtb_ext.ExtBid

ErrorCode int `json:"errorCode,omitempty"`
ErrorMsg string `json:"errorMessage,omitempty"`
RefreshInterval int `json:"refreshInterval,omitempty"`
CreativeType string `json:"crtype,omitempty"`
Summary []Summary `json:"summary,omitempty"`
SKAdnetwork json.RawMessage `json:"skadn,omitempty"`
Video *ExtBidVideo `json:"video,omitempty"`
Banner *ExtBidBanner `json:"banner,omitempty"`
DspId int `json:"dspid,omitempty"`
Winner int `json:"winner,omitempty"`
NetECPM float64 `json:"netecpm,omitempty"`
OriginalBidCPM float64 `json:"origbidcpm,omitempty"`
OriginalBidCur string `json:"origbidcur,omitempty"`
OriginalBidCPMUSD float64 `json:"origbidcpmusd,omitempty"`
Nbr *openrtb3.NoBidReason `json:"-"` // Reason for not bidding
Fsc int `json:"fsc,omitempty"`
AdPod *AdpodBidExt `json:"adpod,omitempty"`
ErrorCode int `json:"errorCode,omitempty"`
ErrorMsg string `json:"errorMessage,omitempty"`
RefreshInterval int `json:"refreshInterval,omitempty"`
CreativeType string `json:"crtype,omitempty"`
Summary []Summary `json:"summary,omitempty"`
SKAdnetwork json.RawMessage `json:"skadn,omitempty"`
Video *ExtBidVideo `json:"video,omitempty"`
Banner *ExtBidBanner `json:"banner,omitempty"`
DspId int `json:"dspid,omitempty"`
Winner int `json:"winner,omitempty"`
NetECPM float64 `json:"netecpm,omitempty"`
OriginalBidCPM float64 `json:"origbidcpm,omitempty"`
OriginalBidCur string `json:"origbidcur,omitempty"`
OriginalBidCPMUSD float64 `json:"origbidcpmusd,omitempty"`
Nbr *openrtb3.NoBidReason `json:"-"` // Reason for not bidding
Fsc int `json:"fsc,omitempty"`
AdPod *AdpodBidExt `json:"adpod,omitempty"`
MultiBidMultiFloor float64 `json:"mbmf,omitempty"`
}

type AdpodBidExt struct {
Expand Down
5 changes: 5 additions & 0 deletions modules/pubmatic/openwrap/models/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ func GetBidLevelFloorsDetails(bidExt BidExt, impCtx ImpCtx,
frv = 0 // set it back to 0
}

//Set the fv from bid.ext.mbmf if it is set
if bidExt.MultiBidMultiFloor > 0 {
fv = bidExt.MultiBidMultiFloor
}

return
}

Expand Down

0 comments on commit ecd9db4

Please sign in to comment.