From cc4a376f026e268173358cb34aca3290a641395f Mon Sep 17 00:00:00 2001 From: bjorn-lw <32431346+bjorn-lw@users.noreply.github.com> Date: Mon, 29 Nov 2021 22:08:48 +0100 Subject: [PATCH] Adform adapter lacked gross/net parameter support (#2084) --- adapters/adf/adf.go | 30 ++++ ...gle-banner-pricetype-gross-extend-ext.json | 122 ++++++++++++++ .../single-banner-pricetype-gross.json | 112 +++++++++++++ .../single-banner-pricetype-net.json | 112 +++++++++++++ ...nners-different-pricetypes-extend-ext.json | 151 ++++++++++++++++++ .../two-banners-different-pricetypes.json | 141 ++++++++++++++++ adapters/adf/params_test.go | 3 + openrtb_ext/imp_adf.go | 1 + static/bidder-params/adf.json | 5 + static/bidder-params/adform.json | 5 + 10 files changed, 682 insertions(+) create mode 100644 adapters/adf/adftest/exemplary/single-banner-pricetype-gross-extend-ext.json create mode 100644 adapters/adf/adftest/exemplary/single-banner-pricetype-gross.json create mode 100644 adapters/adf/adftest/exemplary/single-banner-pricetype-net.json create mode 100644 adapters/adf/adftest/exemplary/two-banners-different-pricetypes-extend-ext.json create mode 100644 adapters/adf/adftest/exemplary/two-banners-different-pricetypes.json diff --git a/adapters/adf/adf.go b/adapters/adf/adf.go index 8014bd5bb56..bc54f78f187 100644 --- a/adapters/adf/adf.go +++ b/adapters/adf/adf.go @@ -16,6 +16,11 @@ type adapter struct { endpoint string } +type adfRequestExt struct { + openrtb_ext.ExtRequest + PriceType string `json:"pt"` +} + // Builder builds a new instance of the Adf adapter for the given bidder with the given config. func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) { bidder := &adapter{ @@ -27,6 +32,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { var errors []error var validImps = make([]openrtb2.Imp, 0, len(request.Imp)) + priceType := "" for _, imp := range request.Imp { var bidderExt adapters.ExtImpBidder @@ -47,6 +53,30 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte imp.TagID = adfImpExt.MasterTagID.String() validImps = append(validImps, imp) + + // If imps specify priceType they should all be the same. If they differ, only the first one will be used + if adfImpExt.PriceType != "" && priceType == "" { + priceType = adfImpExt.PriceType + } + } + + if priceType != "" { + requestExt := adfRequestExt{} + var err error + + if len(request.Ext) > 0 { + if err = json.Unmarshal(request.Ext, &requestExt); err != nil { + errors = append(errors, err) + } + } + + if err == nil { + requestExt.PriceType = priceType + + if request.Ext, err = json.Marshal(&requestExt); err != nil { + errors = append(errors, err) + } + } } request.Imp = validImps diff --git a/adapters/adf/adftest/exemplary/single-banner-pricetype-gross-extend-ext.json b/adapters/adf/adftest/exemplary/single-banner-pricetype-gross-extend-ext.json new file mode 100644 index 00000000000..0cd03c75bb5 --- /dev/null +++ b/adapters/adf/adftest/exemplary/single-banner-pricetype-gross-extend-ext.json @@ -0,0 +1,122 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "ext":{ + "prebid":{ + "aliases":{ + "adfalias": "adf" + } + } + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://adx.adform.net/adx/openrtb", + "body": { + "id": "test-request-id", + "ext": { + "prebid":{ + "aliases":{ + "adfalias": "adf" + } + }, + "pt": "gross" + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828782" + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [{ + "bid": [{ + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "adomain": [ "test.com" ], + "crid": "test-creative-id", + "ext": { + "prebid": { + "type": "banner" + } + } + }] + }], + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "currency": "USD", + "bids": [ + { + "bid": { + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "crid": "test-creative-id", + "adomain": [ "test.com" ], + "ext": { + "prebid": { + "type": "banner" + } + } + }, + "type": "banner" + } + ] + }] +} diff --git a/adapters/adf/adftest/exemplary/single-banner-pricetype-gross.json b/adapters/adf/adftest/exemplary/single-banner-pricetype-gross.json new file mode 100644 index 00000000000..2fb7cf24c5a --- /dev/null +++ b/adapters/adf/adftest/exemplary/single-banner-pricetype-gross.json @@ -0,0 +1,112 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://adx.adform.net/adx/openrtb", + "body": { + "id": "test-request-id", + "ext": { + "prebid": { + }, + "pt": "gross" + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828782" + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [{ + "bid": [{ + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "adomain": [ "test.com" ], + "crid": "test-creative-id", + "ext": { + "prebid": { + "type": "banner" + } + } + }] + }], + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "currency": "USD", + "bids": [ + { + "bid": { + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "crid": "test-creative-id", + "adomain": [ "test.com" ], + "ext": { + "prebid": { + "type": "banner" + } + } + }, + "type": "banner" + } + ] + }] +} diff --git a/adapters/adf/adftest/exemplary/single-banner-pricetype-net.json b/adapters/adf/adftest/exemplary/single-banner-pricetype-net.json new file mode 100644 index 00000000000..cb4b5f8a1f4 --- /dev/null +++ b/adapters/adf/adftest/exemplary/single-banner-pricetype-net.json @@ -0,0 +1,112 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "net" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://adx.adform.net/adx/openrtb", + "body": { + "id": "test-request-id", + "ext": { + "prebid": { + }, + "pt": "net" + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "net" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828782" + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [{ + "bid": [{ + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "adomain": [ "test.com" ], + "crid": "test-creative-id", + "ext": { + "prebid": { + "type": "banner" + } + } + }] + }], + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "currency": "USD", + "bids": [ + { + "bid": { + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "crid": "test-creative-id", + "adomain": [ "test.com" ], + "ext": { + "prebid": { + "type": "banner" + } + } + }, + "type": "banner" + } + ] + }] +} diff --git a/adapters/adf/adftest/exemplary/two-banners-different-pricetypes-extend-ext.json b/adapters/adf/adftest/exemplary/two-banners-different-pricetypes-extend-ext.json new file mode 100644 index 00000000000..59e380d5f2e --- /dev/null +++ b/adapters/adf/adftest/exemplary/two-banners-different-pricetypes-extend-ext.json @@ -0,0 +1,151 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "ext":{ + "prebid":{ + "aliases":{ + "adfalias": "adf" + } + } + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + },{ + "id": "test-imp-id2", + "ext": { + "bidder": { + "mid": "828783", + "priceType": "net" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://adx.adform.net/adx/openrtb", + "body": { + "id": "test-request-id", + "ext": { + "prebid":{ + "aliases":{ + "adfalias": "adf" + } + }, + "pt": "gross" + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828782" + },{ + "id": "test-imp-id2", + "ext": { + "bidder": { + "mid": "828783", + "priceType": "net" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828783" + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [{ + "bid": [{ + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "adomain": [ "test.com" ], + "crid": "test-creative-id", + "ext": { + "prebid": { + "type": "banner" + } + } + }] + }], + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "currency": "USD", + "bids": [ + { + "bid": { + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "crid": "test-creative-id", + "adomain": [ "test.com" ], + "ext": { + "prebid": { + "type": "banner" + } + } + }, + "type": "banner" + } + ] + }] +} diff --git a/adapters/adf/adftest/exemplary/two-banners-different-pricetypes.json b/adapters/adf/adftest/exemplary/two-banners-different-pricetypes.json new file mode 100644 index 00000000000..918ef3ca7f3 --- /dev/null +++ b/adapters/adf/adftest/exemplary/two-banners-different-pricetypes.json @@ -0,0 +1,141 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + },{ + "id": "test-imp-id2", + "ext": { + "bidder": { + "mid": "828783", + "priceType": "net" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + } + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + }, + "httpCalls": [{ + "expectedRequest": { + "uri": "https://adx.adform.net/adx/openrtb", + "body": { + "id": "test-request-id", + "ext": { + "prebid": { + }, + "pt": "gross" + }, + "imp": [{ + "id": "test-imp-id", + "ext": { + "bidder": { + "mid": "828782", + "priceType": "gross" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828782" + },{ + "id": "test-imp-id2", + "ext": { + "bidder": { + "mid": "828783", + "priceType": "net" + } + }, + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "tagid": "828783" + }], + "site": { + "publisher": { + "id": "1" + }, + "page": "some-page-url" + }, + "device": { + "w": 1920, + "h": 800 + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [{ + "bid": [{ + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "adomain": [ "test.com" ], + "crid": "test-creative-id", + "ext": { + "prebid": { + "type": "banner" + } + } + }] + }], + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "currency": "USD", + "bids": [ + { + "bid": { + "id": "test-bid-id", + "impid": "test-imp-id", + "price": 10, + "adm": "{banner html}", + "crid": "test-creative-id", + "adomain": [ "test.com" ], + "ext": { + "prebid": { + "type": "banner" + } + } + }, + "type": "banner" + } + ] + }] +} diff --git a/adapters/adf/params_test.go b/adapters/adf/params_test.go index d075f914082..d46c6528da0 100644 --- a/adapters/adf/params_test.go +++ b/adapters/adf/params_test.go @@ -46,6 +46,8 @@ var validParams = []string{ `{"inv":321,"mname":"12345"}`, `{"mid":123,"inv":321,"mname":"pcl1"}`, `{"mid":"123","inv":321,"mname":"pcl1"}`, + `{"mid":"123","priceType":"gross"}`, + `{"mid":"123","priceType":"net"}`, } var invalidParams = []string{ @@ -62,4 +64,5 @@ var invalidParams = []string{ `{"inv":321}`, `{"inv":"321"}`, `{"mname":"12345"}`, + `{"mid":"123","priceType":"GROSS"}`, } diff --git a/openrtb_ext/imp_adf.go b/openrtb_ext/imp_adf.go index 6a8f9afaa33..e4f5283b7c2 100644 --- a/openrtb_ext/imp_adf.go +++ b/openrtb_ext/imp_adf.go @@ -8,4 +8,5 @@ type ExtImpAdf struct { MasterTagID json.Number `json:"mid,omitempty"` InventorySourceID int `json:"inv,omitempty"` PlacementName string `json:"mname,omitempty"` + PriceType string `json:"priceType,omitempty"` } diff --git a/static/bidder-params/adf.json b/static/bidder-params/adf.json index 4a1a11827ef..e165fa85b7e 100644 --- a/static/bidder-params/adf.json +++ b/static/bidder-params/adf.json @@ -16,6 +16,11 @@ "mname": { "type": ["string"], "description": "A Name which identifies the placement selling the impression" + }, + "priceType": { + "type": ["string"], + "description": "gross or net. Default is net.", + "pattern": "gross|net" } }, "anyOf":[ diff --git a/static/bidder-params/adform.json b/static/bidder-params/adform.json index 906241ffb34..e112f122e49 100644 --- a/static/bidder-params/adform.json +++ b/static/bidder-params/adform.json @@ -16,6 +16,11 @@ "mname": { "type": ["string"], "description": "A Name which identifies the placement selling the impression" + }, + "priceType": { + "type": ["string"], + "description": "gross or net. Default is net.", + "pattern": "gross|net" } }, "anyOf":[