Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teads Bid Adapter: add new window features to request #10796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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