From d0f130d617da4cc190c43fb04e4cd1071ee2887d Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Thu, 7 Sep 2023 17:26:07 +0000 Subject: [PATCH 1/6] Select Netbid or GrossBid from the adserver depending on what you specify in your bidderExt --- adapters/adnuntius/adnuntius.go | 34 +++++- .../supplemental/check-gross-bids.json | 103 ++++++++++++++++++ .../supplemental/check-net-bids.json | 103 ++++++++++++++++++ openrtb_ext/imp_adnuntius.go | 1 + 4 files changed, 235 insertions(+), 6 deletions(-) create mode 100644 adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json create mode 100644 adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json diff --git a/adapters/adnuntius/adnuntius.go b/adapters/adnuntius/adnuntius.go index 3f91d7403f0..65389c06ba4 100644 --- a/adapters/adnuntius/adnuntius.go +++ b/adapters/adnuntius/adnuntius.go @@ -39,6 +39,14 @@ type Ad struct { Amount float64 Currency string } + NetBid struct { + Amount float64 + Currency string + } + GrossBid struct { + Amount float64 + Currency string + } DealID string `json:"dealId,omitempty"` AdId string CreativeWidth string @@ -328,7 +336,7 @@ func getGDPR(request *openrtb2.BidRequest) (string, string, error) { return gdpr, consent, nil } -func generateAdResponse(ad Ad, impId string, html string, request *openrtb2.BidRequest) (*openrtb2.Bid, []error) { +func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.BidRequest) (*openrtb2.Bid, []error) { creativeWidth, widthErr := strconv.ParseInt(ad.CreativeWidth, 10, 64) if widthErr != nil { @@ -344,6 +352,18 @@ func generateAdResponse(ad Ad, impId string, html string, request *openrtb2.BidR }} } + price := ad.Bid.Amount + priceType, _, _, _ := jsonparser.Get(imp.Ext, "bidder", "priceType") + + if string(priceType) != "" { + if strings.ToLower(string(priceType)) == "net" { + price = ad.NetBid.Amount + } + if strings.ToLower(string(priceType)) == "gross" { + price = ad.GrossBid.Amount + } + } + adDomain := []string{} for _, url := range ad.DestinationUrls { domainArray := strings.Split(url, "/") @@ -351,16 +371,18 @@ func generateAdResponse(ad Ad, impId string, html string, request *openrtb2.BidR adDomain = append(adDomain, domain) } + // strings.ToLower(str) + bid := openrtb2.Bid{ ID: ad.AdId, - ImpID: impId, + ImpID: imp.ID, W: creativeWidth, H: creativeHeight, AdID: ad.AdId, DealID: ad.DealID, CID: ad.LineItemId, CrID: ad.CreativeId, - Price: ad.Bid.Amount * 1000, + Price: price * 1000, AdM: html, ADomain: adDomain, } @@ -377,7 +399,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest) adunitMap[adnRespAdunit.TargetId] = adnRespAdunit } - for i, imp := range request.Imp { + for _, imp := range request.Imp { auId, _, _, err := jsonparser.Get(imp.Ext, "bidder", "auId") if err != nil { @@ -394,7 +416,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest) ad := adunit.Ads[0] currency = ad.Bid.Currency - adBid, err := generateAdResponse(ad, request.Imp[i].ID, adunit.Html, request) + adBid, err := generateAdResponse(ad, imp, adunit.Html, request) if err != nil { return nil, []error{&errortypes.BadInput{ Message: fmt.Sprintf("Error at ad generation"), @@ -407,7 +429,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest) }) for _, deal := range adunit.Deals { - dealBid, err := generateAdResponse(deal, request.Imp[i].ID, deal.Html, request) + dealBid, err := generateAdResponse(deal, imp, deal.Html, request) if err != nil { return nil, []error{&errortypes.BadInput{ Message: fmt.Sprintf("Error at ad generation"), diff --git a/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json b/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json new file mode 100644 index 00000000000..46e969d2825 --- /dev/null +++ b/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json @@ -0,0 +1,103 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "user": { + "id": "1kjh3429kjh295jkl" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + } + ] + }, + "ext": { + "bidder": { + "auId": "123", + "priceType": "gross" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://whatever.url?format=json&tzo=0", + "body": { + "adUnits": [ + { + "auId": "123", + "targetId": "123-test-imp-id", + "dimensions": [[300,250],[300,600]] + } + ], + "metaData": { + "usi": "1kjh3429kjh295jkl" + }, + "context": "unknown" + } + }, + "mockResponse": { + "status": 200, + "body": { + "adUnits": [ + { + "auId": "0000000000000123", + "targetId": "123-test-imp-id", + "html": "", + "responseId": "adn-rsp-900646517", + "ads": [ + { + "destinationUrls": { + "url": "http://www.google.com" + }, + "bid": { "amount": 20.0, "currency": "NOK" }, + "grossBid": {"amount": 0.1, "currency": "NOK"}, + "netBid": {"amount": 0.075, "currency": "NOK"}, + "adId": "adn-id-1559784094", + "creativeWidth": "980", + "creativeHeight": "240", + "creativeId": "jn9hpzvlsf8cpdmm", + "lineItemId": "q7y9qm5b0xt9htrv" + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "bids": [ + { + "bid": { + "id": "adn-id-1559784094", + "impid": "test-imp-id", + "price": 100, + "adm": "", + "adid": "adn-id-1559784094", + "adomain": [ + "google.com" + ], + "cid": "q7y9qm5b0xt9htrv", + "crid": "jn9hpzvlsf8cpdmm", + "w": 980, + "h": 240 + }, + "type": "banner" + } + ], + "currency": "NOK" + } + ] +} diff --git a/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json b/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json new file mode 100644 index 00000000000..2f8b0fa0f13 --- /dev/null +++ b/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json @@ -0,0 +1,103 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "user": { + "id": "1kjh3429kjh295jkl" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + } + ] + }, + "ext": { + "bidder": { + "auId": "123", + "priceType": "net" + } + } + } + ] + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://whatever.url?format=json&tzo=0", + "body": { + "adUnits": [ + { + "auId": "123", + "targetId": "123-test-imp-id", + "dimensions": [[300,250],[300,600]] + } + ], + "metaData": { + "usi": "1kjh3429kjh295jkl" + }, + "context": "unknown" + } + }, + "mockResponse": { + "status": 200, + "body": { + "adUnits": [ + { + "auId": "0000000000000123", + "targetId": "123-test-imp-id", + "html": "", + "responseId": "adn-rsp-900646517", + "ads": [ + { + "destinationUrls": { + "url": "http://www.google.com" + }, + "bid": { "amount": 20.0, "currency": "NOK" }, + "grossBid": {"amount": 0.1, "currency": "NOK"}, + "netBid": {"amount": 0.075, "currency": "NOK"}, + "adId": "adn-id-1559784094", + "creativeWidth": "980", + "creativeHeight": "240", + "creativeId": "jn9hpzvlsf8cpdmm", + "lineItemId": "q7y9qm5b0xt9htrv" + } + ] + } + ] + } + } + } + ], + "expectedBidResponses": [ + { + "bids": [ + { + "bid": { + "id": "adn-id-1559784094", + "impid": "test-imp-id", + "price": 75, + "adm": "", + "adid": "adn-id-1559784094", + "adomain": [ + "google.com" + ], + "cid": "q7y9qm5b0xt9htrv", + "crid": "jn9hpzvlsf8cpdmm", + "w": 980, + "h": 240 + }, + "type": "banner" + } + ], + "currency": "NOK" + } + ] +} diff --git a/openrtb_ext/imp_adnuntius.go b/openrtb_ext/imp_adnuntius.go index 86023c48231..cee425fc1e8 100644 --- a/openrtb_ext/imp_adnuntius.go +++ b/openrtb_ext/imp_adnuntius.go @@ -5,4 +5,5 @@ type ImpExtAdnunitus struct { Network string `json:"network"` NoCookies bool `json:"noCookies"` MaxDeals int `json:"maxDeals"` + PriceType string `json:"priceType,omitempty"` } From 88ee484b39f58f8de675837e5a90820377704de0 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Mon, 11 Sep 2023 14:39:26 +0200 Subject: [PATCH 2/6] Changes according to feedback. --- adapters/adnuntius/adnuntius.go | 2 -- static/bidder-params/adnuntius.json | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/adapters/adnuntius/adnuntius.go b/adapters/adnuntius/adnuntius.go index 65389c06ba4..4480f8de229 100644 --- a/adapters/adnuntius/adnuntius.go +++ b/adapters/adnuntius/adnuntius.go @@ -371,8 +371,6 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2. adDomain = append(adDomain, domain) } - // strings.ToLower(str) - bid := openrtb2.Bid{ ID: ad.AdId, ImpID: imp.ID, diff --git a/static/bidder-params/adnuntius.json b/static/bidder-params/adnuntius.json index ff975501edb..f61fa68aaca 100644 --- a/static/bidder-params/adnuntius.json +++ b/static/bidder-params/adnuntius.json @@ -9,6 +9,10 @@ "type": "string", "description": "Placement ID" }, + "maxDeals": { + "type": "integer", + "description": "Specify how many deals that you want to return from the auction." + }, "network": { "type": "string", "description": "Network if required" @@ -16,6 +20,10 @@ "noCookies": { "type": "boolean", "description": "Disable cookies being set by the ad server." + }, + "priceType": { + "type": "string", + "description": "Allows you to specify Net or Gross bids." } }, From a7ce04fa094f8849bdc3ef15c13678c1cbec7a96 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Mon, 11 Sep 2023 15:18:34 +0200 Subject: [PATCH 3/6] Removed Currency from Adnuntius. --- adapters/adnuntius/adnuntius.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adapters/adnuntius/adnuntius.go b/adapters/adnuntius/adnuntius.go index 4480f8de229..407c26d205c 100644 --- a/adapters/adnuntius/adnuntius.go +++ b/adapters/adnuntius/adnuntius.go @@ -40,12 +40,10 @@ type Ad struct { Currency string } NetBid struct { - Amount float64 - Currency string + Amount float64 } GrossBid struct { - Amount float64 - Currency string + Amount float64 } DealID string `json:"dealId,omitempty"` AdId string From e847ee17be79d5051dcc3995fb5e624bc95395b2 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Tue, 12 Sep 2023 12:01:07 +0000 Subject: [PATCH 4/6] Adding error check and making sure that priceType can be optional. --- adapters/adnuntius/adnuntius.go | 24 +++++++++--- .../supplemental/check-price-type-error.json | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json diff --git a/adapters/adnuntius/adnuntius.go b/adapters/adnuntius/adnuntius.go index 407c26d205c..b70e62f3321 100644 --- a/adapters/adnuntius/adnuntius.go +++ b/adapters/adnuntius/adnuntius.go @@ -200,6 +200,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters Message: fmt.Sprintf("ignoring imp id=%s, Adnuntius supports only Banner", imp.ID), }} } + var bidderExt adapters.ExtImpBidder if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { return nil, []error{&errortypes.BadInput{ @@ -210,7 +211,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters var adnuntiusExt openrtb_ext.ImpExtAdnunitus if err := json.Unmarshal(bidderExt.Bidder, &adnuntiusExt); err != nil { return nil, []error{&errortypes.BadInput{ - Message: fmt.Sprintf("Error unmarshalling ExtImpBmtm: %s", err.Error()), + Message: fmt.Sprintf("Error unmarshalling ExtImpValues: %s", err.Error()), }} } @@ -351,13 +352,26 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2. } price := ad.Bid.Amount - priceType, _, _, _ := jsonparser.Get(imp.Ext, "bidder", "priceType") - if string(priceType) != "" { - if strings.ToLower(string(priceType)) == "net" { + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { + return nil, []error{&errortypes.BadInput{ + Message: fmt.Sprintf("Error unmarshalling ExtImpBidder: %s", err.Error()), + }} + } + + var adnuntiusExt openrtb_ext.ImpExtAdnunitus + if err := json.Unmarshal(bidderExt.Bidder, &adnuntiusExt); err != nil { + return nil, []error{&errortypes.BadInput{ + Message: fmt.Sprintf("Error unmarshalling ExtImpValues: %s", err.Error()), + }} + } + + if adnuntiusExt.PriceType != "" { + if strings.EqualFold(string(adnuntiusExt.PriceType), "net") { price = ad.NetBid.Amount } - if strings.ToLower(string(priceType)) == "gross" { + if strings.EqualFold(string(adnuntiusExt.PriceType), "gross") { price = ad.GrossBid.Amount } } diff --git a/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json b/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json new file mode 100644 index 00000000000..1afeb966dce --- /dev/null +++ b/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json @@ -0,0 +1,38 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "user": { + "id": "1kjh3429kjh295jkl" + }, + "imp": [ + { + "id": "test-imp-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + } + ] + }, + "ext": { + "bidder": { + "auId": "123", + "priceType": 123 + } + } + } + ] + }, + "httpCalls": [], + "expectedMakeRequestsErrors": [ + { + "value": "Error unmarshalling ExtImpValues: json: cannot unmarshal number into Go struct field ImpExtAdnunitus.priceType of type string", + "comparison": "literal" + } + ] +} From 429a99ca338c22472eca064448abd07b8ee3e4f6 Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Thu, 28 Sep 2023 12:15:17 +0200 Subject: [PATCH 5/6] Changed name to bidType. --- adapters/adnuntius/adnuntius.go | 6 +++--- .../adnuntiustest/supplemental/check-gross-bids.json | 2 +- .../adnuntiustest/supplemental/check-net-bids.json | 2 +- .../adnuntiustest/supplemental/check-price-type-error.json | 4 ++-- openrtb_ext/imp_adnuntius.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/adapters/adnuntius/adnuntius.go b/adapters/adnuntius/adnuntius.go index b70e62f3321..fd667ddc506 100644 --- a/adapters/adnuntius/adnuntius.go +++ b/adapters/adnuntius/adnuntius.go @@ -367,11 +367,11 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2. }} } - if adnuntiusExt.PriceType != "" { - if strings.EqualFold(string(adnuntiusExt.PriceType), "net") { + if adnuntiusExt.BidType != "" { + if strings.EqualFold(string(adnuntiusExt.BidType), "net") { price = ad.NetBid.Amount } - if strings.EqualFold(string(adnuntiusExt.PriceType), "gross") { + if strings.EqualFold(string(adnuntiusExt.BidType), "gross") { price = ad.GrossBid.Amount } } diff --git a/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json b/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json index 46e969d2825..d6301fe71cf 100644 --- a/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json +++ b/adapters/adnuntius/adnuntiustest/supplemental/check-gross-bids.json @@ -22,7 +22,7 @@ "ext": { "bidder": { "auId": "123", - "priceType": "gross" + "bidType": "gross" } } } diff --git a/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json b/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json index 2f8b0fa0f13..ebb25b2b7ad 100644 --- a/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json +++ b/adapters/adnuntius/adnuntiustest/supplemental/check-net-bids.json @@ -22,7 +22,7 @@ "ext": { "bidder": { "auId": "123", - "priceType": "net" + "bidType": "net" } } } diff --git a/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json b/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json index 1afeb966dce..89016087a43 100644 --- a/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json +++ b/adapters/adnuntius/adnuntiustest/supplemental/check-price-type-error.json @@ -22,7 +22,7 @@ "ext": { "bidder": { "auId": "123", - "priceType": 123 + "bidType": 123 } } } @@ -31,7 +31,7 @@ "httpCalls": [], "expectedMakeRequestsErrors": [ { - "value": "Error unmarshalling ExtImpValues: json: cannot unmarshal number into Go struct field ImpExtAdnunitus.priceType of type string", + "value": "Error unmarshalling ExtImpValues: json: cannot unmarshal number into Go struct field ImpExtAdnunitus.bidType of type string", "comparison": "literal" } ] diff --git a/openrtb_ext/imp_adnuntius.go b/openrtb_ext/imp_adnuntius.go index cee425fc1e8..49833e90f1d 100644 --- a/openrtb_ext/imp_adnuntius.go +++ b/openrtb_ext/imp_adnuntius.go @@ -5,5 +5,5 @@ type ImpExtAdnunitus struct { Network string `json:"network"` NoCookies bool `json:"noCookies"` MaxDeals int `json:"maxDeals"` - PriceType string `json:"priceType,omitempty"` + BidType string `json:"bidType,omitempty"` } From 9096e25ae04559b8752518a195a0cce9c05c629f Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Thu, 28 Sep 2023 14:44:46 +0200 Subject: [PATCH 6/6] Changed static bidder-params to say the same name as the other places. --- static/bidder-params/adnuntius.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/bidder-params/adnuntius.json b/static/bidder-params/adnuntius.json index f61fa68aaca..f7ab32d2f48 100644 --- a/static/bidder-params/adnuntius.json +++ b/static/bidder-params/adnuntius.json @@ -21,7 +21,7 @@ "type": "boolean", "description": "Disable cookies being set by the ad server." }, - "priceType": { + "bidType": { "type": "string", "description": "Allows you to specify Net or Gross bids." }