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

Audience Network (legacy): backport native non-IAB size fix #2558

Merged
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
32 changes: 29 additions & 3 deletions modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { registerBidder } from 'src/adapters/bidderFactory';
import { config } from 'src/config';
import { formatQS } from 'src/url';
import { getTopWindowUrl } from 'src/utils';
import includes from 'core-js/library/fn/array/includes';

const code = 'audienceNetwork';
const currency = 'USD';
Expand All @@ -24,7 +25,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).some(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 @@ -47,7 +49,24 @@ const expandSize = size => size.split('x').map(Number);
* @param {String} size
* @returns {Boolean}
*/
const isValidSize = size => ['300x250', '320x50'].includes(size);
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?
Expand All @@ -56,6 +75,13 @@ const isValidSize = size => ['300x250', '320x50'].includes(size);
*/
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 @@ -118,7 +144,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
13 changes: 12 additions & 1 deletion test/spec/modules/audienceNetworkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('AudienceNetwork adapter', () => {
it('fullwidth', () => {
expect(isBidRequestValid({
bidder,
sizes: [[300, 250]],
sizes: [[300, 250], [336, 280]],
params: {
placementId,
format: 'fullwidth'
Expand All @@ -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