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

DMX: Enforcing w and h in imp #1778

Merged
merged 12 commits into from
Mar 31, 2021
Merged
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
50 changes: 40 additions & 10 deletions adapters/dmx/dmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type dmxParams struct {
Bidfloor float64 `json:"bidfloor,omitempty"`
}

var protocols = []openrtb2.Protocol{2, 3, 5, 6, 7, 8}

func UserSellerOrPubId(str1, str2 string) string {
if str1 != "" {
return str1
Expand Down Expand Up @@ -100,6 +102,12 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
if dmxReq.App.ID != "" {
anyHasId = true
}
if anyHasId == false {
if idfa, valid := getIdfa(request); valid {
stevealliance marked this conversation as resolved.
Show resolved Hide resolved
dmxReq.App.ID = idfa
anyHasId = true
}
}
} else {
dmxReq.App = nil
}
Expand Down Expand Up @@ -147,13 +155,7 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
}
}

if anyHasId == false {
return nil, []error{errors.New("This request contained no identifier")}
}

for _, inst := range dmxReq.Imp {
var banner *openrtb2.Banner
var video *openrtb2.Video
var ins openrtb2.Imp
var params dmxExt
const intVal int8 = 1
Expand All @@ -164,19 +166,19 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
if isDmxParams(params.Bidder) {
if inst.Banner != nil {
if len(inst.Banner.Format) != 0 {
banner = inst.Banner
bannerCopy := *inst.Banner
if params.Bidder.PublisherId != "" || params.Bidder.MemberId != "" {
imps = fetchParams(params, inst, ins, imps, banner, nil, intVal)
imps = fetchParams(params, inst, ins, imps, &bannerCopy, nil, intVal)
} else {
return nil, []error{errors.New("Missing Params for auction to be send")}
}
}
}

if inst.Video != nil {
video = inst.Video
videoCopy := *inst.Video
if params.Bidder.PublisherId != "" || params.Bidder.MemberId != "" {
imps = fetchParams(params, inst, ins, imps, nil, video, intVal)
imps = fetchParams(params, inst, ins, imps, nil, &videoCopy, intVal)
} else {
return nil, []error{errors.New("Missing Params for auction to be send")}
}
Expand All @@ -187,6 +189,10 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt

dmxReq.Imp = imps

if anyHasId == false {
stevealliance marked this conversation as resolved.
Show resolved Hide resolved
return nil, []error{errors.New("This request contained no identifier")}
}

oJson, err := json.Marshal(dmxReq)

if err != nil {
Expand Down Expand Up @@ -271,10 +277,15 @@ func fetchParams(params dmxExt, inst openrtb2.Imp, ins openrtb2.Imp, imps []open
tempimp.Secure = &intVal
}
if banner != nil {
if banner.H == nil || banner.W == nil {
banner.H = &banner.Format[0].H
stevealliance marked this conversation as resolved.
Show resolved Hide resolved
banner.W = &banner.Format[0].W
}
stevealliance marked this conversation as resolved.
Show resolved Hide resolved
tempimp.Banner = banner
}

if video != nil {
video.Protocols = checkProtocols(video)
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
tempimp.Video = video
}

Expand Down Expand Up @@ -327,3 +338,22 @@ func isDmxParams(t interface{}) bool {
return false
}
}

func getIdfa(request *openrtb2.BidRequest) (string, bool) {
if request.Device == nil {
return "", false
}

device := request.Device

if device.IFA != "" {
return device.IFA, true
}
return "", false
}
stevealliance marked this conversation as resolved.
Show resolved Hide resolved
func checkProtocols(imp *openrtb2.Video) []openrtb2.Protocol {
if len(imp.Protocols) > 0 {
return imp.Protocols
}
return protocols
}
148 changes: 148 additions & 0 deletions adapters/dmx/dmxtest/exemplary/idfa-to-app-id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app":{
"bundle":"302324249",
"name":"Skout - iOS Match Buy",
"publisher":{
"id":"10400"
},
"storeurl":"https://itunes.apple.com/app/id302324249"
},
"device": {
"ifa": "ed6207cefff74c14878963566683c070"
},
"imp": [
{

"id": "test-imp-id",
"banner": {
"w": 300,
"h": 250,
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"dmxid": "123454",
"publisher_id": "10400"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "",
"body": {
"id": "test-request-id",
"app":{
"bundle":"302324249",
"id":"ed6207cefff74c14878963566683c070",
"name":"Skout - iOS Match Buy",
"publisher":{
"id":"10400",
"ext": {
"dmx": {
"id": "10400"
}
}
},
"storeurl":"https://itunes.apple.com/app/id302324249"
},
"device": {
"ifa": "ed6207cefff74c14878963566683c070"
},
"imp": [
{
"id": "test-imp-id",
"tagid": "123454",
"secure": 1,
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
],
"w": 300,
"h": 250
},
"ext": {
"bidder": {
"publisher_id": "10400",
"dmxid": "123454"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "958",
"bid": [{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 1.75,
"adid": "29681110",
"adm": "<div>banner-ads</div>",
"adomain": ["dmx.districtm.io"],
"iurl": "https://dmx.districtm.io/b/v2",
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300
}]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 1.75,
"adm": "<div>banner-ads</div>",
"adid": "29681110",
"adomain": ["dmx.districtm.io"],
"iurl": "https://dmx.districtm.io/b/v2",
"cid": "958",
"crid": "29681110",
"w": 300,
"h": 250

},
"type": "banner"
}
]
}
]
}
Loading