Skip to content

Commit b74b366

Browse files
authored
FPD Enrichment: Replace device values w and h with screen size; add ext.vpw and ext.vph (#12108)
1 parent 284058f commit b74b366

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

src/fpd/enrichment.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,24 @@ const ENRICHMENTS = {
9999
},
100100
device() {
101101
return winFallback((win) => {
102-
const w = win.innerWidth || win.document.documentElement.clientWidth || win.document.body.clientWidth;
103-
const h = win.innerHeight || win.document.documentElement.clientHeight || win.document.body.clientHeight;
102+
// screen.width and screen.height are the physical dimensions of the screen
103+
const w = win.screen.width;
104+
const h = win.screen.height;
105+
106+
// vpw and vph are the viewport dimensions of the browser window
107+
const vpw = win.innerWidth || win.document.documentElement.clientWidth || win.document.body.clientWidth;
108+
const vph = win.innerHeight || win.document.documentElement.clientHeight || win.document.body.clientHeight;
104109

105110
const device = {
106111
w,
107112
h,
108113
dnt: getDNT() ? 1 : 0,
109114
ua: win.navigator.userAgent,
110115
language: win.navigator.language.split('-').shift(),
116+
ext: {
117+
vpw,
118+
vph,
119+
},
111120
};
112121

113122
if (win.navigator?.webdriver) {

test/spec/fpd/enrichment_spec.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ describe('FPD enrichment', () => {
3434
},
3535
document: {
3636
querySelector: sinon.stub()
37-
}
37+
},
38+
screen: {
39+
width: 1,
40+
height: 1,
41+
},
3842
};
3943
}
4044

@@ -156,8 +160,8 @@ describe('FPD enrichment', () => {
156160
});
157161
testWindows(() => win, () => {
158162
it('sets w/h', () => {
159-
win.innerHeight = 123;
160-
win.innerWidth = 321;
163+
win.screen.width = 321;
164+
win.screen.height = 123;
161165
return fpd().then(ortb2 => {
162166
sinon.assert.match(ortb2.device, {
163167
w: 321,
@@ -166,6 +170,17 @@ describe('FPD enrichment', () => {
166170
});
167171
});
168172

173+
it('sets ext.vpw/vph', () => {
174+
win.innerWidth = 12;
175+
win.innerHeight = 21;
176+
return fpd().then(ortb2 => {
177+
sinon.assert.match(ortb2.device.ext, {
178+
vpw: 12,
179+
vph: 21,
180+
});
181+
});
182+
});
183+
169184
describe('ext.webdriver', () => {
170185
it('when navigator.webdriver is available', () => {
171186
win.navigator.webdriver = true;

test/spec/modules/asoBidAdapter_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ describe('Adserver.Online bidding adapter', function () {
200200
expect(payload.site.page).to.equal('https://example.com/page.html');
201201

202202
expect(payload.device).to.exist;
203-
expect(payload.device.w).to.equal(window.innerWidth);
204-
expect(payload.device.h).to.equal(window.innerHeight);
203+
expect(payload.device.w).to.equal(window.screen.width);
204+
expect(payload.device.h).to.equal(window.screen.height);
205205

206206
expect(payload.imp).to.have.lengthOf(1);
207207

@@ -229,8 +229,8 @@ describe('Adserver.Online bidding adapter', function () {
229229
expect(payload.site.page).to.equal('https://example.com/page.html');
230230

231231
expect(payload.device).to.exist;
232-
expect(payload.device.w).to.equal(window.innerWidth);
233-
expect(payload.device.h).to.equal(window.innerHeight);
232+
expect(payload.device.w).to.equal(window.screen.width);
233+
expect(payload.device.h).to.equal(window.screen.height);
234234

235235
expect(payload.imp).to.have.lengthOf(1);
236236

@@ -258,8 +258,8 @@ describe('Adserver.Online bidding adapter', function () {
258258
expect(payload.site.page).to.equal('https://example.com/page.html');
259259

260260
expect(payload.device).to.exist;
261-
expect(payload.device.w).to.equal(window.innerWidth);
262-
expect(payload.device.h).to.equal(window.innerHeight);
261+
expect(payload.device.w).to.equal(window.screen.width);
262+
expect(payload.device.h).to.equal(window.screen.height);
263263

264264
expect(payload.imp).to.have.lengthOf(1);
265265

test/spec/modules/prebidServerBidAdapter_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,8 @@ describe('S2S Adapter', function () {
10881088
const requestBid = JSON.parse(server.requests[0].requestBody);
10891089
sinon.assert.match(requestBid.device, {
10901090
ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC',
1091-
w: window.innerWidth,
1092-
h: window.innerHeight
1091+
w: window.screen.width,
1092+
h: window.screen.height,
10931093
})
10941094
sinon.assert.match(requestBid.app, {
10951095
bundle: 'com.test.app',
@@ -1120,8 +1120,8 @@ describe('S2S Adapter', function () {
11201120
const requestBid = JSON.parse(server.requests[0].requestBody);
11211121
sinon.assert.match(requestBid.device, {
11221122
ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC',
1123-
w: window.innerWidth,
1124-
h: window.innerHeight
1123+
w: window.screen.width,
1124+
h: window.screen.height,
11251125
})
11261126
sinon.assert.match(requestBid.app, {
11271127
bundle: 'com.test.app',
@@ -1480,8 +1480,8 @@ describe('S2S Adapter', function () {
14801480
adapter.callBids(addFpdEnrichmentsToS2SRequest(REQUEST, BID_REQUESTS), BID_REQUESTS, addBidResponse, done, ajax);
14811481
const requestBid = JSON.parse(server.requests[0].requestBody);
14821482
sinon.assert.match(requestBid.device, {
1483-
w: window.innerWidth,
1484-
h: window.innerHeight
1483+
w: window.screen.width,
1484+
h: window.screen.height,
14851485
})
14861486
expect(requestBid.imp[0].native.ver).to.equal('1.2');
14871487
});

0 commit comments

Comments
 (0)