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

Adform adapter lacked gross/net parameter support #2084

Merged
merged 6 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 26 additions & 0 deletions adapters/adf/adf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -47,6 +52,27 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte

imp.TagID = adfImpExt.MasterTagID.String()
validImps = append(validImps, imp)

if adfImpExt.PriceType != "" {
var requestExt adfRequestExt

if len(request.Ext) > 0 {
if err := json.Unmarshal(request.Ext, &requestExt); err != nil {
errors = append(errors, err)
continue
}
} else {
requestExt = adfRequestExt{}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

else statement can be omitted if you init requestExt like this: requestExt := adfRequestExt{} (line 57)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! It will be initiated even if it may not be needed but no harm done in that I guess.


requestExt.PriceType = adfImpExt.PriceType

var err error
if request.Ext, err = json.Marshal(&requestExt); err != nil {
Copy link
Contributor

@VeronikaSolovei9 VeronikaSolovei9 Nov 17, 2021

Choose a reason for hiding this comment

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

Line 60: you marshal req.Ext as many times as many imps are there in reqiest - it's located inside for _, imp := range request.Imp {. This should be moved ouside the for loop.
Line 71 sets new request.ext on every iteration over imp array. It means req.ext.PriceType will have the value from last imp in loop.
How will it work on your side if there are two or more imp in request with different PriceType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All priceTypes need to be the same, but really only the first one should be used and not the last one if they should differ.
I took a bad shortcut there. Me programming Go is also a bit like https://youtu.be/C1Sw0PDgHU4.

errors = append(errors, err)
continue
}
}
}

request.Imp = validImps
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test case where there are 2 imps in request with different priceType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if that is really needed but I can add one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thank you @VeronikaSolovei9 for the feedback!

},
"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"
}
]
}]
}
112 changes: 112 additions & 0 deletions adapters/adf/adftest/exemplary/single-banner-pricetype-gross.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}]
}
112 changes: 112 additions & 0 deletions adapters/adf/adftest/exemplary/single-banner-pricetype-net.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}]
}
Loading