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

OpenX adapter: add support for native imps #4135

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions adapters/openx/openx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,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 @@ -243,12 +246,17 @@ func (a *OpenxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRe
//
// 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
// And if all the types 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
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": "test-native",
"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": "test-native",
"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": "some-test-ad",
"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": "some-test-ad",
"crid": "crid_10",
"w": 300,
"h": 200
},
"type": "native"
}
]
}
]
}
44 changes: 43 additions & 1 deletion adapters/openx/openxtest/supplemental/multi-imp.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
}
}
},
{
"id": "native-imp-1",
"native": {
"request": "test-native",
"ver": "1.2"
},
"ext": {
"bidder": {
"unit": "123",
"delDomain": "se-demo-d.openx.net"
}
}
},
{
"id": "banner-imp-2",
"banner": {},
Expand All @@ -46,6 +59,10 @@
"id": "multi-type-imp",
"banner": {},
"video": {"mimes": ["video/mp4"]},
"native": {
"request": "test-native",
"ver": "1.2"
},
"ext": {
"bidder": {
"unit": "555",
Expand All @@ -68,6 +85,14 @@
"banner": {},
"tagid": "111"
},
{
"id": "native-imp-1",
"native": {
"request": "test-native",
"ver": "1.2"
},
"tagid": "123"
},
{
"id": "banner-imp-2",
"banner": {},
Expand All @@ -77,6 +102,10 @@
"id": "multi-type-imp",
"banner": {},
"video": {"mimes": ["video/mp4"]},
"native": {
"request": "test-native",
"ver": "1.2"
},
"tagid": "555"
}
],
Expand All @@ -85,7 +114,7 @@
"delDomain": "se-demo-d.openx.net"
}
},
"impIDs":["banner-imp-1","banner-imp-2","multi-type-imp"]
"impIDs":["banner-imp-1","native-imp-1","banner-imp-2","multi-type-imp"]
},
"mockResponse": {
"status": 200,
Expand All @@ -100,6 +129,11 @@
"impid": "banner-imp-1",
"price": 0.1
},
{
"id": "native-bid-1",
"impid": "native-imp-1",
"price": 0.1
},
{
"id": "banner-bid-2",
"impid": "banner-imp-2",
Expand Down Expand Up @@ -206,6 +240,14 @@
},
"type": "banner"
},
{
"bid": {
"id": "native-bid-1",
"impid": "native-imp-1",
"price": 0.1
},
"type": "native"
},
{
"bid": {
"id": "banner-bid-2",
Expand Down
2 changes: 2 additions & 0 deletions static/bidder-info/openx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ capabilities:
mediaTypes:
- banner
- video
- native
site:
mediaTypes:
- banner
- video
- native
modifyingVastXmlAllowed: true
userSync:
iframe:
Expand Down
Loading