Skip to content

Commit

Permalink
Outbrain adapter: send placement and plcmt fields separately (#11799)
Browse files Browse the repository at this point in the history
* start sending placement and placmt separately

* move setOnAny function to utils

* remove transformSizes and use util function
  • Loading branch information
markkuhar authored Jul 1, 2024
1 parent 4f2ae43 commit 3192ed1
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 104 deletions.
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
}
}
Expand Down

0 comments on commit 3192ed1

Please sign in to comment.