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

Yieldmo: Get bid type from bid.ext.mediatype in bid response #3295

Merged
merged 8 commits into from
Nov 30, 2023
35 changes: 26 additions & 9 deletions adapters/yieldmo/yieldmo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type Ext struct {
Gpid string `json:"gpid,omitempty"`
}

type ExtBid struct {
MediaType string `json:"mediatype,omitempty"`
}

func (a *YieldmoAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var adapterRequests []*adapters.RequestData
Expand Down Expand Up @@ -138,14 +142,18 @@ func (a *YieldmoAdapter) MakeBids(internalRequest *openrtb2.BidRequest, external

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidType, err := getMediaTypeForImp(sb.Bid[i])
if err != nil {
continue
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp),
BidType: bidType,
})
}
}
return bidResponse, nil

}

// Builder builds a new instance of the Yieldmo adapter for the given bidder with the given config.
Expand All @@ -156,12 +164,21 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
return bidder, nil
}

func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType {
//default to video unless banner exists in impression
for _, imp := range imps {
if imp.ID == impId && imp.Banner != nil {
return openrtb_ext.BidTypeBanner
}
// Retrieve the media type corresponding to the bid from the bid.ext object
func getMediaTypeForImp(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
var bidExt ExtBid
if err := json.Unmarshal(bid.Ext, &bidExt); err != nil {
return "", &errortypes.BadInput{Message: err.Error()}
}

switch bidExt.MediaType {
ym-prasanth marked this conversation as resolved.
Show resolved Hide resolved
case "banner":
return openrtb_ext.BidTypeBanner, nil
case "video":
return openrtb_ext.BidTypeVideo, nil
case "native":
return openrtb_ext.BidTypeNative, nil
default:
return "", fmt.Errorf("invalid BidType: %s", bidExt.MediaType)
}
return openrtb_ext.BidTypeVideo
}
12 changes: 10 additions & 2 deletions adapters/yieldmo/yieldmotest/exemplary/app-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300
"w": 300,
"ext":
{
"mediatype": "banner"
}
}
]
}
Expand All @@ -87,7 +91,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250
"h": 250,
"ext":
{
"mediatype": "banner"
}
},
"type": "banner"
}
Expand Down
12 changes: 10 additions & 2 deletions adapters/yieldmo/yieldmotest/exemplary/app_video.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300
"w": 300,
"ext":
{
"mediatype": "video"
}
}
]
}
Expand All @@ -85,7 +89,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250
"h": 250,
"ext":
{
"mediatype": "video"
}
},
"type": "video"
}
Expand Down
12 changes: 10 additions & 2 deletions adapters/yieldmo/yieldmotest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300
"w": 300,
"ext":
{
"mediatype": "banner"
}
}
]
}
Expand All @@ -87,7 +91,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250
"h": 250,
"ext":
{
"mediatype": "banner"
}
},
"type": "banner"
}
Expand Down
12 changes: 10 additions & 2 deletions adapters/yieldmo/yieldmotest/exemplary/simple_video.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300
"w": 300,
"ext":
{
"mediatype": "video"
}
}
]
}
Expand All @@ -85,7 +89,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250
"h": 250,
"ext":
{
"mediatype": "video"
}
},
"type": "video"
}
Expand Down
12 changes: 10 additions & 2 deletions adapters/yieldmo/yieldmotest/exemplary/with_gpid.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"h": 250,
"w": 300
"w": 300,
"ext":
{
"mediatype": "banner"
}
}
]
}
Expand All @@ -95,7 +99,11 @@
"adm": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 250
"h": 250,
"ext":
{
"mediatype": "banner"
}
},
"type": "banner"
}
Expand Down
Loading