Skip to content

Commit

Permalink
Add new window features to HB request
Browse files Browse the repository at this point in the history
  • Loading branch information
github-saad-elmahfoudi committed Dec 4, 2023
1 parent 7be0a10 commit b5afcbe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/teadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions test/spec/modules/teadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit b5afcbe

Please sign in to comment.