Skip to content

Commit

Permalink
Support aliases in prebidServer (prebid#2257)
Browse files Browse the repository at this point in the history
* Support AppNexus aliases in s2s request

* Support dynamic aliases
  • Loading branch information
matthewlane authored and Matt Kendall committed Mar 26, 2018
1 parent 469d586 commit feafdcf
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
19 changes: 16 additions & 3 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ const paramTypes = {
function convertTypes(adUnits) {
adUnits.forEach(adUnit => {
adUnit.bids.forEach(bid => {
const types = paramTypes[bid.bidder] || [];
// aliases use the base bidder's paramTypes
const bidder = adaptermanager.aliasRegistry[bid.bidder] || bid.bidder;
const types = paramTypes[bidder] || [];

Object.keys(types).forEach(key => {
if (bid.params[key]) {
bid.params[key] = types[key](bid.params[key]);
Expand Down Expand Up @@ -402,14 +405,20 @@ const OPEN_RTB_PROTOCOL = {

buildRequest(s2sBidRequest, adUnits) {
let imps = [];
let aliases = {};

// transform ad unit into array of OpenRTB impression objects
adUnits.forEach(adUnit => {
// OpenRTB response contains the adunit code and bidder name. These are
// combined to create a unique key for each bid since an id isn't returned
adUnit.bids.forEach(bid => {
// OpenRTB response contains the adunit code and bidder name. These are
// combined to create a unique key for each bid since an id isn't returned
const key = `${adUnit.code}${bid.bidder}`;
this.bidMap[key] = bid;

// check for and store valid aliases to add to the request
if (adaptermanager.aliasRegistry[bid.bidder]) {
aliases[bid.bidder] = adaptermanager.aliasRegistry[bid.bidder];
}
});

let banner;
Expand Down Expand Up @@ -469,6 +478,10 @@ const OPEN_RTB_PROTOCOL = {
request.user = { ext: { digitrust: digiTrust } };
}

if (!utils.isEmpty(aliases)) {
request.ext = { prebid: { aliases } };
}

return request;
},

Expand Down
2 changes: 2 additions & 0 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let s2sTestingModule; // store s2sTesting module if it's loaded

var _bidderRegistry = {};
exports.bidderRegistry = _bidderRegistry;
exports.aliasRegistry = {};

let _s2sConfig = {};
config.getConfig('s2sConfig', config => {
Expand Down Expand Up @@ -383,6 +384,7 @@ exports.aliasBidAdapter = function (bidderCode, alias) {
} else {
let spec = bidAdaptor.getSpec();
newAdapter = newBidder(Object.assign({}, spec, { code: alias }));
exports.aliasRegistry[alias] = bidderCode;
}
this.registerBidAdapter(newAdapter, alias, {
supportedMediaTypes
Expand Down
1 change: 1 addition & 0 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export function registerBidder(spec) {
putBidder(spec);
if (Array.isArray(spec.aliases)) {
spec.aliases.forEach(alias => {
adaptermanager.aliasRegistry[alias] = spec.code;
putBidder(Object.assign({}, spec, { code: alias }));
});
}
Expand Down
57 changes: 57 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,63 @@ describe('S2S Adapter', () => {
expect(requestBid.site.publisher).to.exist.and.to.be.a('object');
expect(requestBid.site.page).to.exist.and.to.be.a('string');
});

it('adds appnexus aliases to request', () => {
const s2sConfig = Object.assign({}, CONFIG, {
endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'
});
config.setConfig({s2sConfig});

const aliasBidder = {
bidder: 'brealtime',
params: { placementId: '123456' }
};

const request = Object.assign({}, REQUEST);
request.ad_units[0].bids = [aliasBidder];

adapter.callBids(request, BID_REQUESTS, addBidResponse, done, ajax);

const requestBid = JSON.parse(requests[0].requestBody);

expect(requestBid.ext).to.deep.equal({
prebid: {
aliases: {
brealtime: 'appnexus'
}
}
});
});

it('adds dynamic aliases to request', () => {
const s2sConfig = Object.assign({}, CONFIG, {
endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'
});
config.setConfig({s2sConfig});

const alias = 'foobar';
const aliasBidder = {
bidder: alias,
params: { placementId: '123456' }
};

const request = Object.assign({}, REQUEST);
request.ad_units[0].bids = [aliasBidder];

// TODO: stub this
$$PREBID_GLOBAL$$.aliasBidder('appnexus', alias);
adapter.callBids(request, BID_REQUESTS, addBidResponse, done, ajax);

const requestBid = JSON.parse(requests[0].requestBody);

expect(requestBid.ext).to.deep.equal({
prebid: {
aliases: {
[alias]: 'appnexus'
}
}
});
});
});

describe('response handler', () => {
Expand Down

0 comments on commit feafdcf

Please sign in to comment.