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

Conversation

bjorn-lw
Copy link
Contributor

The client version of the Adform adapter supports choosing between returning gross or net via the priceType parameter.

As the new "adf" adapter defaults to net while the old "adform" adapter defaulted to gross, this can make the transition to the new adapter become quite a challenge if you are using plenty of bid conversion functions and the PBS adapter doesn't support selecting gross or net.

This PR adds the same priceType support as the client has.

@bjorn-lw bjorn-lw closed this Nov 15, 2021
@bjorn-lw bjorn-lw reopened this Nov 15, 2021
@bjorn-lw
Copy link
Contributor Author

@braizhas maybe you want to have a look at this as well.

}
} 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.

"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!

@VeronikaSolovei9
Copy link
Contributor

Please update adapter documentation with the description of new parameter

@bjorn-lw
Copy link
Contributor Author

Please update adapter documentation with the description of new parameter

prebid/prebid.github.io#3417

Copy link
Contributor

@VeronikaSolovei9 VeronikaSolovei9 left a comment

Choose a reason for hiding this comment

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

Thank you for the fixes, LGTM :)

@braizhas
Copy link
Contributor

@braizhas maybe you want to have a look at this as well.

@bjorn-lw thanks for the notification.
Changes are legit and would enable gross price bids from Adform.

Please also update adform bidder params as now it acts as an alias to adf bidder. https://github.com/prebid/prebid-server/blob/063990f8cd8b43b5c8d6d25c1a4ac449350710f7/static/bidder-params/adform.json

@bjorn-lw
Copy link
Contributor Author

Please also update adform bidder params as now it acts as an alias to adf bidder. https://github.com/prebid/prebid-server/blob/063990f8cd8b43b5c8d6d25c1a4ac449350710f7/static/bidder-params/adform.json

Fixed, thank you!

requestExt.PriceType = priceType

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

Choose a reason for hiding this comment

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

At this point, you are remarshalling requestExt, which may not be properly populated if the above unmarshal failed. This should be very unlikely, perhaps impossible, but you may want to consider if you want the request to progress through this stage if an error happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hhhjort Thanks! It should be be fixed, but I don't like the many nested if's. I would probably have done it a little different in a language I'm more familiar with. If you can give me a hint on how to make it look nicer, please do.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually this doesn't fix it. If you hit line 69, having encountered and error with unmarshalling the .ext, you still drop down and overwrite the original .ext on line 75. You would have to break out of the section, perhaps returning an error from MakeRequests() at that line, to avoid this issue. I am not terribly concerned with this, as it is something that should really never happen in the first place. And if it does somehow happen, it just means that the request.ext you are sending to your server may have missing/corrupt data in it. I really just wanted to highlight it so you could decide if it is a worry for you and change your handling if it is. If you reply that you are good with it as is, or just do nothing, I am still good with approving this PR. Just giving you some time to respond before it is merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack, nevermind, it does fix it. I just did not read the code properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hhhjort I was frantically reading trying to understand what I missed :) But I think the code is ugly. Can it be written better? You don't have to reply, I could take that online course on Go if I can just get some additional hours in a day :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have any specific recommendations to make this code prettier, it seems normal enough go to me. Well, one thing that might improve the view...

In the initial loop where you try to find the price type, you are only interested in the first value you find. So when you do find it, you could instead call setRequestPriceType(request *openrtb2.BidRequest, priceType string), which would be the following block of code that sets the price type in request.ext. Then in that function, you could return immediately if the unmarshal fails, making it more obvious that a failure aborts the rest of price type processing. Moving the code to its own function isolates it as its own step, leaving the main function cleaner in its logic. You coud also put the loop to find the price type in the function, making it easier to break out of the loop and further focusing the main function's code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hhhjort yes, common clean code sense. I may leave it as is for now if you don't mind. I might get back to this at a later time if I come up with something else that needs to be done in the adapter. Is that OK?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is fine, I have already approved this PR

Copy link
Collaborator

@hhhjort hhhjort left a comment

Choose a reason for hiding this comment

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

LGTM

@mansinahar mansinahar merged commit cc4a376 into prebid:master Nov 29, 2021
wwwyyy pushed a commit to wwwyyy/prebid-server that referenced this pull request Dec 20, 2021
* 'master' of https://github.com/wwwyyy/prebid-server: (23 commits)
  Add GPID Reserved Bidder Name (prebid#2107)
  Marsmedia adapter - param zoneId can get string and int (prebid#2105)
  Algorix: add Server Region Support (prebid#2096)
  New Adapter: Bizzclick (prebid#2056)
  Collect Prometheus Go process metrics (prebid#2101)
  Added channel support (prebid#2037)
  Rubicon: update fpd fields resolving (prebid#2091)
  Beachfront - Currency conversion (prebid#2078)
  New Adapter: Groupm (Alias Of PubMatic) (prebid#2042)
  Adform adapter lacked gross/net parameter support (prebid#2084)
  add iframe sync for openx (prebid#2094)
  changes to the correct user sync url (prebid#2092)
  Smaato: Add instl to tests (prebid#2089)
  Correct MakeRequests() output assertion in adapter JSON tests (prebid#2087)
  Adview: adapter currency fix. (prebid#2060)
  New Adapter: Coinzilla (prebid#2074)
  Syncer Level ExternalURL Override (prebid#2072)
  33Across: Enable Support for SRA requests (prebid#2079)
  Currency conversion on adapter JSON tests (prebid#2071)
  New Adapter: VideoByte (prebid#2058)
  ...
jorgeluisrocha pushed a commit to jwplayer/prebid-server that referenced this pull request Sep 28, 2022
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants