-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Prebid Server Bid Adapter: Include adUnitCode in PBS Adapter Requests #9337
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {auctionManager} from '../../../src/auctionManager.js'; | ||
import {deepSetValue} from '../../../src/utils.js'; | ||
|
||
export function setImpAdUnitCode(imp, bidRequest, context, { adUnit, index = auctionManager.index } = {}) { | ||
adUnit = adUnit || index.getAdUnit(bidRequest); | ||
|
||
if (adUnit) { | ||
deepSetValue( | ||
imp, | ||
`ext.prebid.adunitcode`, | ||
adUnit.code | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {setImpAdUnitCode} from '../../../../libraries/pbsExtensions/processors/adUnitCode.js'; | ||
|
||
describe('pbjs -> ortb adunit code to imp[].ext.prebid.adunitcode', () => { | ||
let index, adUnit, adUnitObj; | ||
beforeEach(() => { | ||
adUnit = ''; | ||
adUnitObj = {code: 'mockAdUnit'}; | ||
index = { | ||
getAdUnit() { | ||
return adUnitObj; | ||
} | ||
} | ||
}); | ||
|
||
function setImp(bidRequest, context, deps = {}) { | ||
const imp = {}; | ||
setImpAdUnitCode(imp, bidRequest, context, Object.assign({adUnit, index}, deps)) | ||
return imp; | ||
} | ||
|
||
it('falls back to index.getAdUnit if adUnit is not present to set adunitcode in ext.prebid.adunitcode', () => { | ||
expect(setImp({bidder: 'mockBidder'})).to.eql({ | ||
'ext': { | ||
'prebid': { | ||
'adunitcode': 'mockAdUnit' | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
it('overrides index.getAdUnit if adUnit is present to set adunitcode in ext.prebid.adunitcode', () => { | ||
adUnit = {code: 'mockAdUnit2'}; | ||
expect(setImp({bidder: 'mockBidder'})).to.eql({ | ||
'ext': { | ||
'prebid': { | ||
'adunitcode': 'mockAdUnit2' | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
it('does not set adunitcode in ext.prebid.adunitcode if adUnit is undefined', () => { | ||
adUnitObj = undefined; | ||
expect(setImp({bidder: 'mockBidder'})).to.eql({}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
adUnitCode = bidRequest.adUnitCode || context.adUnit?.code
; or, even better, if you update this logic tothen in here you can just do
adUnitCode = bidRequest.adUnitCode
.Why? normally bidRequests have an
adUnitCode
property which is all you need; but in the case of the PBS adapter specifically, there is no 1-to-1 correspondence between an imp and a bidRequest; so thebidRequest
parameter here is a "fake" one that should contain only those fields that do not depend on the bidder. The adunit code is one of those fields but I missed it when wrote that logic.The issue with your approach here is that:
adUnit
parameter is never defined - except for your tests, the callers do not know about it;index.getAdUnit
will work for client-side adapters that talk to a PBS backend, but not for the PBS adapter, because in that case thebidRequest
parameter is not a "real" bid request.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @dgirardi for taking the time to walk me through the "why" up above! makes sense in terms of pbs operating differently. Addressed your feedback and refactored things a little bit, can you review again when you have a sec?