Skip to content

Commit f2c15cb

Browse files
donnychanglaneser
andauthored
Bridgewell Bid Adapter: expand request data (#14320)
* enhance adapter with additional bid parameters * Add additional bid parameters to tests of bridgewellBidAdapter * pass mediaType and size to getFloor --------- Co-authored-by: Laneser <[email protected]>
1 parent f46d47e commit f2c15cb

2 files changed

Lines changed: 258 additions & 16 deletions

File tree

modules/bridgewellBidAdapter.js

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,82 @@ export const spec = {
4545
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
4646

4747
const adUnits = [];
48-
var bidderUrl = REQUEST_ENDPOINT + Math.random();
48+
const bidderUrl = REQUEST_ENDPOINT + Math.random();
4949

5050
_each(validBidRequests, function (bid) {
51+
const passthrough = bid.ortb2Imp?.ext?.prebid?.passthrough;
52+
const filteredPassthrough = passthrough ? Object.fromEntries(
53+
Object.entries({
54+
bucket: passthrough.bucket,
55+
client: passthrough.client,
56+
gamAdCode: passthrough.gamAdCode,
57+
gamLoc: passthrough.gamLoc,
58+
colo: passthrough.colo,
59+
device: passthrough.device,
60+
lang: passthrough.lang,
61+
pt: passthrough.pt,
62+
region: passthrough.region,
63+
site: passthrough.site,
64+
ver: passthrough.ver
65+
}).filter(([_, value]) => value !== undefined)
66+
) : undefined;
67+
5168
const adUnit = {
5269
adUnitCode: bid.adUnitCode,
5370
requestId: bid.bidId,
71+
transactionId: bid.transactionId,
72+
adUnitId: bid.adUnitId,
73+
sizes: bid.sizes,
5474
mediaTypes: bid.mediaTypes || {
5575
banner: {
5676
sizes: bid.sizes
5777
}
5878
},
59-
userIds: bid.userId || {},
60-
userIdAsEids: bid.userIdAsEids || {}
79+
ortb2Imp: {
80+
ext: {
81+
prebid: {
82+
passthrough: filteredPassthrough
83+
},
84+
data: {
85+
adserver: {
86+
name: bid.ortb2Imp?.ext?.data?.adserver?.name,
87+
adslot: bid.ortb2Imp?.ext?.data?.adserver?.adslot
88+
},
89+
pbadslot: bid.ortb2Imp?.ext?.data?.pbadslot
90+
},
91+
gpid: bid.ortb2Imp?.ext?.gpid
92+
},
93+
banner: {
94+
pos: bid.ortb2Imp?.banner?.pos
95+
}
96+
}
6197
};
62-
if (bid.params.cid) {
98+
99+
if (bid.params?.cid) {
63100
adUnit.cid = bid.params.cid;
64-
} else {
101+
} else if (bid.params?.ChannelID) {
65102
adUnit.ChannelID = bid.params.ChannelID;
66103
}
104+
105+
let floorInfo = {};
106+
if (typeof bid.getFloor === 'function') {
107+
const mediaType = bid.mediaTypes?.banner ? BANNER : (bid.mediaTypes?.native ? NATIVE : '*');
108+
const sizes = bid.mediaTypes?.banner?.sizes || bid.sizes || [];
109+
const size = sizes.length === 1 ? sizes[0] : '*';
110+
floorInfo = bid.getFloor({currency: 'USD', mediaType: mediaType, size: size}) || {};
111+
}
112+
adUnit.floor = floorInfo.floor;
113+
adUnit.currency = floorInfo.currency;
67114
adUnits.push(adUnit);
68115
});
69116

70117
let topUrl = '';
71-
if (bidderRequest && bidderRequest.refererInfo) {
118+
if (bidderRequest?.refererInfo?.page) {
72119
topUrl = bidderRequest.refererInfo.page;
73120
}
74121

122+
const firstBid = validBidRequests[0] || {};
123+
75124
return {
76125
method: 'POST',
77126
url: bidderUrl,
@@ -82,10 +131,23 @@ export const spec = {
82131
},
83132
inIframe: inIframe(),
84133
url: topUrl,
85-
referrer: bidderRequest.refererInfo.ref,
134+
referrer: bidderRequest?.refererInfo?.ref,
135+
auctionId: firstBid?.auctionId,
136+
bidderRequestId: firstBid?.bidderRequestId,
137+
src: firstBid?.src,
138+
userIds: firstBid?.userId || {},
139+
userIdAsEids: firstBid?.userIdAsEids || [],
140+
auctionsCount: firstBid?.auctionsCount,
141+
bidRequestsCount: firstBid?.bidRequestsCount,
142+
bidderRequestsCount: firstBid?.bidderRequestsCount,
143+
bidderWinsCount: firstBid?.bidderWinsCount,
144+
deferBilling: firstBid?.deferBilling,
145+
metrics: firstBid?.metrics || {},
86146
adUnits: adUnits,
87147
// TODO: please do not send internal data structures over the network
88-
refererInfo: bidderRequest.refererInfo.legacy},
148+
refererInfo: bidderRequest?.refererInfo?.legacy,
149+
ortb2: bidderRequest?.ortb2
150+
},
89151
validBidRequests: validBidRequests
90152
};
91153
},

test/spec/modules/bridgewellBidAdapter_spec.js

Lines changed: 188 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,20 @@ describe('bridgewellBidAdapter', function () {
165165
expect(payload).to.be.an('object');
166166
expect(payload.adUnits).to.be.an('array');
167167
expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/');
168+
expect(payload.userIds).to.deep.equal(userId);
169+
expect(payload.userIdAsEids).to.deep.equal(userIdAsEids);
170+
expect(payload.auctionId).to.equal('1d1a030790a475');
171+
expect(payload.bidderRequestId).to.equal('22edbae2733bf6');
168172
for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) {
169173
const u = payload.adUnits[i];
170174
expect(u).to.have.property('ChannelID').that.is.a('string');
171175
expect(u).to.not.have.property('cid');
172176
expect(u).to.have.property('adUnitCode').and.to.equal('adunit-code-2');
173177
expect(u).to.have.property('requestId').and.to.equal('3150ccb55da321');
174-
expect(u).to.have.property('userIds');
175-
expect(u.userIds).to.deep.equal(userId);
176-
expect(u).to.have.property('userIdAsEids');
177-
expect(u.userIdAsEids).to.deep.equal(userIdAsEids);
178+
expect(u).to.have.property('transactionId');
179+
expect(u).to.have.property('sizes');
180+
expect(u).to.have.property('mediaTypes');
181+
expect(u).to.have.property('ortb2Imp');
178182
}
179183
});
180184

@@ -213,16 +217,20 @@ describe('bridgewellBidAdapter', function () {
213217
expect(payload).to.be.an('object');
214218
expect(payload.adUnits).to.be.an('array');
215219
expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/');
220+
expect(payload.userIds).to.deep.equal(userId);
221+
expect(payload.userIdAsEids).to.deep.equal(userIdAsEids);
222+
expect(payload.auctionId).to.equal('1d1a030790a475');
223+
expect(payload.bidderRequestId).to.equal('22edbae2733bf6');
216224
for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) {
217225
const u = payload.adUnits[i];
218226
expect(u).to.have.property('cid').that.is.a('number');
219227
expect(u).to.not.have.property('ChannelID');
220228
expect(u).to.have.property('adUnitCode').and.to.equal('adunit-code-2');
221229
expect(u).to.have.property('requestId').and.to.equal('3150ccb55da321');
222-
expect(u).to.have.property('userIds');
223-
expect(u.userIds).to.deep.equal(userId);
224-
expect(u).to.have.property('userIdAsEids');
225-
expect(u.userIdAsEids).to.deep.equal(userIdAsEids);
230+
expect(u).to.have.property('transactionId');
231+
expect(u).to.have.property('sizes');
232+
expect(u).to.have.property('mediaTypes');
233+
expect(u).to.have.property('ortb2Imp');
226234
}
227235
});
228236

@@ -240,6 +248,178 @@ describe('bridgewellBidAdapter', function () {
240248
const validBidRequests = request.validBidRequests;
241249
expect(validBidRequests).to.deep.equal(bidRequests);
242250
});
251+
252+
it('should include ortb2Imp fields in adUnit', function () {
253+
const bidderRequest = {
254+
refererInfo: {
255+
page: 'https://www.bridgewell.com/',
256+
legacy: {
257+
referer: 'https://www.bridgewell.com/',
258+
}
259+
}
260+
}
261+
const bidRequestsWithOrtb2 = [
262+
{
263+
'bidder': 'bridgewell',
264+
'params': {
265+
'cid': 1234,
266+
},
267+
'adUnitCode': 'adunit-code-1',
268+
'transactionId': 'trans-123',
269+
'adUnitId': 'adunit-123',
270+
'sizes': [[300, 250]],
271+
'mediaTypes': {
272+
'banner': {
273+
'sizes': [[300, 250]]
274+
}
275+
},
276+
'bidId': 'bid-123',
277+
'ortb2Imp': {
278+
'ext': {
279+
'data': {
280+
'adserver': {
281+
'name': 'gam',
282+
'adslot': '/1234/test'
283+
},
284+
'pbadslot': '/1234/test-pbadslot'
285+
},
286+
'gpid': 'test-gpid',
287+
'prebid': {
288+
'passthrough': {
289+
'bucket': 'test-bucket',
290+
'client': 'test-client',
291+
'gamAdCode': 'test-gam',
292+
'undefinedField': undefined
293+
}
294+
}
295+
},
296+
'banner': {
297+
'pos': 1
298+
}
299+
},
300+
'userId': userId,
301+
'userIdAsEids': userIdAsEids,
302+
}
303+
];
304+
305+
const request = spec.buildRequests(bidRequestsWithOrtb2, bidderRequest);
306+
const adUnit = request.data.adUnits[0];
307+
308+
expect(adUnit.transactionId).to.equal('trans-123');
309+
expect(adUnit.adUnitId).to.equal('adunit-123');
310+
expect(adUnit.sizes).to.deep.equal([[300, 250]]);
311+
expect(adUnit.ortb2Imp.ext.data.adserver.name).to.equal('gam');
312+
expect(adUnit.ortb2Imp.ext.data.adserver.adslot).to.equal('/1234/test');
313+
expect(adUnit.ortb2Imp.ext.data.pbadslot).to.equal('/1234/test-pbadslot');
314+
expect(adUnit.ortb2Imp.ext.gpid).to.equal('test-gpid');
315+
expect(adUnit.ortb2Imp.banner.pos).to.equal(1);
316+
expect(adUnit.ortb2Imp.ext.prebid.passthrough).to.deep.equal({
317+
bucket: 'test-bucket',
318+
client: 'test-client',
319+
gamAdCode: 'test-gam'
320+
});
321+
expect(adUnit.ortb2Imp.ext.prebid.passthrough).to.not.have.property('undefinedField');
322+
});
323+
324+
it('should include floor information when getFloor is available', function () {
325+
const bidderRequest = {
326+
refererInfo: {
327+
page: 'https://www.bridgewell.com/',
328+
legacy: {
329+
referer: 'https://www.bridgewell.com/',
330+
}
331+
}
332+
}
333+
const bidRequestsWithFloor = [
334+
{
335+
'bidder': 'bridgewell',
336+
'params': {
337+
'cid': 1234,
338+
},
339+
'adUnitCode': 'adunit-code-1',
340+
'mediaTypes': {
341+
'banner': {
342+
'sizes': [[300, 250]]
343+
}
344+
},
345+
'bidId': 'bid-123',
346+
'getFloor': function() {
347+
return {
348+
floor: 1.5,
349+
currency: 'USD'
350+
};
351+
},
352+
'userId': userId,
353+
'userIdAsEids': userIdAsEids,
354+
}
355+
];
356+
357+
const request = spec.buildRequests(bidRequestsWithFloor, bidderRequest);
358+
const adUnit = request.data.adUnits[0];
359+
360+
expect(adUnit.floor).to.equal(1.5);
361+
expect(adUnit.currency).to.equal('USD');
362+
});
363+
364+
it('should include additional bid request fields in payload', function () {
365+
const bidderRequest = {
366+
refererInfo: {
367+
page: 'https://www.bridgewell.com/',
368+
ref: 'https://www.referrer.com/',
369+
legacy: {
370+
referer: 'https://www.bridgewell.com/',
371+
}
372+
},
373+
ortb2: {
374+
site: {
375+
name: 'test-site'
376+
}
377+
}
378+
}
379+
const bidRequestsWithMetrics = [
380+
{
381+
'bidder': 'bridgewell',
382+
'params': {
383+
'cid': 1234,
384+
},
385+
'adUnitCode': 'adunit-code-1',
386+
'mediaTypes': {
387+
'banner': {
388+
'sizes': [[300, 250]]
389+
}
390+
},
391+
'bidId': 'bid-123',
392+
'bidderRequestId': 'bidder-req-123',
393+
'auctionId': 'auction-123',
394+
'src': 's2s',
395+
'auctionsCount': 5,
396+
'bidRequestsCount': 10,
397+
'bidderRequestsCount': 3,
398+
'bidderWinsCount': 2,
399+
'deferBilling': true,
400+
'metrics': {
401+
'test': 'metric'
402+
},
403+
'userId': userId,
404+
'userIdAsEids': userIdAsEids,
405+
}
406+
];
407+
408+
const request = spec.buildRequests(bidRequestsWithMetrics, bidderRequest);
409+
const payload = request.data;
410+
411+
expect(payload.auctionId).to.equal('auction-123');
412+
expect(payload.bidderRequestId).to.equal('bidder-req-123');
413+
expect(payload.src).to.equal('s2s');
414+
expect(payload.auctionsCount).to.equal(5);
415+
expect(payload.bidRequestsCount).to.equal(10);
416+
expect(payload.bidderRequestsCount).to.equal(3);
417+
expect(payload.bidderWinsCount).to.equal(2);
418+
expect(payload.deferBilling).to.equal(true);
419+
expect(payload.metrics).to.deep.equal({test: 'metric'});
420+
expect(payload.referrer).to.equal('https://www.referrer.com/');
421+
expect(payload.ortb2).to.deep.equal({site: {name: 'test-site'}});
422+
});
243423
});
244424

245425
describe('interpretResponse', function () {

0 commit comments

Comments
 (0)