From ecd9db495e4c0c0d2734d1fa0b85e9abb955514c Mon Sep 17 00:00:00 2001 From: Avinash Kapre Date: Sun, 17 Nov 2024 20:50:19 +0530 Subject: [PATCH] Send correct multiBidMultiFLoor records to analytics --- adapters/pubmatic/pubmatic.go | 39 ++++++++++++++++++- adapters/pubmatic/pubmatic_ow.go | 4 ++ .../pubmatic/openwrap/auctionresponsehook.go | 1 + modules/pubmatic/openwrap/defaultbids.go | 35 +++++++++++++++++ modules/pubmatic/openwrap/models/response.go | 35 +++++++++-------- modules/pubmatic/openwrap/models/utils.go | 5 +++ 6 files changed, 101 insertions(+), 18 deletions(-) diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go index 84eec48e74a..457ba817f69 100644 --- a/adapters/pubmatic/pubmatic.go +++ b/adapters/pubmatic/pubmatic.go @@ -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 @@ -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 +} diff --git a/adapters/pubmatic/pubmatic_ow.go b/adapters/pubmatic/pubmatic_ow.go index cc52e1d182e..883a2830b77 100644 --- a/adapters/pubmatic/pubmatic_ow.go +++ b/adapters/pubmatic/pubmatic_ow.go @@ -102,3 +102,7 @@ func renameTransparencyParamsKey(bidExt []byte) []byte { return bidExt } + +func addFloorInBidExt(bidExt []byte, requestBody []byte) []byte { + return bidExt +} diff --git a/modules/pubmatic/openwrap/auctionresponsehook.go b/modules/pubmatic/openwrap/auctionresponsehook.go index cacda092cfa..481842d19ad 100644 --- a/modules/pubmatic/openwrap/auctionresponsehook.go +++ b/modules/pubmatic/openwrap/auctionresponsehook.go @@ -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) diff --git a/modules/pubmatic/openwrap/defaultbids.go b/modules/pubmatic/openwrap/defaultbids.go index ebc3af57eae..ba59f5d345d 100644 --- a/modules/pubmatic/openwrap/defaultbids.go +++ b/modules/pubmatic/openwrap/defaultbids.go @@ -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)] diff --git a/modules/pubmatic/openwrap/models/response.go b/modules/pubmatic/openwrap/models/response.go index 438908f8cba..a9bd7864974 100644 --- a/modules/pubmatic/openwrap/models/response.go +++ b/modules/pubmatic/openwrap/models/response.go @@ -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 { diff --git a/modules/pubmatic/openwrap/models/utils.go b/modules/pubmatic/openwrap/models/utils.go index 4775b93426f..6964ceef962 100644 --- a/modules/pubmatic/openwrap/models/utils.go +++ b/modules/pubmatic/openwrap/models/utils.go @@ -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 }