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

PE-87: Implement Prebid Adapter #1

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

PavloMalashnyak
Copy link
Collaborator

@PavloMalashnyak PavloMalashnyak commented Sep 26, 2023

Story

PE-87

Implement BT Bid Adapter that send one request for each configured ad unit to the our prebid server

Testing

What tests did you perform to ensure that this code functions as expected?

  • Manual testing
  • Unit tests
  • Integration tests
  • A/B tests

return [];
}

const seatBids = serverResponse?.body.seatbid || [];

Choose a reason for hiding this comment

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

if we already check for serverResponse on line 37, I don't think we need the conditional operator after serverResponse - maybe serverResponse.body?.seatbid though?

Choose a reason for hiding this comment

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

or we can combine this 2 checks:

const seatBids = serverResponse?.body?.seatbid || [];
if (!seatBids.length) {
  return [];
}

btw, why the server responses with seatbid while it seems to be an array?

const newBids = seatBids.flatMap((seat) => {
return seat.bid.map((bid) => {
const bidResponse = getNewBidResponse(bid);
bidResponse.btBidderCode = seat.seat;
Copy link

@lawrence-hoo lawrence-hoo Sep 28, 2023

Choose a reason for hiding this comment

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

Would it make sense to pass in seat into getNewBidResponse and have bidResponse.btBidderCode = seat.seat be done inside the function instead?

Then I think you could do:

const newBids = seatBids.flatMap(seat =>
  seat.bid.map(bid => getNewBidResponse(bid, seat))
);

Choose a reason for hiding this comment

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

I'm not super familiar with this, so feel free to leave it as is if you think it makes more sense to keep them separate

Choose a reason for hiding this comment

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

bidResponse.btBidderCode = seat.seat; was done this way, due to Relay implementation specific. so, if we can adjust this and probably rename (not to do seat.seat), it would be great! I guess it requires BE change as well.

const { ab, siteId, ...bidderParams } = params;
const imps = [];

for (const mediaType in mediaTypes) {

Choose a reason for hiding this comment

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

Personally I'm more of a fan of:
const imps = Object.entries(mediaTypes).map(([mediaType, currentType]) => ...)

Not really a huge deal either way; if you keep the for ... in I wonder if you'd need to add a hasOwnProperty check for safety

Choose a reason for hiding this comment

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

do we expect mediaType to be anything other than a banner?
I mean, you specified supportedMediaTypes: [BANNER], but here if we get VIDEO, we won't error. am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rn we only support banner, but in future we plan to support other types. Might be worth adding check for supported media types

expect(requests[0].bids).to.equal(validBidRequests);
});

it('should build post request ortb2 fields are not present', () => {

Choose a reason for hiding this comment

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

Should this be something like: "should build post request even when ortb2 fields are not present"?

expect(bids.length).to.equal(0);
});

it('should return bids array', () => {

Choose a reason for hiding this comment

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

Would it better to have this say something like: "should return bids array when serverResponse is defined and seatbid array is not empty"? Feel free to leave it as-is, I'm not really sure what the convention should be.

Copy link

@MariiaKolisnyk MariiaKolisnyk left a comment

Choose a reason for hiding this comment

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

did you skip logging on purpose?

why do we use this repo? are we going to merge it to our Prebid instance?

isStr(bid.params.siteId) &&
!!bid.params?.ab &&
isBoolean(bid.params.ab)
);

Choose a reason for hiding this comment

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

do you think we can add a log in case of invalid bidRequests and specify what is missing/wrong?

also, we can move out bid.params check to not repeat it:

  bid.params && bid.params.siteId && ...

or even something like:

  const { siteId, ab } = bid.params || {};

  if (!siteId || !isStr(bid.params.siteId)) {
    logError('BT Bid Adapter: siteId must be string type.');
    return false;
  }

code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER],
isBidRequestValid: (bid) => {

Choose a reason for hiding this comment

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

might be worth adding JSDoc, e.g.:
image

it's up to you, however I prefer to declare methods separately to make export spec clearer:

function isBidRequestValid() { ... }
function buildRequests() { ... }

export const spec = {
  code: BIDDER_CODE,
  gvlid: GVLID,
  supportedMediaTypes: [BANNER],
  isBidRequestValid,
  buildRequests,
  ...
}

# Params

- `ab` required, whether AdBlock is enabled.
- `siteId` required, site id.

Choose a reason for hiding this comment

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

would be nice to specify the types, table view might work better:
image


The BT service accepts industry standard OpenRTB 2.5 as its payload. The BT Bidder Adapter converts Prebid.js parameters into an OpenRTB 2.5 request.

# Params

Choose a reason for hiding this comment

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

should this be Bid Params?

Comment on lines 9 to 11
The BT Bidder Adapter provides an interface to the BT Service. The BT Bidder Adapter sends one request to the BT Service per ad unit, but the BT Service will then send one request to each configured exchange. This is functionally similar to Prebid Server. One client side request, bids from many exchanges.

The BT service accepts industry standard OpenRTB 2.5 as its payload. The BT Bidder Adapter converts Prebid.js parameters into an OpenRTB 2.5 request.

Choose a reason for hiding this comment

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

so, this is just copy-pasted from Relay docs, we might be more creative, unless this is approved by Product

const newBids = seatBids.flatMap((seat) => {
return seat.bid.map((bid) => {
const bidResponse = getNewBidResponse(bid);
bidResponse.btBidderCode = seat.seat;

Choose a reason for hiding this comment

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

bidResponse.btBidderCode = seat.seat; was done this way, due to Relay implementation specific. so, if we can adjust this and probably rename (not to do seat.seat), it would be great! I guess it requires BE change as well.

if (!seatBids.length) {
return [];
}
const newBids = seatBids.flatMap((seat) => {

Choose a reason for hiding this comment

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

newBids is redundant, we can just return seatBids.flatMap((seat) ...

}

function getBTRequest(validBidRequest, bidderRequest) {
let request = {

Choose a reason for hiding this comment

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

could be const

const imps = [];

for (const mediaType in mediaTypes) {
let bidImp = {

Choose a reason for hiding this comment

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

could be const

const { ab, siteId, ...bidderParams } = params;
const imps = [];

for (const mediaType in mediaTypes) {

Choose a reason for hiding this comment

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

do we expect mediaType to be anything other than a banner?
I mean, you specified supportedMediaTypes: [BANNER], but here if we get VIDEO, we won't error. am I missing something?

@PavloMalashnyak
Copy link
Collaborator Author

did you skip logging on purpose?

why do we use this repo? are we going to merge it to our Prebid instance?

Yes, I didn't log anything as it isn't a part of acceptance criteria. But I could add some logs.

We use this forked repo to contribute to Prebid.js in the future. I think we will merge this into up-prebid.js once they are merged to the Prebid.js

Choose a reason for hiding this comment

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

I wonder if the file name should start with a lowercase letter? I did not check the convention, but I don't see any files in Prebid that start with a capital letter.

@PavloMalashnyak PavloMalashnyak merged commit 79a0a94 into bt-master Oct 17, 2023
PavloMalashnyak pushed a commit that referenced this pull request Mar 4, 2024
* Kimberlite bid adapter (#1)

* initial: bid adapter

* styling

* Fix: lint (#2)

* Fix: lint (#4)

* review fixes (#6)

* Change: filling request.ext.prebid section (#7)

---------

Co-authored-by: Oleg <oleg.s@solta.io>
PavloMalashnyak added a commit that referenced this pull request Mar 4, 2024
* PE-87: Implement Prebid Adapter (#1)

* PE-87: implement BT Bid Adapter

* PE-87: rework adapter to use ortbConverter lib, make requested changes

* PE-87: update imports

* PE-110: Add user sync logic to the Prebid Adapter (#3)

* PE-110: add user sync logic

* PE-110: update userSync url

* PE-110: check if iframe is enabled before setting params

* PE-111: BT Prebid Adapter can request AA ads or regular ads (#2)

* PE-120: Send Prebid Bidder info to BT Server (#4)

* PE-120: add btBidderCode to the bid object

* PE-120: use single quotes for logs string

* PE-123: Add More Metadata in site.ext.blockthrough (#5)

* PE-123: send additional meta data

* PE-123: send auctionID under imp.ext.prebid.blockthrough

* PE-123: use ortb2 config to set site.ext params

* PE-123: sent auctionId in ext.prebid.blockthrough.auctionID

* PE-123: update logs for bidderConfig setup

* PE-000: check if blockthrough is defined (#6)

* PE-87: remove BT specific logic (#7)

* Implement Blockthrough Prebid Adapter

* PE-87: Implement Prebid Adapter - misc fixes (#9)

* PE-87: rename test file, add bidder config

* PE-87: increase ttl

* PE-000: fix test

* BP-74: Change the way we enable debug (#10)

* BP-79: Send GPID as a part of `imp[].ext` (#11)

* BP-79: send gpid in imp.ext

* BP-79: add optional operator

* BP-90: Update Cookie Sync Logic (#12)

* BP-90: pass bidder to cookie sync

* BP-90: update sync logic, fix typo

* BP-90: use const for syncs variable

* BP-55: Re-add endpoint URLs (#13)

* BP-91: Add prebid JS version to auction request (#14)
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.

3 participants