Skip to content

Commit

Permalink
Rubicon: Add imp[].ext.rp.rtb.formats logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNahornyi committed Oct 25, 2023
1 parent ec729e6 commit f8de17f
Show file tree
Hide file tree
Showing 5 changed files with 550 additions and 3 deletions.
30 changes: 27 additions & 3 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ type rubiconImpExtRP struct {
ZoneID int `json:"zone_id"`
Target json.RawMessage `json:"target,omitempty"`
Track rubiconImpExtRPTrack `json:"track"`
RTB *rubiconImpExtRpRtb `json:"rtb,omitempty"`
}

type rubiconImpExtRpRtb struct {
Formats []openrtb_ext.BidType `json:"formats,omitempty"`
}

type rubiconUserExtRP struct {
Expand Down Expand Up @@ -299,6 +304,10 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
Skadn: bidderExt.Skadn,
}

if len(bidderExt.Bidder.Formats) > 0 {
impExt.RP.RTB = &rubiconImpExtRpRtb{bidderExt.Bidder.Formats}
}

imp.Ext, err = json.Marshal(&impExt)
if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -592,19 +601,31 @@ func prepareImpsToExtMap(impsToExtMap map[*openrtb2.Imp]rubiconExtImpBidder) map
continue
}

splitImps := splitMultiFormatImp(imp)
splitImps, formats := splitMultiFormatImp(imp)
for _, imp := range splitImps {
impCopy := imp

existingFormats := bidderExt.Bidder.Formats
var resolvedFormats []openrtb_ext.BidType
if len(existingFormats) > 0 {
resolvedFormats = existingFormats
} else {
resolvedFormats = formats
}
bidderExt.Bidder.Formats = resolvedFormats

preparedImpsToExtMap[impCopy] = bidderExt
}
}

return preparedImpsToExtMap
}

func splitMultiFormatImp(imp *openrtb2.Imp) []*openrtb2.Imp {
func splitMultiFormatImp(imp *openrtb2.Imp) ([]*openrtb2.Imp, []openrtb_ext.BidType) {
splitImps := make([]*openrtb2.Imp, 0)
mediaTypes := make([]openrtb_ext.BidType, 0)
if imp.Banner != nil {
mediaTypes = append(mediaTypes, openrtb_ext.BidTypeBanner)
impCopy := *imp
impCopy.Video = nil
impCopy.Native = nil
Expand All @@ -613,6 +634,7 @@ func splitMultiFormatImp(imp *openrtb2.Imp) []*openrtb2.Imp {
}

if imp.Video != nil {
mediaTypes = append(mediaTypes, openrtb_ext.BidTypeVideo)
impCopy := *imp
impCopy.Banner = nil
impCopy.Native = nil
Expand All @@ -621,6 +643,7 @@ func splitMultiFormatImp(imp *openrtb2.Imp) []*openrtb2.Imp {
}

if imp.Native != nil {
mediaTypes = append(mediaTypes, openrtb_ext.BidTypeNative)
impCopy := *imp
impCopy.Banner = nil
impCopy.Video = nil
Expand All @@ -629,14 +652,15 @@ func splitMultiFormatImp(imp *openrtb2.Imp) []*openrtb2.Imp {
}

if imp.Audio != nil {
mediaTypes = append(mediaTypes, openrtb_ext.BidTypeAudio)
impCopy := *imp
impCopy.Banner = nil
impCopy.Video = nil
impCopy.Native = nil
splitImps = append(splitImps, &impCopy)
}

return splitImps
return splitImps, mediaTypes
}

func resolveBidFloor(bidFloor float64, bidFloorCur string, reqInfo *adapters.ExtraRequestInfo) (float64, error) {
Expand Down
Loading

0 comments on commit f8de17f

Please sign in to comment.