Skip to content

Commit 39dba15

Browse files
Fuska1gmiedlar-ox
andauthored
OpenX: Native support (#4144)
Co-authored-by: gmiedlar-ox <gabriela.miedlar@openx.com>
1 parent a8ff354 commit 39dba15

File tree

5 files changed

+259
-9
lines changed

5 files changed

+259
-9
lines changed

adapters/openx/openx.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,26 @@ type openxRespExt struct {
3434

3535
func (a *OpenxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
3636
var errs []error
37-
var bannerImps []openrtb2.Imp
37+
var bannerAndNativeImps []openrtb2.Imp
3838
var videoImps []openrtb2.Imp
3939

4040
for _, imp := range request.Imp {
41-
// OpenX doesn't allow multi-type imp. Banner takes priority over video.
41+
// OpenX doesn't allow multi-type imp. Banner takes priority over video and video takes priority over native
42+
// Openx also wants to send banner and native imps in one request
4243
if imp.Banner != nil {
43-
bannerImps = append(bannerImps, imp)
44+
bannerAndNativeImps = append(bannerAndNativeImps, imp)
4445
} else if imp.Video != nil {
4546
videoImps = append(videoImps, imp)
47+
} else if imp.Native != nil {
48+
bannerAndNativeImps = append(bannerAndNativeImps, imp)
4649
}
4750
}
4851

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

53-
reqCopy.Imp = bannerImps
56+
reqCopy.Imp = bannerAndNativeImps
5457
adapterReq, errors := a.makeRequest(&reqCopy)
5558
if adapterReq != nil {
5659
adapterRequests = append(adapterRequests, adapterReq)
@@ -256,12 +259,17 @@ func getBidVideo(bid *openrtb2.Bid) *openrtb_ext.ExtBidPrebidVideo {
256259
//
257260
// OpenX doesn't support multi-type impressions.
258261
// If both banner and video exist, take banner as we do not want in-banner video.
262+
// If both video and native exist and banner is nil, take video.
263+
// If both banner and native exist, take banner.
264+
// If all of the types (banner, video, native) exist, take banner.
259265
func getMediaTypeForImp(impId string, imps []openrtb2.Imp) openrtb_ext.BidType {
260266
mediaType := openrtb_ext.BidTypeBanner
261267
for _, imp := range imps {
262268
if imp.ID == impId {
263269
if imp.Banner == nil && imp.Video != nil {
264270
mediaType = openrtb_ext.BidTypeVideo
271+
} else if imp.Banner == nil && imp.Native != nil {
272+
mediaType = openrtb_ext.BidTypeNative
265273
}
266274
return mediaType
267275
}

adapters/openx/openxtest/exemplary/simple-banner.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
5151
"impid": "test-imp-id",
5252
"price": 0.500000,
53-
"adm": "some-test-ad",
53+
"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\"}]}",
5454
"crid": "crid_10",
5555
"h": 90,
5656
"w": 728
@@ -72,7 +72,7 @@
7272
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
7373
"impid": "test-imp-id",
7474
"price": 0.5,
75-
"adm": "some-test-ad",
75+
"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\"}]}",
7676
"crid": "crid_10",
7777
"w": 728,
7878
"h": 90
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"imp": [
5+
{
6+
"id": "test-imp-id",
7+
"native": {
8+
"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]}]}",
9+
"ver": "1.2"
10+
},
11+
"ext": {
12+
"bidder": {
13+
"unit": "539439964",
14+
"delDomain": "se-demo-d.openx.net"
15+
}
16+
}
17+
}
18+
]
19+
},
20+
21+
"httpCalls": [
22+
{
23+
"expectedRequest": {
24+
"uri": "http://rtb.openx.net/prebid",
25+
"body": {
26+
"id": "test-request-id",
27+
"imp": [
28+
{
29+
"id": "test-imp-id",
30+
"native": {
31+
"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]}]}",
32+
"ver": "1.2"
33+
},
34+
"tagid": "539439964"
35+
}
36+
],
37+
"ext": {
38+
"bc": "hb_pbs_1.0.0",
39+
"delDomain": "se-demo-d.openx.net"
40+
}
41+
},
42+
"impIDs":["test-imp-id"]
43+
},
44+
"mockResponse": {
45+
"status": 200,
46+
"body": {
47+
"id": "test-request-id",
48+
"cur": "USD",
49+
"seatbid": [
50+
{
51+
"seat": "openx",
52+
"bid": [{
53+
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
54+
"impid": "test-imp-id",
55+
"price": 0.500000,
56+
"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\"}]}",
57+
"crid": "crid_10",
58+
"w": 300,
59+
"h": 200
60+
}]
61+
}
62+
]
63+
}
64+
}
65+
}
66+
],
67+
68+
"expectedBidResponses": [
69+
{
70+
"currency": "USD",
71+
"bids": [
72+
{
73+
"bid": {
74+
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
75+
"impid": "test-imp-id",
76+
"price": 0.5,
77+
"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\"}]}",
78+
"crid": "crid_10",
79+
"w": 300,
80+
"h": 200
81+
},
82+
"type": "native"
83+
}
84+
]
85+
}
86+
]
87+
}

0 commit comments

Comments
 (0)