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

Add a check against the size config when setting targeting #3183

Merged
merged 1 commit into from
Oct 17, 2018
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
15 changes: 1 addition & 14 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @module adaptermanger */

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

/**
* Returns object describing the status of labels on the adUnit or bidder along with labels passed into requestBids
* @param bidOrAdUnit the bidder or adUnit to get label info on
* @param activeLabels the labels passed to requestBids
* @returns {LabelDescriptor}
*/
function getLabels(bidOrAdUnit, activeLabels) {
if (bidOrAdUnit.labelAll) {
return {labelAll: true, labels: bidOrAdUnit.labelAll, activeLabels};
}
return {labelAll: false, labels: bidOrAdUnit.labelAny, activeLabels};
}

function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) {
return adUnits.reduce((result, adUnit) => {
let {
Expand Down
27 changes: 27 additions & 0 deletions src/sizeMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ export function setSizeConfig(config) {
}
config.getConfig('sizeConfig', config => setSizeConfig(config.sizeConfig));

/**
* Returns object describing the status of labels on the adUnit or bidder along with labels passed into requestBids
* @param bidOrAdUnit the bidder or adUnit to get label info on
* @param activeLabels the labels passed to requestBids
* @returns {LabelDescriptor}
*/
export function getLabels(bidOrAdUnit, activeLabels) {
if (bidOrAdUnit.labelAll) {
return {labelAll: true, labels: bidOrAdUnit.labelAll, activeLabels};
}
return {labelAll: false, labels: bidOrAdUnit.labelAny, activeLabels};
}

/**
* Determines whether a single size is valid given configured sizes
* @param {Array} size [width, height]
* @param {Array<SizeConfig>} configs
* @returns {boolean}
*/
export function sizeSupported(size, configs = sizeConfig) {
let maps = evaluateSizeConfig(configs);
if (!maps.shouldFilter) {
return true;
}
return !!maps.sizesSupported[size];
}

/**
* Resolves the unique set of the union of all sizes and labels that are active from a SizeConfig.mediaQuery match
* @param {Array<string>} labels Labels specified on adUnit or bidder
Expand Down
2 changes: 2 additions & 0 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { uniques, isGptPubadsDefined, getHighestCpm, getOldestHighestCpmBid, gro
import { config } from './config';
import { NATIVE_TARGETING_KEYS } from './native';
import { auctionManager } from './auctionManager';
import { sizeSupported } from './sizeMapping';
import includes from 'core-js/library/fn/array/includes';

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

function getBidsReceived() {
const bidsReceived = auctionManager.getBidsReceived()
.filter(bid => bid.mediaType !== 'banner' || sizeSupported([bid.width, bid.height]))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this bid.mediaType !== 'banner' here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size mapping only applies to (and filters) banner ads currently, so if it is not a banner bid then the filter will immediately let it through and not apply any size filtering.

.filter(isUnusedBid)
.filter(exports.isBidNotExpired)
;
Expand Down
9 changes: 8 additions & 1 deletion test/spec/sizeMapping_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { resolveStatus, setSizeConfig } from 'src/sizeMapping';
import { resolveStatus, setSizeConfig, sizeSupported } from 'src/sizeMapping';
import includes from 'core-js/library/fn/array/includes';

let utils = require('src/utils');
Expand Down Expand Up @@ -75,6 +75,13 @@ describe('sizeMapping', function () {
});

describe('when handling sizes', function () {
it('should allow us to validate a single size', function() {
matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false};

expect(sizeSupported([300, 250])).to.equal(true);
expect(sizeSupported([80, 80])).to.equal(false);
});

it('should log a warning when mediaQuery property missing from sizeConfig', function () {
let errorConfig = deepClone(sizeConfig);

Expand Down