diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go index 7c112670c..e35229143 100644 --- a/adapters/pubmatic/pubmatic.go +++ b/adapters/pubmatic/pubmatic.go @@ -24,6 +24,8 @@ const MAX_IMPRESSIONS_PUBMATIC = 30 const ae = "ae" +const BidderPubMatic = "pubmatic" + type PubmaticAdapter struct { URI string bidderName string @@ -37,8 +39,9 @@ type pubmaticBidExt struct { } type pubmaticWrapperExt struct { - ProfileID int `json:"profile,omitempty"` - VersionID int `json:"version,omitempty"` + ProfileID int `json:"profile,omitempty"` + VersionID int `json:"version,omitempty"` + BidderCode string `json:"biddercode,omitempty"` } type pubmaticBidExtVideo struct { @@ -386,6 +389,19 @@ func extractPubmaticExtFromRequest(request *openrtb2.BidRequest) (extRequestAdSe pmReqExt.Wrapper = wrpExt } + if pmReqExt.Wrapper == nil { + pmReqExt.Wrapper = &pubmaticWrapperExt{} + } + + // Always set bidder code to default + pmReqExt.Wrapper.BidderCode = BidderPubMatic + + // Override bidder code if alias exists + for alias := range reqExt.Prebid.Aliases { + pmReqExt.Wrapper.BidderCode = alias + break + } + if acatBytes, ok := reqExtBidderParams["acat"]; ok { var acat []string err = jsonutil.Unmarshal(acatBytes, &acat) diff --git a/adapters/pubmatic/pubmatic_test.go b/adapters/pubmatic/pubmatic_test.go index d26754c8c..ac1e645c1 100644 --- a/adapters/pubmatic/pubmatic_test.go +++ b/adapters/pubmatic/pubmatic_test.go @@ -285,7 +285,7 @@ func TestExtractPubmaticExtFromRequest(t *testing.T) { Ext: json.RawMessage(`{"prebid":{"bidderparams":{}}}`), }, }, - expectedReqExt: extRequestAdServer{}, + expectedReqExt: extRequestAdServer{Wrapper: &pubmaticWrapperExt{ProfileID: 0, VersionID: 0, BidderCode: "pubmatic"}}, wantErr: false, }, { @@ -296,7 +296,7 @@ func TestExtractPubmaticExtFromRequest(t *testing.T) { }, }, expectedReqExt: extRequestAdServer{ - Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456}, + Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456, BidderCode: "pubmatic"}, }, wantErr: false, }, @@ -317,7 +317,7 @@ func TestExtractPubmaticExtFromRequest(t *testing.T) { }, }, expectedReqExt: extRequestAdServer{ - Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456}, + Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456, BidderCode: "pubmatic"}, Acat: []string{"drg", "dlu", "ssr"}, }, wantErr: false, @@ -330,7 +330,7 @@ func TestExtractPubmaticExtFromRequest(t *testing.T) { }, }, expectedReqExt: extRequestAdServer{ - Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456}, + Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456, BidderCode: "pubmatic"}, }, wantErr: true, }, @@ -343,7 +343,31 @@ func TestExtractPubmaticExtFromRequest(t *testing.T) { }, expectedReqExt: extRequestAdServer{ Marketplace: &marketplaceReqExt{AllowedBidders: []string{"pubmatic", "groupm"}}, - Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456}, + Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456, BidderCode: "pubmatic"}, + }, + wantErr: false, + }, + { + name: "Valid_request_ext_with_alias", + args: args{ + request: &openrtb2.BidRequest{ + Ext: json.RawMessage(`{"prebid":{"aliases":{"pubmatic-1":"pubmatic"},"bidderparams":{"wrapper":{"profile":123,"version":456}}}}`), + }, + }, + expectedReqExt: extRequestAdServer{ + Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456, BidderCode: "pubmatic-1"}, + }, + wantErr: false, + }, + { + name: "Valid_request_ext_with_empty_alias", + args: args{ + request: &openrtb2.BidRequest{ + Ext: json.RawMessage(`{"prebid":{"aliases":{},"bidderparams":{"wrapper":{"profile":123,"version":456}}}}`), + }, + }, + expectedReqExt: extRequestAdServer{ + Wrapper: &pubmaticWrapperExt{ProfileID: 123, VersionID: 456, BidderCode: "pubmatic"}, }, wantErr: false, }, diff --git a/adapters/pubmatic/pubmatictest/exemplary/banner.json b/adapters/pubmatic/pubmatictest/exemplary/banner.json index af6c70f11..f371349dc 100644 --- a/adapters/pubmatic/pubmatictest/exemplary/banner.json +++ b/adapters/pubmatic/pubmatictest/exemplary/banner.json @@ -86,7 +86,8 @@ "ext": { "wrapper": { "profile": 5123, - "version":1 + "version":1, + "biddercode":"pubmatic" }, "acat": ["drg","dlu","ssr"] } diff --git a/adapters/pubmatic/pubmatictest/exemplary/native.json b/adapters/pubmatic/pubmatictest/exemplary/native.json index e154ae995..e054a10a4 100644 --- a/adapters/pubmatic/pubmatictest/exemplary/native.json +++ b/adapters/pubmatic/pubmatictest/exemplary/native.json @@ -55,7 +55,8 @@ "ext": { "wrapper": { "profile": 5123, - "version": 1 + "version": 1, + "biddercode":"pubmatic" } } }, diff --git a/adapters/pubmatic/pubmatictest/exemplary/video.json b/adapters/pubmatic/pubmatictest/exemplary/video.json index c92c97dd3..a3e4ec22f 100644 --- a/adapters/pubmatic/pubmatictest/exemplary/video.json +++ b/adapters/pubmatic/pubmatictest/exemplary/video.json @@ -97,7 +97,8 @@ "ext": { "wrapper": { "profile": 5123, - "version":1 + "version":1, + "biddercode":"pubmatic" }, "acat": ["drg","dlu","ssr"] } diff --git a/adapters/pubmatic/pubmatictest/supplemental/bid_ext_ibv_true.json b/adapters/pubmatic/pubmatictest/supplemental/bid_ext_ibv_true.json index b994a0080..f4d3cc7b7 100644 --- a/adapters/pubmatic/pubmatictest/supplemental/bid_ext_ibv_true.json +++ b/adapters/pubmatic/pubmatictest/supplemental/bid_ext_ibv_true.json @@ -97,7 +97,8 @@ "ext": { "wrapper": { "profile": 5123, - "version":1 + "version":1, + "biddercode":"pubmatic" }, "acat": ["drg","dlu","ssr"] } diff --git a/adapters/pubmatic/pubmatictest/supplemental/extra-bid.json b/adapters/pubmatic/pubmatictest/supplemental/extra-bid.json index b6f2b53ec..3cdb3b7f0 100644 --- a/adapters/pubmatic/pubmatictest/supplemental/extra-bid.json +++ b/adapters/pubmatic/pubmatictest/supplemental/extra-bid.json @@ -97,7 +97,8 @@ "ext": { "wrapper": { "profile": 5123, - "version":1 + "version":1, + "biddercode":"pubmatic" }, "acat": ["drg","dlu","ssr"], "marketplace": { diff --git a/adapters/pubmatic/pubmatictest/supplemental/native_invalid_adm.json b/adapters/pubmatic/pubmatictest/supplemental/native_invalid_adm.json index 052409415..a28a47097 100644 --- a/adapters/pubmatic/pubmatictest/supplemental/native_invalid_adm.json +++ b/adapters/pubmatic/pubmatictest/supplemental/native_invalid_adm.json @@ -55,7 +55,8 @@ "ext": { "wrapper": { "profile": 5123, - "version": 1 + "version": 1, + "biddercode":"pubmatic" } } }, diff --git a/adapters/pubmatic/pubmatictest/supplemental/nilReqExt.json b/adapters/pubmatic/pubmatictest/supplemental/nilReqExt.json index e5a119f9c..ea7a62b79 100644 --- a/adapters/pubmatic/pubmatictest/supplemental/nilReqExt.json +++ b/adapters/pubmatic/pubmatictest/supplemental/nilReqExt.json @@ -89,7 +89,8 @@ "ext": { "wrapper": { "profile": 5123, - "version": 1 + "version": 1, + "biddercode":"pubmatic" } } }, diff --git a/adapters/pubmatic/pubmatictest/supplemental/reqBidderParams.json b/adapters/pubmatic/pubmatictest/supplemental/reqBidderParams.json index cc1cc136a..dbc0ae5cf 100644 --- a/adapters/pubmatic/pubmatictest/supplemental/reqBidderParams.json +++ b/adapters/pubmatic/pubmatictest/supplemental/reqBidderParams.json @@ -98,7 +98,8 @@ "ext": { "wrapper": { "profile": 1234, - "version": 2 + "version": 2, + "biddercode":"pubmatic" } } }, diff --git a/adapters/pubmatic/pubmatictest/supplemental/reqExtPrebidAliases.json b/adapters/pubmatic/pubmatictest/supplemental/reqExtPrebidAliases.json new file mode 100644 index 000000000..96787f0d3 --- /dev/null +++ b/adapters/pubmatic/pubmatictest/supplemental/reqExtPrebidAliases.json @@ -0,0 +1,176 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ] + }, + "ext": { + "bidder": { + "adSlot": "AdTag_Div1@300x250", + "publisherId": " 999 ", + "keywords": [ + { + "key": "pmZoneID", + "value": [ + "Zone1", + "Zone2" + ] + }, + { + "key": "preference", + "value": [ + "sports", + "movies" + ] + } + ], + "wrapper": { + "version": 1, + "profile": 5123 + } + } + } + } + ], + "device": { + "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + }, + "ext": { + "prebid": { + "aliases": { + "pubmatic-alias": "pubmatic" + }, + "bidderparams": { + "wrapper": { + "profile": 1234, + "version": 2 + } + } + } + }, + "site": { + "id": "siteID", + "publisher": { + "id": "1234" + } + } + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + "body": { + "id": "test-request-id", + "imp": [ + { + "id": "test-imp-id", + "tagid": "AdTag_Div1", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + } + ], + "h": 250, + "w": 300 + }, + "ext": { + "pmZoneId": "Zone1,Zone2", + "preference": "sports,movies" + } + } + ], + "device": { + "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + }, + "site": { + "id": "siteID", + "publisher": { + "id": "999" + } + }, + "ext": { + "wrapper": { + "profile": 1234, + "version": 2, + "biddercode": "pubmatic-alias" + } + } + }, + "impIDs": ["test-imp-id"] + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [ + { + "seat": "958", + "bid": [ + { + "id": "7706636740145184841", + "impid": "test-imp-id", + "price": 0.500000, + "adid": "29681110", + "adm": "some-test-ad", + "adomain": [ + "pubmatic.com" + ], + "crid": "29681110", + "h": 250, + "w": 300, + "dealid": "test deal", + "mtype": 1, + "ext": { + "dspid": 6, + "deal_channel": 1 + } + } + ] + } + ], + "bidid": "5778926625248726496", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "7706636740145184841", + "impid": "test-imp-id", + "price": 0.5, + "adid": "29681110", + "adm": "some-test-ad", + "adomain": [ + "pubmatic.com" + ], + "crid": "29681110", + "w": 300, + "h": 250, + "dealid": "test deal", + "mtype": 1, + "ext": { + "dspid": 6, + "deal_channel": 1 + } + }, + "type": "banner" + } + ] + } + ] +} diff --git a/exchange/exchangetest/aliases.json b/exchange/exchangetest/aliases.json index 239e80b59..5b27e6c75 100644 --- a/exchange/exchangetest/aliases.json +++ b/exchange/exchangetest/aliases.json @@ -97,7 +97,14 @@ } } } - ] + ], + "ext": { + "prebid": { + "aliases": { + "districtm": "appnexus" + } + } + } } }, "mockResponse": { diff --git a/exchange/exchangetest/bidadjustmentfactors.json b/exchange/exchangetest/bidadjustmentfactors.json index 84e0148ba..028190654 100644 --- a/exchange/exchangetest/bidadjustmentfactors.json +++ b/exchange/exchangetest/bidadjustmentfactors.json @@ -96,7 +96,14 @@ } } } - ] + ], + "ext": { + "prebid": { + "aliases": { + "districtm": "appnexus" + } + } + } }, "bidAdjustments": { "appnexus": 2.5, diff --git a/exchange/exchangetest/buyeruid_case_insensitive.json b/exchange/exchangetest/buyeruid_case_insensitive.json index 6999e8c95..a080fdb3c 100644 --- a/exchange/exchangetest/buyeruid_case_insensitive.json +++ b/exchange/exchangetest/buyeruid_case_insensitive.json @@ -74,7 +74,14 @@ } } } - ] + ], + "ext": { + "prebid": { + "aliases": { + "APPnexus": "appnexus" + } + } + } } } }, @@ -103,7 +110,14 @@ } } } - ] + ], + "ext": { + "prebid": { + "aliases": { + "appNEXUS": "appnexus" + } + } + } } } }, diff --git a/exchange/exchangetest/eidpermissions-allowed-alias.json b/exchange/exchangetest/eidpermissions-allowed-alias.json index 886927723..2dee83fb5 100644 --- a/exchange/exchangetest/eidpermissions-allowed-alias.json +++ b/exchange/exchangetest/eidpermissions-allowed-alias.json @@ -93,7 +93,14 @@ } } } - ] + ], + "ext": { + "prebid": { + "aliases": { + "foo": "appnexus" + } + } + } } }, "mockResponse": { diff --git a/exchange/exchangetest/tricky-userids.json b/exchange/exchangetest/tricky-userids.json index 180415db2..087b2e71a 100644 --- a/exchange/exchangetest/tricky-userids.json +++ b/exchange/exchangetest/tricky-userids.json @@ -147,7 +147,14 @@ } } } - ] + ], + "ext": { + "prebid": { + "aliases": { + "districtm": "appnexus" + } + } + } } }, "mockResponse": { diff --git a/exchange/utils.go b/exchange/utils.go index 3b88f3d86..9659f1957 100644 --- a/exchange/utils.go +++ b/exchange/utils.go @@ -506,6 +506,14 @@ func buildRequestExtForBidder(bidder string, req *openrtb_ext.RequestWrapper, re AlternateBidderCodes: alternateBidderCodes, } + if prebid != nil && prebid.Aliases != nil { + if aliasValue, ok := prebid.Aliases[bidder]; ok { + prebidNew.Aliases = map[string]string{ + bidder: aliasValue, + } + } + } + // Copy Allowed Fields // Per: https://docs.prebid.org/prebid-server/endpoints/openrtb2/pbs-endpoint-auction.html#prebid-server-ortb2-extension-summary if prebid != nil { diff --git a/exchange/utils_test.go b/exchange/utils_test.go index 992099265..68c82a5cd 100644 --- a/exchange/utils_test.go +++ b/exchange/utils_test.go @@ -2752,6 +2752,11 @@ func TestBuildRequestExtForBidder(t *testing.T) { requestExt: json.RawMessage(`{"prebid":{"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":20,"increment":0.1}]},"mediatypepricegranularity":{},"includebidderkeys":true,"includewinners":true,"includebrandcategory":{"primaryadserver":1,"publisher":"anyPublisher","withcategory":true}}}}`), expectedJson: json.RawMessage(`{"prebid":{"targeting":{"includebrandcategory":{"primaryadserver":1,"publisher":"anyPublisher","withcategory":true}}}}`), }, + { + name: "request_ext_with_aliase", + requestExt: json.RawMessage(`{"prebid":{"aliases":{"foo":"pubmatic", "bar":"pubmatic"}}}`), + expectedJson: json.RawMessage(`{"prebid":{"aliases":{"foo":"pubmatic"}}}`), + }, } for _, test := range testCases {