Skip to content

Commit

Permalink
Audience Network: allow native bids for non-IAB sizes (#2203)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell authored and harpere committed Mar 6, 2018
1 parent 95fe0a5 commit c54a179
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
29 changes: 27 additions & 2 deletions modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const isBidRequestValid = bid =>
typeof bid.params.placementId === 'string' &&
bid.params.placementId.length > 0 &&
Array.isArray(bid.sizes) && bid.sizes.length > 0 &&
(isVideo(bid.params.format) || bid.sizes.map(flattenSize).some(isValidSize));
(isFullWidth(bid.params.format) ? bid.sizes.map(flattenSize).every(size => size === '300x250') : true) &&
(isValidNonSizedFormat(bid.params.format) || bid.sizes.map(flattenSize).some(isValidSize));

/**
* Flattens a 2-element [W, H] array as a 'WxH' string,
Expand All @@ -51,13 +52,37 @@ const expandSize = size => size.split('x').map(Number);
*/
const isValidSize = size => includes(['300x250', '320x50'], size);

/**
* Is this a valid, non-sized format?
* @param {String} size
* @returns {Boolean}
*/
const isValidNonSizedFormat = format => includes(['video', 'native'], format);

/**
* Is this a valid size and format?
* @param {String} size
* @returns {Boolean}
*/
const isValidSizeAndFormat = (size, format) =>
(isFullWidth(format) && flattenSize(size) === '300x250') ||
isValidNonSizedFormat(format) ||
isValidSize(flattenSize(size));

/**
* Is this a video format?
* @param {String} format
* @returns {Boolean}
*/
const isVideo = format => format === 'video';

/**
* Is this a fullwidth format?
* @param {String} format
* @returns {Boolean}
*/
const isFullWidth = format => format === 'fullwidth';

/**
* Which SDK version should be used for this format?
* @param {String} format
Expand Down Expand Up @@ -120,7 +145,7 @@ const buildRequests = bids => {

bids.forEach(bid => bid.sizes
.map(flattenSize)
.filter(size => isValidSize(size) || isVideo(bid.params.format))
.filter(size => isValidSizeAndFormat(size, bid.params.format))
.slice(0, 1)
.forEach(size => {
placementids.push(bid.params.placementId);
Expand Down
49 changes: 49 additions & 0 deletions test/spec/modules/audienceNetworkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ describe('AudienceNetwork adapter', () => {
})).to.equal(true);
});

it('native with non-IAB size', () => {
expect(isBidRequestValid({
bidder,
sizes: [[728, 90]],
params: {
placementId,
format: 'native'
}
})).to.equal(true);
});

it('video', () => {
expect(isBidRequestValid({
bidder,
Expand Down Expand Up @@ -139,6 +150,44 @@ describe('AudienceNetwork adapter', () => {
data: 'placementids[]=test-placement-id&adformats[]=video&testmode=false&pageurl=&sdk[]=&playerwidth=640&playerheight=480'
}]);
});

it('can build URL for native unit in non-IAB size', () => {
expect(buildRequests([{
bidder,
bidId: requestId,
sizes: [[728, 90]],
params: {
placementId,
format: 'native'
}
}])).to.deep.equal([{
adformats: ['native'],
method: 'GET',
requestIds: [requestId],
sizes: ['728x90'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: 'placementids[]=test-placement-id&adformats[]=native&testmode=false&pageurl=&sdk[]=5.5.web'
}]);
});

it('can build URL for fullwidth 300x250 unit', () => {
expect(buildRequests([{
bidder,
bidId: requestId,
sizes: [[300, 250]],
params: {
placementId,
format: 'fullwidth'
}
}])).to.deep.equal([{
adformats: ['fullwidth'],
method: 'GET',
requestIds: [requestId],
sizes: ['300x250'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: 'placementids[]=test-placement-id&adformats[]=fullwidth&testmode=false&pageurl=&sdk[]=5.5.web'
}]);
});
});

describe('interpretResponse', () => {
Expand Down

0 comments on commit c54a179

Please sign in to comment.