Skip to content

Commit

Permalink
Teads Bid Adapter: add new window features to request (#10796)
Browse files Browse the repository at this point in the history
* Add new window features to HB request

* fixup! Add new window features to HB request
  • Loading branch information
github-saad-elmahfoudi authored Dec 6, 2023
1 parent 264efa7 commit bf909ea
Show file tree
Hide file tree
Showing 2 changed files with 65 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
58 changes: 58 additions & 0 deletions test/spec/modules/teadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect} from 'chai';
import {spec, storage} from 'modules/teadsBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';
import { off } from '../../../src/events';

const ENDPOINT = 'https://a.teads.tv/hb/bid-request';
const AD_SCRIPT = '<script type="text/javascript" class="teads" async="true" src="https://a.teads.tv/hb/getAdSettings"></script>"';
Expand Down Expand Up @@ -254,6 +255,63 @@ 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);
const screenOrientation = window.top.screen.orientation?.type

if (screenOrientation) {
expect(payload.screenOrientation).to.exist;
expect(payload.screenOrientation).to.deep.equal(screenOrientation);
} else expect(payload.screenOrientation).to.not.exist;
});

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);
const hardwareConcurrency = window.top.navigator?.hardwareConcurrency

if (hardwareConcurrency) {
expect(payload.hardwareConcurrency).to.exist;
expect(payload.hardwareConcurrency).to.deep.equal(hardwareConcurrency);
} else expect(payload.hardwareConcurrency).to.not.exist
});

it('should add deviceMemory info to payload', function () {
const request = spec.buildRequests(bidRequests, bidderRequestDefault);
const payload = JSON.parse(request.data);
const deviceMemory = window.top.navigator.deviceMemory

if (deviceMemory) {
expect(payload.deviceMemory).to.exist;
expect(payload.deviceMemory).to.deep.equal(deviceMemory);
} else expect(payload.deviceMemory).to.not.exist;
});

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 bf909ea

Please sign in to comment.