Skip to content

Commit

Permalink
Adapter Name Case Insensitive: alternate bidder codes (prebid#3229)
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon authored Oct 20, 2023
1 parent 53e0adc commit 6b98a81
Show file tree
Hide file tree
Showing 5 changed files with 683 additions and 19 deletions.
272 changes: 272 additions & 0 deletions exchange/exchangetest/alternate-bidder-codes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"incomingRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "imp-id-1",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"prebid": {
"bidder": {
"pubmatic": {
"publisherId": 5890
},
"appnexus": {
"placementId": 1
}
}
}
}
}
],
"ext": {
"prebid": {
"alternatebiddercodes": {
"enabled": true,
"bidders": {
"PUBmatic": {
"enabled": true,
"allowedbiddercodes": [
"groupm"
]
}
}
}
}
}
}
},
"outgoingRequests": {
"pubmatic": {
"expectRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "imp-id-1",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"bidder": {
"publisherId": 5890
}
}
}
],
"ext": {
"prebid": {
"alternatebiddercodes": {
"enabled": true,
"bidders": {
"pubmatic": {
"enabled": true,
"allowedbiddercodes": [
"groupm"
]
}
}
}
}
}
}
},
"mockResponse": {
"pbsSeatBids": [
{
"pbsBids": [
{
"ortbBid": {
"id": "pubmatic-bid-1",
"impid": "imp-id-1",
"price": 0.71
},
"bidType": "video",
"bidMeta": {
"adaptercode": "pubmatic"
}
}
],
"seat": "pubmatic"
},
{
"pbsBids": [
{
"ortbBid": {
"id": "pubmatic-bid-2",
"impid": "imp-id-1",
"price": 0.51
},
"bidType": "video",
"bidMeta": {
"adaptercode": "pubmatic"
}
}
],
"seat": "groupm"
}
]
}
},
"appnexus": {
"expectRequest": {
"ortbRequest": {
"id": "some-request-id",
"site": {
"page": "test.somepage.com"
},
"imp": [
{
"id": "imp-id-1",
"video": {
"mimes": [
"video/mp4"
]
},
"ext": {
"bidder": {
"placementId": 1
}
}
}
],
"ext": {
"prebid": {
"alternatebiddercodes": {
"enabled": true,
"bidders": null
}
}
}
}
},
"mockResponse": {
"pbsSeatBids": [
{
"pbsBids": [
{
"ortbBid": {
"id": "appnexus-bid-1",
"impid": "imp-id-1",
"price": 0.3
},
"bidType": "banner",
"bidMeta": {
"adaptercode": "appnexus"
}
}
],
"seat": "appnexus"
},
{
"pbsBids": [
{
"ortbBid": {
"id": "appnexus-bid-2",
"impid": "imp-id-1",
"price": 0.3
},
"bidType": "banner",
"bidMeta": {
"adaptercode": "appnexus"
}
}
],
"seat": "groupm"
}
]
}
}
},
"response": {
"bids": {
"id": "some-request-id",
"seatbid": [
{
"seat": "groupm",
"bid": [
{
"id": "pubmatic-bid-2",
"impid": "imp-id-1",
"price": 0.51,
"ext": {
"origbidcpm": 0.51,
"prebid": {
"meta": {
"adaptercode": "pubmatic"
},
"type": "video"
}
}
},
{
"id": "appnexus-bid-2",
"impid": "imp-id-1",
"price": 0.3,
"ext": {
"origbidcpm": 0.3,
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
]
},
{
"seat": "pubmatic",
"bid": [
{
"id": "pubmatic-bid-1",
"impid": "imp-id-1",
"price": 0.71,
"ext": {
"origbidcpm": 0.71,
"prebid": {
"meta": {
"adaptercode": "pubmatic"
},
"type": "video"
}
}
}
]
},
{
"seat": "appnexus",
"bid": [
{
"id": "appnexus-bid-1",
"impid": "imp-id-1",
"price": 0.3,
"ext": {
"origbidcpm": 0.3,
"prebid": {
"meta": {
"adaptercode": "appnexus"
},
"type": "banner"
}
}
}
]
}
]
}
}
}
30 changes: 16 additions & 14 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,30 +442,32 @@ func buildRequestExtForBidder(bidder string, requestExt json.RawMessage, request
}

func buildRequestExtAlternateBidderCodes(bidder string, accABC *openrtb_ext.ExtAlternateBidderCodes, reqABC *openrtb_ext.ExtAlternateBidderCodes) *openrtb_ext.ExtAlternateBidderCodes {
if reqABC != nil {
alternateBidderCodes := &openrtb_ext.ExtAlternateBidderCodes{
Enabled: reqABC.Enabled,
}
if bidderCodes, ok := reqABC.Bidders[bidder]; ok {
alternateBidderCodes.Bidders = map[string]openrtb_ext.ExtAdapterAlternateBidderCodes{
bidder: bidderCodes,
}
}
return alternateBidderCodes

if altBidderCodes := copyExtAlternateBidderCodes(bidder, reqABC); altBidderCodes != nil {
return altBidderCodes
}

if accABC != nil {
if altBidderCodes := copyExtAlternateBidderCodes(bidder, accABC); altBidderCodes != nil {
return altBidderCodes
}

return nil
}

func copyExtAlternateBidderCodes(bidder string, altBidderCodes *openrtb_ext.ExtAlternateBidderCodes) *openrtb_ext.ExtAlternateBidderCodes {
if altBidderCodes != nil {
alternateBidderCodes := &openrtb_ext.ExtAlternateBidderCodes{
Enabled: accABC.Enabled,
Enabled: altBidderCodes.Enabled,
}
if bidderCodes, ok := accABC.Bidders[bidder]; ok {

if bidderCodes, ok := altBidderCodes.IsBidderInAlternateBidderCodes(bidder); ok {
alternateBidderCodes.Bidders = map[string]openrtb_ext.ExtAdapterAlternateBidderCodes{
bidder: bidderCodes,
}
}

return alternateBidderCodes
}

return nil
}

Expand Down
Loading

0 comments on commit 6b98a81

Please sign in to comment.