Skip to content

Commit

Permalink
Missena Bid Adapter : send bid sizes (#12560)
Browse files Browse the repository at this point in the history
* Missena Bid Adapter : send bid sizes

* Move function to utils

* Move the function to the proper place
  • Loading branch information
pdamoc authored Jan 15, 2025
1 parent f1019c1 commit 0954a82
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
25 changes: 25 additions & 0 deletions libraries/sizeUtils/sizeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,28 @@ export function getAdUnitSizes(adUnit) {
}
return sizes;
}

/**
* Normalize adUnit.mediaTypes.banner.sizes to Array.<Array.<number>>
*
* @param {Array.<number|string> | Array.<Array.<number|string>>} bidSizes - value of adUnit.mediaTypes.banner.sizes.
* @returns {Array.<Array.<number>>} - Normalized value.
*/

export function normalizeBannerSizes(bidSizes) {
let sizes = [];
if (Array.isArray(bidSizes) && bidSizes.length === 2 && !Array.isArray(bidSizes[0])) {
sizes.push({
width: parseInt(bidSizes[0], 10),
height: parseInt(bidSizes[1], 10),
});
} else if (Array.isArray(bidSizes) && Array.isArray(bidSizes[0])) {
bidSizes.forEach((size) => {
sizes.push({
width: parseInt(size[0], 10),
height: parseInt(size[1], 10),
});
});
}
return sizes;
}
2 changes: 2 additions & 0 deletions modules/missenaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { isAutoplayEnabled } from '../libraries/autoplayDetection/autoplay.js';
import { normalizeBannerSizes } from '../libraries/sizeUtils/sizeUtils.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -87,6 +88,7 @@ function toPayload(bidRequest, bidderRequest) {
payload.coppa = bidderRequest?.ortb2?.regs?.coppa ? 1 : 0;
payload.autoplay = isAutoplayEnabled() === true ? 1 : 0;
payload.screen = { height: screen.height, width: screen.width };
payload.sizes = normalizeBannerSizes(bidRequest.mediaTypes.banner.sizes);

return {
method: 'POST',
Expand Down
15 changes: 12 additions & 3 deletions test/spec/modules/missenaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('Missena Adapter', function () {
const bid = {
bidder: 'missena',
bidId: bidId,
sizes: [[1, 1]],
mediaTypes: { banner: { sizes: [[1, 1]] } },
ortb2: {
device: {
Expand Down Expand Up @@ -55,14 +54,14 @@ describe('Missena Adapter', function () {
const bidWithoutFloor = {
bidder: 'missena',
bidId: bidId,
sizes: [[1, 1]],
mediaTypes: { banner: { sizes: [[1, 1]] } },
mediaTypes: { banner: { sizes: [1, 1] } },
params: {
apiKey: API_KEY,
placement: 'sticky',
formats: ['sticky-banner'],
},
};

const consentString = 'AAAAAAAAA==';

const bidderRequest = {
Expand Down Expand Up @@ -178,6 +177,16 @@ describe('Missena Adapter', function () {
expect(payload.screen.height).to.equal(screen.height);
});

it('should send size', function () {
expect(payload.sizes[0].width).to.equal(1);
expect(payload.sizes[0].height).to.equal(1);
});

it('should send single size', function () {
expect(payloadNoFloor.sizes[0].width).to.equal(1);
expect(payloadNoFloor.sizes[0].height).to.equal(1);
});

getDataFromLocalStorageStub.restore();
getDataFromLocalStorageStub = sinon.stub(
storage,
Expand Down

0 comments on commit 0954a82

Please sign in to comment.