Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 64 additions & 8 deletions modules/bridgewellBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,76 @@ export const spec = {
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);

const adUnits = [];
var bidderUrl = REQUEST_ENDPOINT + Math.random();
const bidderUrl = REQUEST_ENDPOINT + Math.random();

_each(validBidRequests, function (bid) {
const passthrough = bid.ortb2Imp?.ext?.prebid?.passthrough;
const filteredPassthrough = passthrough ? Object.fromEntries(
Object.entries({
bucket: passthrough.bucket,
client: passthrough.client,
gamAdCode: passthrough.gamAdCode,
gamLoc: passthrough.gamLoc,
colo: passthrough.colo,
device: passthrough.device,
lang: passthrough.lang,
pt: passthrough.pt,
region: passthrough.region,
site: passthrough.site,
ver: passthrough.ver
}).filter(([_, value]) => value !== undefined)
) : undefined;

const adUnit = {
adUnitCode: bid.adUnitCode,
requestId: bid.bidId,
transactionId: bid.transactionId,
adUnitId: bid.adUnitId,
sizes: bid.sizes,
mediaTypes: bid.mediaTypes || {
banner: {
sizes: bid.sizes
}
},
userIds: bid.userId || {},
userIdAsEids: bid.userIdAsEids || {}
ortb2Imp: {
ext: {
prebid: {
passthrough: filteredPassthrough
},
data: {
adserver: {
name: bid.ortb2Imp?.ext?.data?.adserver?.name,
adslot: bid.ortb2Imp?.ext?.data?.adserver?.adslot
},
pbadslot: bid.ortb2Imp?.ext?.data?.pbadslot
},
gpid: bid.ortb2Imp?.ext?.gpid
},
banner: {
pos: bid.ortb2Imp?.banner?.pos
}
}
};
if (bid.params.cid) {

if (bid.params?.cid) {
adUnit.cid = bid.params.cid;
} else {
} else if (bid.params?.ChannelID) {
adUnit.ChannelID = bid.params.ChannelID;
}

const floorInfo = bid.getFloor?.() || {};
adUnit.floor = floorInfo.floor;
adUnit.currency = floorInfo.currency;
adUnits.push(adUnit);
});

let topUrl = '';
if (bidderRequest && bidderRequest.refererInfo) {
if (bidderRequest?.refererInfo?.page) {
topUrl = bidderRequest.refererInfo.page;
}

const firstBid = validBidRequests[0] || {};

return {
method: 'POST',
url: bidderUrl,
Expand All @@ -82,10 +125,23 @@ export const spec = {
},
inIframe: inIframe(),
url: topUrl,
referrer: bidderRequest.refererInfo.ref,
referrer: bidderRequest?.refererInfo?.ref,
auctionId: firstBid?.auctionId,
bidderRequestId: firstBid?.bidderRequestId,
src: firstBid?.src,
userIds: firstBid?.userId || {},
userIdAsEids: firstBid?.userIdAsEids || [],
auctionsCount: firstBid?.auctionsCount,
bidRequestsCount: firstBid?.bidRequestsCount,
bidderRequestsCount: firstBid?.bidderRequestsCount,
bidderWinsCount: firstBid?.bidderWinsCount,
deferBilling: firstBid?.deferBilling,
metrics: firstBid?.metrics || {},
adUnits: adUnits,
// TODO: please do not send internal data structures over the network
refererInfo: bidderRequest.refererInfo.legacy},
refererInfo: bidderRequest?.refererInfo?.legacy,
ortb2: bidderRequest?.ortb2
},
validBidRequests: validBidRequests
};
},
Expand Down
196 changes: 188 additions & 8 deletions test/spec/modules/bridgewellBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,20 @@ describe('bridgewellBidAdapter', function () {
expect(payload).to.be.an('object');
expect(payload.adUnits).to.be.an('array');
expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/');
expect(payload.userIds).to.deep.equal(userId);
expect(payload.userIdAsEids).to.deep.equal(userIdAsEids);
expect(payload.auctionId).to.equal('1d1a030790a475');
expect(payload.bidderRequestId).to.equal('22edbae2733bf6');
for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) {
const u = payload.adUnits[i];
expect(u).to.have.property('ChannelID').that.is.a('string');
expect(u).to.not.have.property('cid');
expect(u).to.have.property('adUnitCode').and.to.equal('adunit-code-2');
expect(u).to.have.property('requestId').and.to.equal('3150ccb55da321');
expect(u).to.have.property('userIds');
expect(u.userIds).to.deep.equal(userId);
expect(u).to.have.property('userIdAsEids');
expect(u.userIdAsEids).to.deep.equal(userIdAsEids);
expect(u).to.have.property('transactionId');
expect(u).to.have.property('sizes');
expect(u).to.have.property('mediaTypes');
expect(u).to.have.property('ortb2Imp');
}
});

Expand Down Expand Up @@ -213,16 +217,20 @@ describe('bridgewellBidAdapter', function () {
expect(payload).to.be.an('object');
expect(payload.adUnits).to.be.an('array');
expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/');
expect(payload.userIds).to.deep.equal(userId);
expect(payload.userIdAsEids).to.deep.equal(userIdAsEids);
expect(payload.auctionId).to.equal('1d1a030790a475');
expect(payload.bidderRequestId).to.equal('22edbae2733bf6');
for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) {
const u = payload.adUnits[i];
expect(u).to.have.property('cid').that.is.a('number');
expect(u).to.not.have.property('ChannelID');
expect(u).to.have.property('adUnitCode').and.to.equal('adunit-code-2');
expect(u).to.have.property('requestId').and.to.equal('3150ccb55da321');
expect(u).to.have.property('userIds');
expect(u.userIds).to.deep.equal(userId);
expect(u).to.have.property('userIdAsEids');
expect(u.userIdAsEids).to.deep.equal(userIdAsEids);
expect(u).to.have.property('transactionId');
expect(u).to.have.property('sizes');
expect(u).to.have.property('mediaTypes');
expect(u).to.have.property('ortb2Imp');
}
});

Expand All @@ -240,6 +248,178 @@ describe('bridgewellBidAdapter', function () {
const validBidRequests = request.validBidRequests;
expect(validBidRequests).to.deep.equal(bidRequests);
});

it('should include ortb2Imp fields in adUnit', function () {
const bidderRequest = {
refererInfo: {
page: 'https://www.bridgewell.com/',
legacy: {
referer: 'https://www.bridgewell.com/',
}
}
}
const bidRequestsWithOrtb2 = [
{
'bidder': 'bridgewell',
'params': {
'cid': 1234,
},
'adUnitCode': 'adunit-code-1',
'transactionId': 'trans-123',
'adUnitId': 'adunit-123',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250]]
}
},
'bidId': 'bid-123',
'ortb2Imp': {
'ext': {
'data': {
'adserver': {
'name': 'gam',
'adslot': '/1234/test'
},
'pbadslot': '/1234/test-pbadslot'
},
'gpid': 'test-gpid',
'prebid': {
'passthrough': {
'bucket': 'test-bucket',
'client': 'test-client',
'gamAdCode': 'test-gam',
'undefinedField': undefined
}
}
},
'banner': {
'pos': 1
}
},
'userId': userId,
'userIdAsEids': userIdAsEids,
}
];

const request = spec.buildRequests(bidRequestsWithOrtb2, bidderRequest);
const adUnit = request.data.adUnits[0];

expect(adUnit.transactionId).to.equal('trans-123');
expect(adUnit.adUnitId).to.equal('adunit-123');
expect(adUnit.sizes).to.deep.equal([[300, 250]]);
expect(adUnit.ortb2Imp.ext.data.adserver.name).to.equal('gam');
expect(adUnit.ortb2Imp.ext.data.adserver.adslot).to.equal('/1234/test');
expect(adUnit.ortb2Imp.ext.data.pbadslot).to.equal('/1234/test-pbadslot');
expect(adUnit.ortb2Imp.ext.gpid).to.equal('test-gpid');
expect(adUnit.ortb2Imp.banner.pos).to.equal(1);
expect(adUnit.ortb2Imp.ext.prebid.passthrough).to.deep.equal({
bucket: 'test-bucket',
client: 'test-client',
gamAdCode: 'test-gam'
});
expect(adUnit.ortb2Imp.ext.prebid.passthrough).to.not.have.property('undefinedField');
});

it('should include floor information when getFloor is available', function () {
const bidderRequest = {
refererInfo: {
page: 'https://www.bridgewell.com/',
legacy: {
referer: 'https://www.bridgewell.com/',
}
}
}
const bidRequestsWithFloor = [
{
'bidder': 'bridgewell',
'params': {
'cid': 1234,
},
'adUnitCode': 'adunit-code-1',
'mediaTypes': {
'banner': {
'sizes': [[300, 250]]
}
},
'bidId': 'bid-123',
'getFloor': function() {
return {
floor: 1.5,
currency: 'USD'
};
},
'userId': userId,
'userIdAsEids': userIdAsEids,
}
];

const request = spec.buildRequests(bidRequestsWithFloor, bidderRequest);
const adUnit = request.data.adUnits[0];

expect(adUnit.floor).to.equal(1.5);
expect(adUnit.currency).to.equal('USD');
});

it('should include additional bid request fields in payload', function () {
const bidderRequest = {
refererInfo: {
page: 'https://www.bridgewell.com/',
ref: 'https://www.referrer.com/',
legacy: {
referer: 'https://www.bridgewell.com/',
}
},
ortb2: {
site: {
name: 'test-site'
}
}
}
const bidRequestsWithMetrics = [
{
'bidder': 'bridgewell',
'params': {
'cid': 1234,
},
'adUnitCode': 'adunit-code-1',
'mediaTypes': {
'banner': {
'sizes': [[300, 250]]
}
},
'bidId': 'bid-123',
'bidderRequestId': 'bidder-req-123',
'auctionId': 'auction-123',
'src': 's2s',
'auctionsCount': 5,
'bidRequestsCount': 10,
'bidderRequestsCount': 3,
'bidderWinsCount': 2,
'deferBilling': true,
'metrics': {
'test': 'metric'
},
'userId': userId,
'userIdAsEids': userIdAsEids,
}
];

const request = spec.buildRequests(bidRequestsWithMetrics, bidderRequest);
const payload = request.data;

expect(payload.auctionId).to.equal('auction-123');
expect(payload.bidderRequestId).to.equal('bidder-req-123');
expect(payload.src).to.equal('s2s');
expect(payload.auctionsCount).to.equal(5);
expect(payload.bidRequestsCount).to.equal(10);
expect(payload.bidderRequestsCount).to.equal(3);
expect(payload.bidderWinsCount).to.equal(2);
expect(payload.deferBilling).to.equal(true);
expect(payload.metrics).to.deep.equal({test: 'metric'});
expect(payload.referrer).to.equal('https://www.referrer.com/');
expect(payload.ortb2).to.deep.equal({site: {name: 'test-site'}});
});
});

describe('interpretResponse', function () {
Expand Down
Loading