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

[EXCH-11021] add support for native imps in golang prebid server #15

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
16 changes: 12 additions & 4 deletions adapters/openx/openx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ type openxRespExt struct {

func (a *OpenxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var bannerImps []openrtb2.Imp
var bannerAndNativeImps []openrtb2.Imp
var videoImps []openrtb2.Imp

for _, imp := range request.Imp {
// OpenX doesn't allow multi-type imp. Banner takes priority over video.
// OpenX doesn't allow multi-type imp. Banner takes priority over video and video takes priority over native
// Openx also wants to send banner and native imps in one request
if imp.Banner != nil {
bannerImps = append(bannerImps, imp)
bannerAndNativeImps = append(bannerAndNativeImps, imp)
} else if imp.Video != nil {
videoImps = append(videoImps, imp)
} else if imp.Native != nil {
bannerAndNativeImps = append(bannerAndNativeImps, imp)
}
}

var adapterRequests []*adapters.RequestData
// Make a copy as we don't want to change the original request
reqCopy := *request

reqCopy.Imp = bannerImps
reqCopy.Imp = bannerAndNativeImps
adapterReq, errors := a.makeRequest(&reqCopy)
if adapterReq != nil {
adapterRequests = append(adapterRequests, adapterReq)
Expand Down Expand Up @@ -256,12 +259,17 @@ func getBidVideo(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidVideo {
//
// OpenX doesn't support multi-type impressions.
// If both banner and video exist, take banner as we do not want in-banner video.
// If both video and native exist and banner is nil, take video.
// If both banner and native exist, take banner.
// If all of the types (banner, video, native) exist, take banner.
func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType {
mediaType := openrtb_ext.BidTypeBanner
for _, imp := range imps {
if imp.ID == impId {
if imp.Banner == nil && imp.Video != nil {
mediaType = openrtb_ext.BidTypeVideo
} else if imp.Banner == nil && imp.Native != nil {
mediaType = openrtb_ext.BidTypeNative
}
return mediaType
}
Expand Down
4 changes: 2 additions & 2 deletions adapters/openx/openxtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.500000,
"adm": "some-test-ad",
"adm": "{\"ver\": \"1.2\", \"assets\": [{\"id\": 1, \"required\": 1,\"title\": {\"text\": \"OpenX (Title)\"}}], \"link\": {\"url\": \"https://www.openx.com/\"}, \"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"http://example.com/impression\"}]}",
"crid": "crid_10",
"h": 90,
"w": 728
Expand All @@ -72,7 +72,7 @@
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"adm": "{\"ver\": \"1.2\", \"assets\": [{\"id\": 1, \"required\": 1,\"title\": {\"text\": \"OpenX (Title)\"}}], \"link\": {\"url\": \"https://www.openx.com/\"}, \"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"http://example.com/impression\"}]}",
"crid": "crid_10",
"w": 728,
"h": 90
Expand Down
87 changes: 87 additions & 0 deletions adapters/openx/openxtest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request": "{\"ver\":\"1.2\",\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":90}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"wmin\":1200,\"hmin\":627}}],\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]}]}",
"ver": "1.2"
},
"ext": {
"bidder": {
"unit": "539439964",
"delDomain": "se-demo-d.openx.net"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://rtb.openx.net/prebid",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request": "{\"ver\":\"1.2\",\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":90}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"wmin\":1200,\"hmin\":627}}],\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]}]}",
"ver": "1.2"
},
"tagid": "539439964"
}
],
"ext": {
"bc": "hb_pbs_1.0.0",
"delDomain": "se-demo-d.openx.net"
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"cur": "USD",
"seatbid": [
{
"seat": "openx",
"bid": [{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.500000,
"adm": "{\"ver\": \"1.2\", \"assets\": [{\"id\": 1, \"required\": 1,\"title\": {\"text\": \"OpenX (Title)\"}}], \"link\": {\"url\": \"https://www.openx.com/\"}, \"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"http://example.com/impression\"}]}",
"crid": "crid_10",
"w": 300,
"h": 200
}]
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "{\"ver\": \"1.2\", \"assets\": [{\"id\": 1, \"required\": 1,\"title\": {\"text\": \"OpenX (Title)\"}}], \"link\": {\"url\": \"https://www.openx.com/\"}, \"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"http://example.com/impression\"}]}",
"crid": "crid_10",
"w": 300,
"h": 200
},
"type": "native"
}
]
}
]
}
Loading
Loading