-
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
Option to use a configurable vendor preset for s2sConfig #2073
Changes from 3 commits
1832bdc
b1f3823
c1c6462
ee6bdb4
5488050
7e8ec2c
6bc107d
b901fc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,40 @@ const DEFAULT_S2S_CURRENCY = 'USD'; | |
const DEFAULT_S2S_NETREVENUE = true; | ||
|
||
let _s2sConfig; | ||
|
||
const s2sDefaultConfig = { | ||
enabled: false, | ||
timeout: 1000, | ||
maxBids: 1, | ||
adapter: 'prebidServer' | ||
}; | ||
|
||
config.setDefaults({ | ||
's2sConfig': { | ||
enabled: false, | ||
timeout: 1000, | ||
maxBids: 1, | ||
adapter: 'prebidServer' | ||
} | ||
's2sConfig': s2sDefaultConfig | ||
}); | ||
|
||
// accountId and bidders params are not included here, should be configured by end-user | ||
const availVendorDefaults = { | ||
'appnexus': { | ||
adapter: 'prebidServer', | ||
cookieSet: true, | ||
cookieSetUrl: '//acdn.adnxs.com/cookieset/cs.js', | ||
enabled: true, | ||
endpoint: '//prebid.adnxs.com/pbs/v1/auction', | ||
syncEndpoint: '//prebid.adnxs.com/pbs/v1/cookie_sync', | ||
timeout: 1000 | ||
}, | ||
'rubicon': { | ||
adapter: 'prebidServer', | ||
cookieSet: true, | ||
cookieSetUrl: 'https://secure-assets.rubiconproject.com/utils/cookieset/cs.js', | ||
enabled: true, | ||
endpoint: 'https://prebid-server.rubiconproject.com/auction', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bretg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been avoiding the protocol-relative URLs due to articles like https://stackoverflow.com/questions/28446314/why-use-protocol-relative-urls-at-all You haven't seen issues with protocol-relative URLs? In any case, go ahead with this for now and we'll start the conversation internally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked to @mkendall07 -- the issue here is that non-secure demand is left on the table for HTTPS. So, yes, let's switch the endpoints to protocol-relative. Thanks Matt. We'll take this discussion up internally as well. |
||
syncEndpoint: 'https://prebid-server.rubiconproject.com/cookie_sync', | ||
timeout: 500 | ||
} | ||
}; | ||
|
||
/** | ||
* Set config for server to server header bidding | ||
* @typedef {Object} options - required | ||
|
@@ -42,6 +67,21 @@ config.setDefaults({ | |
* @property {string} [cookieSetUrl] url for cookie set library, if passed then cookieSet is enabled | ||
*/ | ||
function setS2sConfig(options) { | ||
if (options.defaultVendor) { | ||
let vendor = options.defaultVendor | ||
|
||
if (availVendorDefaults.hasOwnProperty(vendor)) { | ||
Object.keys(availVendorDefaults[vendor]).forEach(function(vendorKey) { | ||
if (s2sDefaultConfig[vendorKey] === options[vendorKey]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I read somewhere that you shouldn't write code as clever as you are, because debugging code is 2x more difficult than writing it. So if you write clever code, you by definition cannot debug it... :) Ok it's probably an exaggeration but the point remains. It took me awhile to figure out why this works - it's because its compare There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback @mkendall07, I've just finished making a slight change to hopefully infer the logic better. I also put in a comment as a backup. Please let me know your thoughts. |
||
options[vendorKey] = availVendorDefaults[vendor][vendorKey] | ||
} | ||
}); | ||
} else { | ||
utils.logError('Incorrect or unavailable prebid server default vendor option: ' + vendor); | ||
return false; | ||
} | ||
} | ||
|
||
let keys = Object.keys(options); | ||
|
||
if (['accountId', 'bidders', 'endpoint'].filter(key => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -475,5 +475,62 @@ describe('S2S Adapter', () => { | |
config.setConfig({ s2sConfig: options }); | ||
sinon.assert.calledOnce(logErrorSpy); | ||
}); | ||
|
||
it('should log error when vendor does not exist', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a test to show there's a failure when 'defaultVendor' doesn't exist but endpoint isn't specified? This will show there's no default-defaultVendor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @bretg - I'm not sure I follow what you mean. Can you please clarify further when you get the chance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think he's saying to add a test case to assert an error when both endpoint & vendor default are not specified in the S2S config (or vendor default doesn't exist) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks for that clarification. I've added a test case in the next commit. |
||
const options = { | ||
accountId: '1', | ||
bidders: ['appnexus'], | ||
defaultVendor: 'mytest' | ||
}; | ||
|
||
config.setConfig({ s2sConfig: options }); | ||
sinon.assert.calledOnce(logErrorSpy); | ||
}); | ||
|
||
it('should configure the s2sConfig object with appnexus vendor defaults unless specified by user', () => { | ||
const options = { | ||
accountId: '123', | ||
bidders: ['appnexus'], | ||
defaultVendor: 'appnexus', | ||
timeout: 750 | ||
}; | ||
|
||
config.setConfig({ s2sConfig: options }); | ||
sinon.assert.notCalled(logErrorSpy); | ||
|
||
let vendorConfig = config.getConfig('s2sConfig'); | ||
expect(vendorConfig).to.have.property('accountId', '123'); | ||
expect(vendorConfig).to.have.property('adapter', 'prebidServer'); | ||
expect(vendorConfig.bidders).to.deep.equal(['appnexus']); | ||
expect(vendorConfig.cookieSet).to.be.true; | ||
expect(vendorConfig).to.have.property('cookieSetUrl', '//acdn.adnxs.com/cookieset/cs.js'); | ||
expect(vendorConfig.enabled).to.be.true; | ||
expect(vendorConfig).to.have.property('endpoint', '//prebid.adnxs.com/pbs/v1/auction'); | ||
expect(vendorConfig).to.have.property('syncEndpoint', '//prebid.adnxs.com/pbs/v1/cookie_sync'); | ||
expect(vendorConfig).to.have.property('timeout', 750); | ||
}); | ||
|
||
it('should configure the s2sConfig object with rubicon vendor defaults unless specified by user', () => { | ||
const options = { | ||
accountId: 'abc', | ||
bidders: ['rubicon'], | ||
defaultVendor: 'rubicon', | ||
timeout: 750 | ||
}; | ||
|
||
config.setConfig({ s2sConfig: options }); | ||
sinon.assert.notCalled(logErrorSpy); | ||
|
||
let vendorConfig = config.getConfig('s2sConfig'); | ||
expect(vendorConfig).to.have.property('accountId', 'abc'); | ||
expect(vendorConfig).to.have.property('adapter', 'prebidServer'); | ||
expect(vendorConfig.bidders).to.deep.equal(['rubicon']); | ||
expect(vendorConfig.cookieSet).to.be.true; | ||
expect(vendorConfig).to.have.property('cookieSetUrl', 'https://secure-assets.rubiconproject.com/utils/cookieset/cs.js'); | ||
expect(vendorConfig.enabled).to.be.true; | ||
expect(vendorConfig).to.have.property('endpoint', 'https://prebid-server.rubiconproject.com/auction'); | ||
expect(vendorConfig).to.have.property('syncEndpoint', 'https://prebid-server.rubiconproject.com/cookie_sync'); | ||
expect(vendorConfig).to.have.property('timeout', 750); | ||
}); | ||
}); | ||
}); |
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.
We discussed -- please remove the cookieSetUrl for Rubicon and turn cookieSet to false. Thanks. Also make "endpoint" protocol-relative. Thanks.