From b5afcbea912e6233c0afa41d303834f8fb711ed6 Mon Sep 17 00:00:00 2001 From: El Mahfoudi Saad Date: Mon, 4 Dec 2023 16:47:31 +0100 Subject: [PATCH] Add new window features to HB request --- modules/teadsBidAdapter.js | 7 ++++ test/spec/modules/teadsBidAdapter_spec.js | 48 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index 5e92af640b8..ba16c6ddf82 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -45,6 +45,7 @@ export const spec = { */ buildRequests: function(validBidRequests, bidderRequest) { const bids = validBidRequests.map(buildRequestObject); + const topWindow = window.top; const payload = { referrer: getReferrerInfo(bidderRequest), @@ -55,6 +56,12 @@ export const spec = { timeToFirstByte: getTimeToFirstByte(window), data: bids, deviceWidth: screen.width, + screenOrientation: screen.orientation?.type, + historyLength: topWindow.history?.length, + viewportHeight: topWindow.visualViewport?.height, + viewportWidth: topWindow.visualViewport?.width, + hardwareConcurrency: topWindow.navigator?.hardwareConcurrency, + deviceMemory: topWindow.navigator?.deviceMemory, hb_version: '$prebid.version$', ...getSharedViewerIdParameters(validBidRequests), ...getFirstPartyTeadsIdParameter(validBidRequests) diff --git a/test/spec/modules/teadsBidAdapter_spec.js b/test/spec/modules/teadsBidAdapter_spec.js index b0d5f436e0b..4c5bcdcfa31 100644 --- a/test/spec/modules/teadsBidAdapter_spec.js +++ b/test/spec/modules/teadsBidAdapter_spec.js @@ -254,6 +254,54 @@ describe('teadsBidAdapter', () => { expect(payload.pageReferrer).to.deep.equal(document.referrer); }); + it('should add screenOrientation info to payload', function () { + const request = spec.buildRequests(bidRequests, bidderRequestDefault); + const payload = JSON.parse(request.data); + + expect(payload.screenOrientation).to.exist; + expect(payload.screenOrientation).to.deep.equal(window.top.screen.orientation.type); + }); + + it('should add historyLength info to payload', function () { + const request = spec.buildRequests(bidRequests, bidderRequestDefault); + const payload = JSON.parse(request.data); + + expect(payload.historyLength).to.exist; + expect(payload.historyLength).to.deep.equal(window.top.history.length); + }); + + it('should add viewportHeight info to payload', function () { + const request = spec.buildRequests(bidRequests, bidderRequestDefault); + const payload = JSON.parse(request.data); + + expect(payload.viewportHeight).to.exist; + expect(payload.viewportHeight).to.deep.equal(window.top.visualViewport.height); + }); + + it('should add viewportWidth info to payload', function () { + const request = spec.buildRequests(bidRequests, bidderRequestDefault); + const payload = JSON.parse(request.data); + + expect(payload.viewportWidth).to.exist; + expect(payload.viewportWidth).to.deep.equal(window.top.visualViewport.width); + }); + + it('should add hardwareConcurrency info to payload', function () { + const request = spec.buildRequests(bidRequests, bidderRequestDefault); + const payload = JSON.parse(request.data); + + expect(payload.hardwareConcurrency).to.exist; + expect(payload.hardwareConcurrency).to.deep.equal(window.top.navigator.hardwareConcurrency); + }); + + it('should add deviceMemory info to payload', function () { + const request = spec.buildRequests(bidRequests, bidderRequestDefault); + const payload = JSON.parse(request.data); + + expect(payload.deviceMemory).to.exist; + expect(payload.deviceMemory).to.deep.equal(window.top.navigator.deviceMemory); + }); + describe('pageTitle', function () { it('should add pageTitle info to payload based on document title', function () { const testText = 'This is a title';