Skip to content

Commit 21a9076

Browse files
EMXDigitalrakeshbalakrishnan28DBogdanEMX
authored
Emxd 3336 add app video ctv (#1529)
* Adapter changes for app and video support * adding ctv devicetype test case * Adding whitespace * Updates based on feedback from Prebid team * protocol bug fix and testing * Modifying test cases to accomodate new imp.ext field * bidtype bug fix and additonal testcase for storeUrl Co-authored-by: Rakesh Balakrishnan <[email protected]> Co-authored-by: Dan Bogdan <[email protected]>
1 parent dd7a5fc commit 21a9076

25 files changed

+1375
-54
lines changed

adapters/emx_digital/emx_digital.go

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/url"
88
"strconv"
9+
"strings"
910
"time"
1011

1112
"github.com/mxmCherry/openrtb"
@@ -110,7 +111,6 @@ func unpackImpExt(imp *openrtb.Imp) (*openrtb_ext.ExtImpEmxDigital, error) {
110111
}
111112

112113
func buildImpBanner(imp *openrtb.Imp) error {
113-
imp.Ext = nil
114114

115115
if imp.Banner == nil {
116116
return &errortypes.BadInput{
@@ -137,6 +137,40 @@ func buildImpBanner(imp *openrtb.Imp) error {
137137
return nil
138138
}
139139

140+
func buildImpVideo(imp *openrtb.Imp) error {
141+
142+
if len(imp.Video.MIMEs) == 0 {
143+
return &errortypes.BadInput{
144+
Message: fmt.Sprintf("Video: missing required field mimes"),
145+
}
146+
}
147+
148+
if imp.Video.H == 0 && imp.Video.W == 0 {
149+
return &errortypes.BadInput{
150+
Message: fmt.Sprintf("Video: Need at least one size to build request"),
151+
}
152+
}
153+
154+
if imp.Video.Protocols != nil {
155+
imp.Video.Protocols = cleanProtocol(imp.Video.Protocols)
156+
}
157+
158+
return nil
159+
}
160+
161+
// not supporting VAST protocol 7 (VAST 4.0);
162+
func cleanProtocol(protocols []openrtb.Protocol) []openrtb.Protocol {
163+
newitems := make([]openrtb.Protocol, 0, len(protocols))
164+
165+
for _, i := range protocols {
166+
if i != openrtb.ProtocolVAST40 {
167+
newitems = append(newitems, i)
168+
}
169+
}
170+
171+
return newitems
172+
}
173+
140174
// Add EMX required properties to Imp object
141175
func addImpProps(imp *openrtb.Imp, secure *int8, emxExt *openrtb_ext.ExtImpEmxDigital) {
142176
imp.TagID = emxExt.TagID
@@ -170,14 +204,22 @@ func preprocess(request *openrtb.BidRequest) []error {
170204
errors := make([]error, 0, impsCount)
171205
resImps := make([]openrtb.Imp, 0, impsCount)
172206
secure := int8(0)
173-
207+
domain := ""
174208
if request.Site != nil && request.Site.Page != "" {
175-
pageURL, err := url.Parse(request.Site.Page)
176-
if err == nil && pageURL.Scheme == "https" {
177-
secure = int8(1)
209+
domain = request.Site.Page
210+
} else if request.App != nil {
211+
if request.App.Domain != "" {
212+
domain = request.App.Domain
213+
} else if request.App.StoreURL != "" {
214+
domain = request.App.StoreURL
178215
}
179216
}
180217

218+
pageURL, err := url.Parse(domain)
219+
if err == nil && pageURL.Scheme == "https" {
220+
secure = int8(1)
221+
}
222+
181223
for _, imp := range request.Imp {
182224
emxExt, err := unpackImpExt(&imp)
183225
if err != nil {
@@ -187,10 +229,17 @@ func preprocess(request *openrtb.BidRequest) []error {
187229

188230
addImpProps(&imp, &secure, emxExt)
189231

190-
if err := buildImpBanner(&imp); err != nil {
232+
if imp.Video != nil {
233+
if err := buildImpVideo(&imp); err != nil {
234+
errors = append(errors, err)
235+
continue
236+
}
237+
} else if err := buildImpBanner(&imp); err != nil {
191238
errors = append(errors, err)
192239
continue
240+
193241
}
242+
194243
resImps = append(resImps, imp)
195244
}
196245

@@ -229,7 +278,7 @@ func (a *EmxDigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern
229278

230279
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
231280
Bid: &sb.Bid[i],
232-
BidType: "banner",
281+
BidType: getBidType(sb.Bid[i].AdM),
233282
})
234283
}
235284
}
@@ -238,6 +287,24 @@ func (a *EmxDigitalAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern
238287

239288
}
240289

290+
func getBidType(bidAdm string) openrtb_ext.BidType {
291+
if bidAdm != "" && ContainsAny(bidAdm, []string{"<?xml", "<vast"}) {
292+
return openrtb_ext.BidTypeVideo
293+
}
294+
return openrtb_ext.BidTypeBanner
295+
}
296+
297+
func ContainsAny(raw string, keys []string) bool {
298+
lowerCased := strings.ToLower(raw)
299+
for i := 0; i < len(keys); i++ {
300+
if strings.Contains(lowerCased, keys[i]) {
301+
return true
302+
}
303+
}
304+
return false
305+
306+
}
307+
241308
func NewEmxDigitalBidder(endpoint string) *EmxDigitalAdapter {
242309
return &EmxDigitalAdapter{
243310
endpoint: endpoint,

adapters/emx_digital/emx_digitaltest/exemplary/banner-and-video-app.json

Lines changed: 198 additions & 0 deletions
Large diffs are not rendered by default.

adapters/emx_digital/emx_digitaltest/exemplary/banner-and-video-site.json

Lines changed: 200 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "some_test_auction",
4+
"imp": [{
5+
"id": "some_test_ad_id",
6+
"banner": {
7+
"format": [{
8+
"w": 300,
9+
"h": 250
10+
}],
11+
"w": 300,
12+
"h": 250
13+
},
14+
"ext": {
15+
"bidder": {
16+
"tagid": "25251"
17+
}
18+
}
19+
}],
20+
"device": {
21+
"ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36",
22+
"ip": "123.123.123.123",
23+
"dnt": 1
24+
},
25+
"app": {
26+
"domain": "www.publisher.com",
27+
"storeurl": "http://www.publisher.com/awesome/site?with=some&parameters=here"
28+
}
29+
},
30+
31+
"httpCalls": [{
32+
"expectedRequest": {
33+
"uri": "https://hb.emxdgt.com?t=1000&ts=2060541160",
34+
"headers": {
35+
"Accept": [
36+
"application/json"
37+
],
38+
"Content-Type": [
39+
"application/json;charset=utf-8"
40+
],
41+
"X-Forwarded-For": [
42+
"123.123.123.123"
43+
],
44+
"Dnt": [
45+
"1"
46+
],
47+
"User-Agent": [
48+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
49+
]
50+
},
51+
"body": {
52+
"id": "some_test_auction",
53+
"imp": [{
54+
"id": "some_test_ad_id",
55+
"banner": {
56+
"format": [{
57+
"w": 300,
58+
"h": 250
59+
}],
60+
"w": 300,
61+
"h": 250
62+
},
63+
"ext": {
64+
"bidder": {
65+
"tagid": "25251"
66+
}
67+
},
68+
"tagid": "25251",
69+
"secure": 0
70+
}],
71+
"app": {
72+
"domain": "www.publisher.com",
73+
"storeurl": "http://www.publisher.com/awesome/site?with=some&parameters=here"
74+
},
75+
"device": {
76+
"ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36",
77+
"ip": "123.123.123.123",
78+
"dnt": 1
79+
}
80+
}
81+
},
82+
"mockResponse": {
83+
"status": 200,
84+
"body": {
85+
"id": "some_test_auction",
86+
"seatbid": [{
87+
"seat": "12356",
88+
"bid": [{
89+
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
90+
"id": "some_test_ad_id",
91+
"impid": "some_test_ad_id",
92+
"ttl": 300,
93+
"crid": "94395500",
94+
"w": 300,
95+
"price": 2.942808,
96+
"adid": "94395500",
97+
"h": 250
98+
}]
99+
}],
100+
"cur": "USD"
101+
}
102+
}
103+
}],
104+
105+
"expectedBids": [{
106+
"bid": {
107+
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
108+
"id": "some_test_ad_id",
109+
"impid": "some_test_ad_id",
110+
"ttl": 300,
111+
"crid": "94395500",
112+
"w": 300,
113+
"price": 2.942808,
114+
"adid": "94395500",
115+
"h": 250
116+
},
117+
"type": "banner"
118+
}]
119+
}

adapters/emx_digital/emx_digitaltest/exemplary/minimal-banner.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
"w": 300,
6464
"h": 250
6565
},
66+
"ext": {
67+
"bidder": {
68+
"tagid": "25251"
69+
}
70+
},
6671
"tagid": "25251",
6772
"secure": 0
6873
}],
@@ -85,7 +90,7 @@
8590
"seat": "12356",
8691
"bid": [{
8792
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
88-
"id": "uuid",
93+
"id": "some_test_ad_id",
8994
"impid": "some_test_ad_id",
9095
"ttl": 300,
9196
"crid": "94395500",
@@ -103,7 +108,7 @@
103108
"expectedBids": [{
104109
"bid": {
105110
"adm": "<div id=\"123456789_ad\"><script>!function(){console.log\"Hello, world.\";}();<\/script><\/div>",
106-
"id": "uuid",
111+
"id": "some_test_ad_id",
107112
"impid": "some_test_ad_id",
108113
"ttl": 300,
109114
"crid": "94395500",
@@ -114,4 +119,4 @@
114119
},
115120
"type": "banner"
116121
}]
117-
}
122+
}

0 commit comments

Comments
 (0)