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

Fixes audienceNetwork adapter ignoring banner.format sizes. #1164

Merged
merged 2 commits into from
Jan 14, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"mockBidRequest": {
"id": "test-req-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 640,
"h": 480
},
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"publisherid": "123",
"placementid": "456"
}
}
}
],
"site": {
"domain": "prebid.org",
"page": "prebid.org"
},
"device": {
"ip": "152.193.6.74"
},
"user": {
"id": "db089de9-a62e-4861-a881-0ff15e052516",
"buyeruid": "v4_bidder_token"
},
"tmax": 500
},
"httpcalls": [
{
"expectedRequest": {
"uri": "https://an.facebook.com/placementbid.ortb",
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"X-Fb-Pool-Routing-Token": [
"v4_bidder_token"
]
},
"body": {
"id": "test-req-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"w": -1,
"h": 250
},
"tagid": "123_456"
}
],
"ext": {
"appnexus": {
"hb_source": 5
},
"prebid": {}
},
"site": {
"domain": "prebid.org",
"page": "prebid.org",
"publisher": {
"id": "123"
}
},
"device": {
"ip": "152.193.6.74"
},
"user": {
"id": "db089de9-a62e-4861-a881-0ff15e052516",
"buyeruid": "v4_bidder_token"
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"seatbid": [
{
"bid": [
{
"id": "987",
"impid": "test-imp-id",
"price": 1.000000,
"adm": "{\"type\":\"ID\",\"bid_id\":\"987\",\"placement_id\":\"123_456\",\"resolved_placement_id\":\"123_456\",\"sdk_version\":\"5.5.0\",\"device_id\":\"abc\",\"template\":1,\"payload\":null,\"bid_time_token\":\"v4_bidder_token=\"}",
"nurl": "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=def&placement=456&auction=123&impression=123&request=123478&bid=987&ortb_loss_code=0&clearing_price=${AUCTION_PRICE}&app_version=iOS-1.0",
"lurl": "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=def&placement=456&auction=123&impression=123&request=123478&bid=987&ortb_loss_code=${AUCTION_LOSS}&clearing_price=${AUCTION_PRICE}&app_version=iOS-1.0",
"burl": "https://www.facebook.com/audiencenetwork/burl/?partner=test-platform-id&app=def&placement=456&auction=123&impression=123&request=123478&bid=987&clearing_price=${AUCTION_PRICE}"
}
]
}
],
"bidid": "654",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "987",
"impid": "test-imp-id",
"price": 1,
"adm": "{\"type\":\"ID\",\"bid_id\":\"987\",\"placement_id\":\"123_456\",\"resolved_placement_id\":\"123_456\",\"sdk_version\":\"5.5.0\",\"device_id\":\"abc\",\"template\":1,\"payload\":null,\"bid_time_token\":\"v4_bidder_token=\"}",
"adid": "987",
"crid": "987",
"nurl": "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=def&placement=456&auction=123&impression=123&request=123478&bid=987&ortb_loss_code=0&clearing_price=${AUCTION_PRICE}&app_version=iOS-1.0",
"lurl": "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=def&placement=456&auction=123&impression=123&request=123478&bid=987&ortb_loss_code=${AUCTION_LOSS}&clearing_price=${AUCTION_PRICE}&app_version=iOS-1.0",
"burl": "https://www.facebook.com/audiencenetwork/burl/?partner=test-platform-id&app=def&placement=456&auction=123&impression=123&request=123478&bid=987&clearing_price=${AUCTION_PRICE}"
},
"type": "banner"
}
]
}
]
}
13 changes: 11 additions & 2 deletions adapters/audienceNetwork/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,17 @@ func (this *FacebookAdapter) modifyImp(out *openrtb.Imp) error {
}

if out.Banner.H == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("imp #%s: banner height required", out.ID),
for _, f := range out.Banner.Format {
if _, ok := supportedBannerHeights[f.H]; ok {
h := f.H
out.Banner.H = &h
break
}
}
if out.Banner.H == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("imp #%s: banner height required", out.ID),
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nitpick but we can avoid one extra lookup operation is we use an else statement instead

162 func (this *FacebookAdapter) modifyImp(out *openrtb.Imp) error {
163     impType, ok := resolveImpType(out)
164 +-- 22 lines: if !ok {------------------------------------------
186         if out.Banner.H == nil {
187             for _, f := range out.Banner.Format {
188                 if _, ok := supportedBannerHeights[f.H]; ok {
189                     h := f.H
190                     out.Banner.H = &h
191                     break
192                 }
193             }
194             if out.Banner.H == nil {
195                 return &errortypes.BadInput{
196                     Message: fmt.Sprintf("imp #%s: banner height required", out.ID),
197                 }
198             }
199 -       }
200 -
201 -       if _, ok := supportedBannerHeights[*out.Banner.H]; !ok {
202 +       } else if _, ok := supportedBannerHeights[*out.Banner.H]; !ok {
203             return &errortypes.BadInput{
204                 Message: fmt.Sprintf("imp #%s: only banner heights 50 and 250 are supported", out.ID),
205             }
206         }
207
208         /* This will get overwritten post-serialization */
209         out.Banner.W = openrtb.Uint64Ptr(0)
210         out.Banner.Format = nil
211         break
212     }
213
214     return nil
215 }
adapters/audienceNetwork/facebook.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, that will save one hash table lookup under certain circumstances. :)

Expand Down