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

Outbrain adapter: send placement and plcmt fields separately #11799

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
11 changes: 1 addition & 10 deletions modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {deepAccess, deepClone, deepSetValue, mergeDeep, parseSizesInput} from '../src/utils.js';
import {deepAccess, deepClone, deepSetValue, mergeDeep, parseSizesInput, setOnAny} from '../src/utils.js';
import {config} from '../src/config.js';
import {Renderer} from '../src/Renderer.js';

Expand Down Expand Up @@ -255,15 +255,6 @@ export const spec = {

registerBidder(spec);

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
Expand Down
11 changes: 1 addition & 10 deletions modules/codefuelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepAccess, isArray} from '../src/utils.js';
import {isArray, setOnAny} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

Expand Down Expand Up @@ -148,15 +148,6 @@ function getDeviceType() {
return 2; // 'desktop'
}

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
Expand Down
13 changes: 2 additions & 11 deletions modules/deltaprojectsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
isFn,
isNumber,
logError,
logWarn
logWarn,
setOnAny
} from '../src/utils.js';
import {config} from '../src/config.js';

Expand Down Expand Up @@ -234,16 +235,6 @@ export function getBidFloor(bid, mediaType, size, currency) {
}
}

/** -- Helper methods -- */
function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

/** -- Register -- */
export const spec = {
code: BIDDER_CODE,
Expand Down
10 changes: 1 addition & 9 deletions modules/dianomiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
parseSizesInput,
deepSetValue,
formatQS,
setOnAny
} from '../src/utils.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
Expand Down Expand Up @@ -355,15 +356,6 @@ function parseNative(bid) {
return result;
}

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
Expand Down
11 changes: 1 addition & 10 deletions modules/finativeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import {registerBidder} from '../src/adapters/bidderFactory.js';
import {NATIVE} from '../src/mediaTypes.js';
import {_map, deepAccess, deepSetValue, isEmpty} from '../src/utils.js';
import {_map, deepSetValue, isEmpty, setOnAny} from '../src/utils.js';
import {config} from '../src/config.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';

Expand Down Expand Up @@ -224,15 +224,6 @@ function parseNative(bid) {
return result;
}

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
11 changes: 1 addition & 10 deletions modules/mgidBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
isFn,
isNumber,
isBoolean,
isInteger, deepSetValue, getBidIdParameter,
isInteger, deepSetValue, getBidIdParameter, setOnAny
} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
Expand Down Expand Up @@ -431,15 +431,6 @@ export const spec = {

registerBidder(spec);

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

/**
* Unpack the Server's Bid into a Prebid-compatible one.
* @param serverBid
Expand Down
49 changes: 7 additions & 42 deletions modules/outbrainBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
import {OUTSTREAM} from '../src/video.js';
import {_map, deepAccess, deepSetValue, isArray, logWarn, replaceAuctionPrice} from '../src/utils.js';
import {_map, deepAccess, deepSetValue, logWarn, replaceAuctionPrice, setOnAny, parseGPTSingleSizeArrayToRtbSize} from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {config} from '../src/config.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
Expand Down Expand Up @@ -94,7 +94,7 @@ export const spec = {
imp.video = getVideoAsset(bid);
} else {
imp.banner = {
format: transformSizes(bid.sizes)
format: bid.sizes?.map((size) => parseGPTSingleSizeArrayToRtbSize(size))
}
}

Expand Down Expand Up @@ -174,7 +174,7 @@ export const spec = {
}
const { seatbid, cur } = serverResponse.body;

const bidResponses = flatten(seatbid.map(seat => seat.bid)).reduce((result, bid) => {
const bidResponses = seatbid.map(seat => seat.bid).flat().reduce((result, bid) => {
result[bid.impid - 1] = bid;
return result;
}, []);
Expand Down Expand Up @@ -288,19 +288,6 @@ function parseNative(bid) {
return result;
}

function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
}

function flatten(arr) {
return [].concat(...arr);
}

function getNativeAssets(bid) {
return _map(bid.nativeParams, (bidParams, key) => {
const props = NATIVE_PARAMS[key];
Expand All @@ -319,7 +306,7 @@ function getNativeAssets(bid) {
}

if (bidParams.sizes) {
const sizes = flatten(bidParams.sizes);
const sizes = bidParams.sizes.flat();
w = parseInt(sizes[0], 10);
h = parseInt(sizes[1], 10);
}
Expand All @@ -339,7 +326,7 @@ function getNativeAssets(bid) {
}

function getVideoAsset(bid) {
const sizes = flatten(bid.mediaTypes.video.playerSize);
const sizes = bid.mediaTypes.video.playerSize.flat();
return {
w: parseInt(sizes[0], 10),
h: parseInt(sizes[1], 10),
Expand All @@ -354,34 +341,12 @@ function getVideoAsset(bid) {
minduration: bid.mediaTypes.video.minduration,
maxduration: bid.mediaTypes.video.maxduration,
startdelay: bid.mediaTypes.video.startdelay,
placement: bid.mediaTypes.video.plcmt ?? bid.mediaTypes.video.placement,
placement: bid.mediaTypes.video.placement,
plcmt: bid.mediaTypes.video.plcmt,
linearity: bid.mediaTypes.video.linearity
};
}

/* Turn bid request sizes into ut-compatible format */
function transformSizes(requestSizes) {
if (!isArray(requestSizes)) {
return [];
}

if (requestSizes.length === 2 && !isArray(requestSizes[0])) {
return [{
w: parseInt(requestSizes[0], 10),
h: parseInt(requestSizes[1], 10)
}];
} else if (isArray(requestSizes[0])) {
return requestSizes.map(item =>
({
w: parseInt(item[0], 10),
h: parseInt(item[1], 10)
})
);
}

return [];
}

function _getFloor(bid, type) {
const floorInfo = bid.getFloor({
currency: CURRENCY,
Expand Down
20 changes: 19 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {includes} from './polyfill.js';
import { EVENTS, S2S } from './constants.js';
import {GreedyPromise} from './utils/promise.js';
import {getGlobal} from './prebidGlobal.js';
import { default as deepAccess } from 'dlv/index.js';

export { default as deepAccess } from 'dlv/index.js';
export { deepAccess };
export { dset as deepSetValue } from 'dset';

var tStr = 'String';
Expand Down Expand Up @@ -1231,3 +1232,20 @@ export function hasNonSerializableProperty(obj, checkedObjects = new Set()) {
}
return false;
}

/**
* Returns the value of a nested property in an array of objects.
*
* @param {Array} collection - Array of objects.
* @param {String} key - Key of nested property.
* @returns {any, undefined} - Value of nested property.
*/
export function setOnAny(collection, key) {
for (let i = 0, result; i < collection.length; i++) {
result = deepAccess(collection[i], key);
if (result) {
return result;
}
}
return undefined;
}
3 changes: 2 additions & 1 deletion test/spec/modules/outbrainBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ describe('Outbrain Adapter', function () {
minduration: 3,
maxduration: 10,
startdelay: 2,
placement: 4,
placement: 5,
plcmt: 4,
linearity: 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you simply ordered these two lines differently than your tests expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, it should be ok like this. Locally all the tests pass, I am really not sure what is the problem. Can you see excected vs. actual diff on circle ci?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It passed, if you print it to console somehow you can, but I'm sure others have a better way

}
}
Expand Down
Loading