Skip to content

Commit e23dba3

Browse files
authored
Ogury Bid Adapter: Add device infos with size in bidrequest (#8416)
* Add device infos with size in bidrequest * trigger rebuild on CI to fix tests * restore sinon stubbed methods after all tests * restore stub correctly at end of tests * trigger rebuild on CI to fix tests
1 parent b2c496c commit e23dba3

File tree

2 files changed

+208
-4
lines changed

2 files changed

+208
-4
lines changed

modules/oguryBidAdapter.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,29 @@ const DEFAULT_TIMEOUT = 1000;
1010
const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request';
1111
const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io';
1212
const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io';
13-
const ADAPTER_VERSION = '1.2.11';
13+
const ADAPTER_VERSION = '1.2.12';
14+
15+
function getClientWidth() {
16+
const documentElementClientWidth = window.top.document.documentElement.clientWidth
17+
? window.top.document.documentElement.clientWidth
18+
: 0
19+
const innerWidth = window.top.innerWidth ? window.top.innerWidth : 0
20+
const outerWidth = window.top.outerWidth ? window.top.outerWidth : 0
21+
const screenWidth = window.top.screen.width ? window.top.screen.width : 0
22+
23+
return documentElementClientWidth || innerWidth || outerWidth || screenWidth
24+
}
25+
26+
function getClientHeight() {
27+
const documentElementClientHeight = window.top.document.documentElement.clientHeight
28+
? window.top.document.documentElement.clientHeight
29+
: 0
30+
const innerHeight = window.top.innerHeight ? window.top.innerHeight : 0
31+
const outerHeight = window.top.outerHeight ? window.top.outerHeight : 0
32+
const screenHeight = window.top.screen.height ? window.top.screen.height : 0
33+
34+
return documentElementClientHeight || innerHeight || outerHeight || screenHeight
35+
}
1436

1537
function isBidRequestValid(bid) {
1638
const adUnitSizes = getAdUnitSizes(bid);
@@ -60,6 +82,10 @@ function buildRequests(validBidRequests, bidderRequest) {
6082
ext: {
6183
adapterversion: ADAPTER_VERSION,
6284
prebidversion: '$prebid.version$'
85+
},
86+
device: {
87+
w: getClientWidth(),
88+
h: getClientHeight()
6389
}
6490
};
6591

test/spec/modules/oguryBidAdapter_spec.js

Lines changed: 181 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ describe('OguryBidAdapter', function () {
226226
});
227227

228228
describe('buildRequests', function () {
229+
const stubbedWidth = 200
230+
const stubbedHeight = 600
231+
const stubbedWidthMethod = sinon.stub(window.top.document.documentElement, 'clientWidth').get(function() {
232+
return stubbedWidth;
233+
});
234+
const stubbedHeightMethod = sinon.stub(window.top.document.documentElement, 'clientHeight').get(function() {
235+
return stubbedHeight;
236+
});
237+
229238
const defaultTimeout = 1000;
230239
const expectedRequestObject = {
231240
id: bidRequests[0].auctionId,
@@ -270,10 +279,19 @@ describe('OguryBidAdapter', function () {
270279
},
271280
ext: {
272281
prebidversion: '$prebid.version$',
273-
adapterversion: '1.2.11'
282+
adapterversion: '1.2.12'
283+
},
284+
device: {
285+
w: stubbedWidth,
286+
h: stubbedHeight
274287
}
275288
};
276289

290+
after(function() {
291+
stubbedWidthMethod.restore();
292+
stubbedHeightMethod.restore();
293+
});
294+
277295
it('sends bid request to ENDPOINT via POST', function () {
278296
const validBidRequests = utils.deepClone(bidRequests)
279297

@@ -290,6 +308,166 @@ describe('OguryBidAdapter', function () {
290308
expect(request.data.regs.ext.gdpr).to.be.a('number');
291309
});
292310

311+
describe('getClientWidth', () => {
312+
function testGetClientWidth(testGetClientSizeParams) {
313+
const stubbedClientWidth = sinon.stub(window.top.document.documentElement, 'clientWidth').get(function() {
314+
return testGetClientSizeParams.docClientSize
315+
})
316+
317+
const stubbedInnerWidth = sinon.stub(window.top, 'innerWidth').get(function() {
318+
return testGetClientSizeParams.innerSize
319+
})
320+
321+
const stubbedOuterWidth = sinon.stub(window.top, 'outerWidth').get(function() {
322+
return testGetClientSizeParams.outerSize
323+
})
324+
325+
const stubbedWidth = sinon.stub(window.top.screen, 'width').get(function() {
326+
return testGetClientSizeParams.screenSize
327+
})
328+
329+
const validBidRequests = utils.deepClone(bidRequests)
330+
331+
const request = spec.buildRequests(validBidRequests, bidderRequest);
332+
expect(request.data.device.w).to.equal(testGetClientSizeParams.expectedSize);
333+
334+
stubbedClientWidth.restore();
335+
stubbedInnerWidth.restore();
336+
stubbedOuterWidth.restore();
337+
stubbedWidth.restore();
338+
}
339+
340+
it('should get documentElementClientWidth by default', () => {
341+
testGetClientWidth({
342+
docClientSize: 22,
343+
innerSize: 50,
344+
outerSize: 45,
345+
screenSize: 10,
346+
expectedSize: 22,
347+
})
348+
})
349+
350+
it('should get innerWidth as first fallback', () => {
351+
testGetClientWidth({
352+
docClientSize: undefined,
353+
innerSize: 700,
354+
outerSize: 650,
355+
screenSize: 10,
356+
expectedSize: 700,
357+
})
358+
})
359+
360+
it('should get outerWidth as second fallback', () => {
361+
testGetClientWidth({
362+
docClientSize: undefined,
363+
innerSize: undefined,
364+
outerSize: 650,
365+
screenSize: 10,
366+
expectedSize: 650,
367+
})
368+
})
369+
370+
it('should get screenWidth as last fallback', () => {
371+
testGetClientWidth({
372+
docClientSize: undefined,
373+
innerSize: undefined,
374+
outerSize: undefined,
375+
screenSize: 10,
376+
expectedSize: 10,
377+
});
378+
});
379+
380+
it('should return 0 if all window width values are undefined', () => {
381+
testGetClientWidth({
382+
docClientSize: undefined,
383+
innerSize: undefined,
384+
outerSize: undefined,
385+
screenSize: undefined,
386+
expectedSize: 0,
387+
});
388+
});
389+
});
390+
391+
describe('getClientHeight', () => {
392+
function testGetClientHeight(testGetClientSizeParams) {
393+
const stubbedClientHeight = sinon.stub(window.top.document.documentElement, 'clientHeight').get(function() {
394+
return testGetClientSizeParams.docClientSize
395+
})
396+
397+
const stubbedInnerHeight = sinon.stub(window.top, 'innerHeight').get(function() {
398+
return testGetClientSizeParams.innerSize
399+
})
400+
401+
const stubbedOuterHeight = sinon.stub(window.top, 'outerHeight').get(function() {
402+
return testGetClientSizeParams.outerSize
403+
})
404+
405+
const stubbedHeight = sinon.stub(window.top.screen, 'height').get(function() {
406+
return testGetClientSizeParams.screenSize
407+
})
408+
409+
const validBidRequests = utils.deepClone(bidRequests)
410+
411+
const request = spec.buildRequests(validBidRequests, bidderRequest);
412+
expect(request.data.device.h).to.equal(testGetClientSizeParams.expectedSize);
413+
414+
stubbedClientHeight.restore();
415+
stubbedInnerHeight.restore();
416+
stubbedOuterHeight.restore();
417+
stubbedHeight.restore();
418+
}
419+
420+
it('should get documentElementClientHeight by default', () => {
421+
testGetClientHeight({
422+
docClientSize: 420,
423+
innerSize: 500,
424+
outerSize: 480,
425+
screenSize: 230,
426+
expectedSize: 420,
427+
});
428+
});
429+
430+
it('should get innerHeight as first fallback', () => {
431+
testGetClientHeight({
432+
docClientSize: undefined,
433+
innerSize: 500,
434+
outerSize: 480,
435+
screenSize: 230,
436+
expectedSize: 500,
437+
});
438+
});
439+
440+
it('should get outerHeight as second fallback', () => {
441+
testGetClientHeight({
442+
docClientSize: undefined,
443+
innerSize: undefined,
444+
outerSize: 480,
445+
screenSize: 230,
446+
expectedSize: 480,
447+
});
448+
});
449+
450+
it('should get screenHeight as last fallback', () => {
451+
testGetClientHeight({
452+
docClientSize: undefined,
453+
innerSize: undefined,
454+
outerSize: undefined,
455+
screenSize: 230,
456+
expectedSize: 230,
457+
});
458+
});
459+
460+
it('should return 0 if all window height values are undefined', () => {
461+
testGetClientHeight({
462+
docClientSize: undefined,
463+
innerSize: undefined,
464+
outerSize: undefined,
465+
screenSize: undefined,
466+
expectedSize: 0,
467+
});
468+
});
469+
});
470+
293471
it('should not add gdpr infos if not present', () => {
294472
const bidderRequestWithoutGdpr = {
295473
...bidderRequest,
@@ -481,7 +659,7 @@ describe('OguryBidAdapter', function () {
481659
advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[0].adomain
482660
},
483661
nurl: openRtbBidResponse.body.seatbid[0].bid[0].nurl,
484-
adapterVersion: '1.2.11',
662+
adapterVersion: '1.2.12',
485663
prebidVersion: '$prebid.version$'
486664
}, {
487665
requestId: openRtbBidResponse.body.seatbid[0].bid[1].impid,
@@ -498,7 +676,7 @@ describe('OguryBidAdapter', function () {
498676
advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[1].adomain
499677
},
500678
nurl: openRtbBidResponse.body.seatbid[0].bid[1].nurl,
501-
adapterVersion: '1.2.11',
679+
adapterVersion: '1.2.12',
502680
prebidVersion: '$prebid.version$'
503681
}]
504682

0 commit comments

Comments
 (0)