Skip to content

Commit

Permalink
otm prioritize sizes (prebid#3642)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedotxxl authored and mike-chowla committed Mar 15, 2019
1 parent 8c5f26e commit 7cfb94b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
43 changes: 39 additions & 4 deletions modules/otmBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BANNER} from '../src/mediaTypes';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER} from 'src/mediaTypes';
import {registerBidder} from 'src/adapters/bidderFactory';

export const spec = {
code: 'otm',
Expand All @@ -9,10 +9,11 @@ export const spec = {
},
buildRequests: function (bidRequests) {
const requests = bidRequests.map(function (bid) {
const size = getMaxPrioritySize(bid.sizes);
const params = {
tz: getTz(),
w: bid.sizes[0][0],
h: bid.sizes[0][1],
w: size[0],
h: size[1],
s: bid.params.tid,
bidid: bid.bidId,
transactionid: bid.transactionId,
Expand Down Expand Up @@ -57,4 +58,38 @@ function getTz() {
return new Date().getTimezoneOffset();
}

function getMaxPrioritySize(sizes) {
var maxPrioritySize = null;

const sizesByPriority = [
[300, 250],
[240, 400],
[728, 90],
[300, 600],
[970, 250],
[300, 50],
[320, 100]
];

const sizeToString = (size) => {
return size[0] + 'x' + size[1];
};

const sizesAsString = sizes.map(sizeToString);

sizesByPriority.forEach(size => {
if (!maxPrioritySize) {
if (sizesAsString.indexOf(sizeToString(size)) !== -1) {
maxPrioritySize = size;
}
}
});

if (maxPrioritySize) {
return maxPrioritySize;
} else {
return sizes[0];
}
}

registerBidder(spec);
38 changes: 38 additions & 0 deletions test/spec/modules/otmBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ describe('otmBidAdapterTests', function () {
expect(req_data.bidid).to.equal('bid1234');
});

it('validate_best_size_select', function () {
// when:
let bidRequestData = [{
bidId: 'bid1234',
bidder: 'otm',
params: {
tid: '123',
bidfloor: 20
},
sizes: [[300, 500], [300, 600], [240, 400], [300, 50]]
}];

let request = spec.buildRequests(bidRequestData);
let req_data = request[0].data;

// then:
expect(req_data.w).to.equal(240);
expect(req_data.h).to.equal(400);

// when:
bidRequestData = [{
bidId: 'bid1234',
bidder: 'otm',
params: {
tid: '123',
bidfloor: 20
},
sizes: [[200, 240], [400, 440]]
}];

request = spec.buildRequests(bidRequestData);
req_data = request[0].data;

// then:
expect(req_data.w).to.equal(200);
expect(req_data.h).to.equal(240);
});

it('validate_response_params', function () {
let bidRequestData = {
data: {
Expand Down

0 comments on commit 7cfb94b

Please sign in to comment.