Skip to content

Commit 175a7ca

Browse files
authored
add a check against the size config when setting targeting (#3183)
1 parent 79af988 commit 175a7ca

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

src/adaptermanager.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @module adaptermanger */
22

33
import { flatten, getBidderCodes, getDefinedParams, shuffle, timestamp } from './utils';
4-
import { resolveStatus } from './sizeMapping';
4+
import { getLabels, resolveStatus } from './sizeMapping';
55
import { processNativeAdUnitParams, nativeAdapters } from './native';
66
import { newBidder } from './adapters/bidderFactory';
77
import { ajaxBuilder } from 'src/ajax';
@@ -34,19 +34,6 @@ var _analyticsRegistry = {};
3434
* @property {Array<string>} activeLabels the labels specified as being active by requestBids
3535
*/
3636

37-
/**
38-
* Returns object describing the status of labels on the adUnit or bidder along with labels passed into requestBids
39-
* @param bidOrAdUnit the bidder or adUnit to get label info on
40-
* @param activeLabels the labels passed to requestBids
41-
* @returns {LabelDescriptor}
42-
*/
43-
function getLabels(bidOrAdUnit, activeLabels) {
44-
if (bidOrAdUnit.labelAll) {
45-
return {labelAll: true, labels: bidOrAdUnit.labelAll, activeLabels};
46-
}
47-
return {labelAll: false, labels: bidOrAdUnit.labelAny, activeLabels};
48-
}
49-
5037
function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) {
5138
return adUnits.reduce((result, adUnit) => {
5239
let {

src/sizeMapping.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,33 @@ export function setSizeConfig(config) {
2424
}
2525
config.getConfig('sizeConfig', config => setSizeConfig(config.sizeConfig));
2626

27+
/**
28+
* Returns object describing the status of labels on the adUnit or bidder along with labels passed into requestBids
29+
* @param bidOrAdUnit the bidder or adUnit to get label info on
30+
* @param activeLabels the labels passed to requestBids
31+
* @returns {LabelDescriptor}
32+
*/
33+
export function getLabels(bidOrAdUnit, activeLabels) {
34+
if (bidOrAdUnit.labelAll) {
35+
return {labelAll: true, labels: bidOrAdUnit.labelAll, activeLabels};
36+
}
37+
return {labelAll: false, labels: bidOrAdUnit.labelAny, activeLabels};
38+
}
39+
40+
/**
41+
* Determines whether a single size is valid given configured sizes
42+
* @param {Array} size [width, height]
43+
* @param {Array<SizeConfig>} configs
44+
* @returns {boolean}
45+
*/
46+
export function sizeSupported(size, configs = sizeConfig) {
47+
let maps = evaluateSizeConfig(configs);
48+
if (!maps.shouldFilter) {
49+
return true;
50+
}
51+
return !!maps.sizesSupported[size];
52+
}
53+
2754
/**
2855
* Resolves the unique set of the union of all sizes and labels that are active from a SizeConfig.mediaQuery match
2956
* @param {Array<string>} labels Labels specified on adUnit or bidder

src/targeting.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { uniques, isGptPubadsDefined, getHighestCpm, getOldestHighestCpmBid, gro
22
import { config } from './config';
33
import { NATIVE_TARGETING_KEYS } from './native';
44
import { auctionManager } from './auctionManager';
5+
import { sizeSupported } from './sizeMapping';
56
import includes from 'core-js/library/fn/array/includes';
67

78
const utils = require('./utils.js');
@@ -198,6 +199,7 @@ export function newTargeting(auctionManager) {
198199

199200
function getBidsReceived() {
200201
const bidsReceived = auctionManager.getBidsReceived()
202+
.filter(bid => bid.mediaType !== 'banner' || sizeSupported([bid.width, bid.height]))
201203
.filter(isUnusedBid)
202204
.filter(exports.isBidNotExpired)
203205
;

test/spec/sizeMapping_spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { resolveStatus, setSizeConfig } from 'src/sizeMapping';
2+
import { resolveStatus, setSizeConfig, sizeSupported } from 'src/sizeMapping';
33
import includes from 'core-js/library/fn/array/includes';
44

55
let utils = require('src/utils');
@@ -75,6 +75,13 @@ describe('sizeMapping', function () {
7575
});
7676

7777
describe('when handling sizes', function () {
78+
it('should allow us to validate a single size', function() {
79+
matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false};
80+
81+
expect(sizeSupported([300, 250])).to.equal(true);
82+
expect(sizeSupported([80, 80])).to.equal(false);
83+
});
84+
7885
it('should log a warning when mediaQuery property missing from sizeConfig', function () {
7986
let errorConfig = deepClone(sizeConfig);
8087

0 commit comments

Comments
 (0)