Skip to content

Commit

Permalink
Seedtag Bid Adapter : add geom to bidRequest (#10906)
Browse files Browse the repository at this point in the history
* add adunit geometry parameter to the bid request

* lint

* add unit test

* add size check

* use global slot for all tests

* fix test when slot is not available$
  • Loading branch information
ybootin authored Jan 11, 2024
1 parent 000a0ad commit c2d4a88
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
23 changes: 22 additions & 1 deletion modules/seedtagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ function buildBidRequest(validBidRequest) {
return mediaTypesMap[pbjsType];
}
);

const bidRequest = {
id: validBidRequest.bidId,
transactionId: validBidRequest.ortb2Imp?.ext?.tid,
sizes: validBidRequest.sizes,
supplyTypes: mediaTypes,
adUnitId: params.adUnitId,
adUnitCode: validBidRequest.adUnitCode,
geom: geom(validBidRequest.adUnitCode),
placement: params.placement,
requestCount: validBidRequest.bidderRequestsCount || 1, // FIXME : in unit test the parameter bidderRequestsCount is undefined
};
Expand Down Expand Up @@ -198,6 +198,27 @@ function ttfb() {
return ttfb >= 0 && ttfb <= performance.now() ? ttfb : 0;
}

function geom(adunitCode) {
const slot = document.getElementById(adunitCode);
if (slot) {
const scrollY = window.scrollY;
const { top, left, width, height } = slot.getBoundingClientRect();
const viewport = {
width: window.innerWidth,
height: window.innerHeight,
};

return {
scrollY,
top,
left,
width,
height,
viewport,
};
}
}

export function getTimeoutUrl(data) {
let queryParams = '';
if (
Expand Down
54 changes: 52 additions & 2 deletions test/spec/modules/seedtagBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@ import { expect } from 'chai';
import { spec, getTimeoutUrl } from 'modules/seedtagBidAdapter.js';
import * as utils from 'src/utils.js';
import { config } from '../../../src/config.js';
import * as mockGpt from 'test/spec/integration/faker/googletag.js';

const PUBLISHER_ID = '0000-0000-01';
const ADUNIT_ID = '000000';

const adUnitCode = '/19968336/header-bid-tag-0'

// create a default adunit
const slot = document.createElement('div');
slot.id = adUnitCode;
slot.style.width = '300px'
slot.style.height = '250px'
slot.style.position = 'absolute'
slot.style.top = '10px'
slot.style.left = '20px'

document.body.appendChild(slot);

function getSlotConfigs(mediaTypes, params) {
return {
params: params,
Expand All @@ -25,7 +39,7 @@ function getSlotConfigs(mediaTypes, params) {
tid: 'd704d006-0d6e-4a09-ad6c-179e7e758096',
}
},
adUnitCode: 'adunit-code',
adUnitCode: adUnitCode,
};
}

Expand All @@ -46,6 +60,13 @@ const createBannerSlotConfig = (placement, mediatypes) => {
};

describe('Seedtag Adapter', function () {
beforeEach(function () {
mockGpt.reset();
});

afterEach(function () {
mockGpt.enable();
});
describe('isBidRequestValid method', function () {
describe('returns true', function () {
describe('when banner slot config has all mandatory params', () => {
Expand Down Expand Up @@ -277,7 +298,7 @@ describe('Seedtag Adapter', function () {
expect(data.auctionStart).to.be.greaterThanOrEqual(now);
expect(data.ttfb).to.be.greaterThanOrEqual(0);

expect(data.bidRequests[0].adUnitCode).to.equal('adunit-code');
expect(data.bidRequests[0].adUnitCode).to.equal(adUnitCode);
});

describe('GDPR params', function () {
Expand Down Expand Up @@ -374,6 +395,35 @@ describe('Seedtag Adapter', function () {
expect(videoBid.sizes[1][1]).to.equal(600);
expect(videoBid.requestCount).to.equal(1);
});

it('should have geom parameters if slot is available', function() {
const request = spec.buildRequests(validBidRequests, bidderRequest);
const data = JSON.parse(request.data);
const bidRequests = data.bidRequests;
const bannerBid = bidRequests[0];

// on some CI, the DOM is not initialized, so we need to check if the slot is available
const slot = document.getElementById(adUnitCode)
if (slot) {
expect(bannerBid).to.have.property('geom')

const params = [['width', 300], ['height', 250], ['top', 10], ['left', 20], ['scrollY', 0]]
params.forEach(([param, value]) => {
expect(bannerBid.geom).to.have.property(param)
expect(bannerBid.geom[param]).to.be.a('number')
expect(bannerBid.geom[param]).to.be.equal(value)
})

expect(bannerBid.geom).to.have.property('viewport')
const viewportParams = ['width', 'height']
viewportParams.forEach(param => {
expect(bannerBid.geom.viewport).to.have.property(param)
expect(bannerBid.geom.viewport[param]).to.be.a('number')
})
} else {
expect(bannerBid).to.not.have.property('geom')
}
})
});

describe('COPPA param', function () {
Expand Down

0 comments on commit c2d4a88

Please sign in to comment.