Skip to content

Commit

Permalink
Add device infos with size in bidrequest
Browse files Browse the repository at this point in the history
  • Loading branch information
jogury committed May 16, 2022
1 parent 873d314 commit 4766598
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 4 deletions.
28 changes: 27 additions & 1 deletion modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,29 @@ const DEFAULT_TIMEOUT = 1000;
const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io';
const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io';
const ADAPTER_VERSION = '1.2.11';
const ADAPTER_VERSION = '1.2.12';

function getClientWidth() {
const documentElementClientWidth = window.top.document.documentElement.clientWidth
? window.top.document.documentElement.clientWidth
: 0
const innerWidth = window.top.innerWidth ? window.top.innerWidth : 0
const outerWidth = window.top.outerWidth ? window.top.outerWidth : 0
const screenWidth = window.top.screen.width ? window.top.screen.width : 0

return documentElementClientWidth || innerWidth || outerWidth || screenWidth
}

function getClientHeight() {
const documentElementClientHeight = window.top.document.documentElement.clientHeight
? window.top.document.documentElement.clientHeight
: 0
const innerHeight = window.top.innerHeight ? window.top.innerHeight : 0
const outerHeight = window.top.outerHeight ? window.top.outerHeight : 0
const screenHeight = window.top.screen.height ? window.top.screen.height : 0

return documentElementClientHeight || innerHeight || outerHeight || screenHeight
}

function isBidRequestValid(bid) {
const adUnitSizes = getAdUnitSizes(bid);
Expand Down Expand Up @@ -60,6 +82,10 @@ function buildRequests(validBidRequests, bidderRequest) {
ext: {
adapterversion: ADAPTER_VERSION,
prebidversion: '$prebid.version$'
},
device: {
w: getClientWidth(),
h: getClientHeight()
}
};

Expand Down
170 changes: 167 additions & 3 deletions test/spec/modules/oguryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ describe('OguryBidAdapter', function () {
});

describe('buildRequests', function () {
const stubbedWidth = 200
const stubbedHeight = 600
sinon.stub(window.top.document.documentElement, 'clientWidth').get(function() {
return stubbedWidth;
});

sinon.stub(window.top.document.documentElement, 'clientHeight').get(function() {
return stubbedHeight;
});

const defaultTimeout = 1000;
const expectedRequestObject = {
id: bidRequests[0].auctionId,
Expand Down Expand Up @@ -270,7 +280,11 @@ describe('OguryBidAdapter', function () {
},
ext: {
prebidversion: '$prebid.version$',
adapterversion: '1.2.11'
adapterversion: '1.2.12'
},
device: {
w: stubbedWidth,
h: stubbedHeight
}
};

Expand All @@ -290,6 +304,156 @@ describe('OguryBidAdapter', function () {
expect(request.data.regs.ext.gdpr).to.be.a('number');
});

describe('getClientWidth', () => {
function testGetClientWidth(testGetClientSizeParams) {
sinon.stub(window.top.document.documentElement, 'clientWidth').get(function() {
return testGetClientSizeParams.docClientSize
})

sinon.stub(window.top, 'innerWidth').get(function() {
return testGetClientSizeParams.innerSize
})

sinon.stub(window.top, 'outerWidth').get(function() {
return testGetClientSizeParams.outerSize
})

sinon.stub(window.top.screen, 'width').get(function() {
return testGetClientSizeParams.screenSize
})

const validBidRequests = utils.deepClone(bidRequests)

const request = spec.buildRequests(validBidRequests, bidderRequest);
expect(request.data.device.w).to.equal(testGetClientSizeParams.expectedSize);
}

it('should get documentElementClientWidth by default', () => {
testGetClientWidth({
docClientSize: 22,
innerSize: 50,
outerSize: 45,
screenSize: 10,
expectedSize: 22,
})
})

it('should get innerWidth as first fallback', () => {
testGetClientWidth({
docClientSize: undefined,
innerSize: 700,
outerSize: 650,
screenSize: 10,
expectedSize: 700,
})
})

it('should get outerWidth as second fallback', () => {
testGetClientWidth({
docClientSize: undefined,
innerSize: undefined,
outerSize: 650,
screenSize: 10,
expectedSize: 650,
})
})

it('should get screenWidth as last fallback', () => {
testGetClientWidth({
docClientSize: undefined,
innerSize: undefined,
outerSize: undefined,
screenSize: 10,
expectedSize: 10,
});
});

it('should return 0 if all window width values are undefined', () => {
testGetClientWidth({
docClientSize: undefined,
innerSize: undefined,
outerSize: undefined,
screenSize: undefined,
expectedSize: 0,
});
});
});

describe('getClientHeight', () => {
function testGetClientHeight(testGetClientSizeParams) {
sinon.stub(window.top.document.documentElement, 'clientHeight').get(function() {
return testGetClientSizeParams.docClientSize
})

sinon.stub(window.top, 'innerHeight').get(function() {
return testGetClientSizeParams.innerSize
})

sinon.stub(window.top, 'outerHeight').get(function() {
return testGetClientSizeParams.outerSize
})

sinon.stub(window.top.screen, 'height').get(function() {
return testGetClientSizeParams.screenSize
})

const validBidRequests = utils.deepClone(bidRequests)

const request = spec.buildRequests(validBidRequests, bidderRequest);
expect(request.data.device.h).to.equal(testGetClientSizeParams.expectedSize);
}

it('should get documentElementClientHeight by default', () => {
testGetClientHeight({
docClientSize: 420,
innerSize: 500,
outerSize: 480,
screenSize: 230,
expectedSize: 420,
});
});

it('should get innerHeight as first fallback', () => {
testGetClientHeight({
docClientSize: undefined,
innerSize: 500,
outerSize: 480,
screenSize: 230,
expectedSize: 500,
});
});

it('should get outerHeight as second fallback', () => {
testGetClientHeight({
docClientSize: undefined,
innerSize: undefined,
outerSize: 480,
screenSize: 230,
expectedSize: 480,
});
});

it('should get screenHeight as last fallback', () => {
testGetClientHeight({
docClientSize: undefined,
innerSize: undefined,
outerSize: undefined,
screenSize: 230,
expectedSize: 230,
});
});

it('should return 0 if all window height values are undefined', () => {
testGetClientHeight({
docClientSize: undefined,
innerSize: undefined,
outerSize: undefined,
screenSize: undefined,
expectedSize: 0,
});
});
});

it('should not add gdpr infos if not present', () => {
const bidderRequestWithoutGdpr = {
...bidderRequest,
Expand Down Expand Up @@ -481,7 +645,7 @@ describe('OguryBidAdapter', function () {
advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[0].adomain
},
nurl: openRtbBidResponse.body.seatbid[0].bid[0].nurl,
adapterVersion: '1.2.11',
adapterVersion: '1.2.12',
prebidVersion: '$prebid.version$'
}, {
requestId: openRtbBidResponse.body.seatbid[0].bid[1].impid,
Expand All @@ -498,7 +662,7 @@ describe('OguryBidAdapter', function () {
advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[1].adomain
},
nurl: openRtbBidResponse.body.seatbid[0].bid[1].nurl,
adapterVersion: '1.2.11',
adapterVersion: '1.2.12',
prebidVersion: '$prebid.version$'
}]

Expand Down

0 comments on commit 4766598

Please sign in to comment.