Skip to content

Commit

Permalink
Merge branch 'master' of github.com:prebid/Prebid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoscani committed Oct 6, 2020
2 parents 1acd03e + ea498f9 commit 12f5974
Show file tree
Hide file tree
Showing 38 changed files with 590 additions and 526 deletions.
97 changes: 72 additions & 25 deletions modules/adotBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import {Renderer} from '../src/Renderer.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {isStr, isArray, isNumber, isPlainObject, isBoolean, logError} from '../src/utils.js';
import {isStr, isArray, isNumber, isPlainObject, isBoolean, logError, replaceAuctionPrice} from '../src/utils.js';
import find from 'core-js-pure/features/array/find.js';

const ADAPTER_VERSION = 'v1.0.0';
const BID_METHOD = 'POST';
const BIDDER_URL = 'https://dsp.adotmob.com/headerbidding/bidrequest';
const FIRST_PRICE = 1;
const NET_REVENUE = true;
// eslint-disable-next-line no-template-curly-in-string
const AUCTION_PRICE = '${AUCTION_PRICE}';
const TTL = 10;

const SUPPORTED_VIDEO_CONTEXTS = ['instream', 'outstream'];
const SUPPORTED_INSTREAM_CONTEXTS = ['pre-roll', 'mid-roll', 'post-roll'];
const SUPPORTED_VIDEO_MIMES = ['video/mp4'];
const BID_SUPPORTED_MEDIA_TYPES = ['banner', 'video', 'native'];

const DOMAIN_REGEX = new RegExp('//([^/]*)');
const OUTSTREAM_VIDEO_PLAYER_URL = 'https://adserver.adotmob.com/video/player.min.js';

const NATIVE_PLACEMENTS = {
title: {id: 1, name: 'title'},
icon: {id: 2, type: 1, name: 'img'},
Expand All @@ -18,15 +30,9 @@ const NATIVE_PLACEMENTS = {
cta: {id: 6, type: 12, name: 'data'}
};
const NATIVE_ID_MAPPING = {1: 'title', 2: 'icon', 3: 'image', 4: 'sponsoredBy', 5: 'body', 6: 'cta'};
const SUPPORTED_VIDEO_MIMES = ['video/mp4'];
const DOMAIN_REGEX = new RegExp('//([^/]*)');
const FIRST_PRICE = 1;
const BID_SUPPORTED_MEDIA_TYPES = ['banner', 'video', 'native'];
const TTL = 10;
const NET_REVENUE = true;
// eslint-disable-next-line no-template-curly-in-string
const AUCTION_PRICE = '${AUCTION_PRICE}';
const OUTSTREAM_VIDEO_PLAYER_URL = 'https://adserver.adotmob.com/video/player.min.js';
const NATIVE_PRESET_FORMATTERS = {
image: formatNativePresetImage
}

function isNone(value) {
return (value === null) || (value === undefined);
Expand Down Expand Up @@ -183,6 +189,7 @@ function generateImpressionsFromAdUnit(acc, adUnit) {
const {bidId, mediaTypes, params} = adUnit;
const {placementId} = params;
const pmp = {};
const ext = {placementId};

if (placementId) pmp.deals = [{id: placementId}]

Expand All @@ -193,8 +200,8 @@ function generateImpressionsFromAdUnit(acc, adUnit) {
const impId = `${bidId}_${index}`;

if (mediaType === 'banner') return acc.concat(generateBannerFromAdUnit(impId, data, params));
if (mediaType === 'video') return acc.concat({id: impId, video: generateVideoFromAdUnit(data, params), pmp});
if (mediaType === 'native') return acc.concat({id: impId, native: generateNativeFromAdUnit(data, params), pmp});
if (mediaType === 'video') return acc.concat({id: impId, video: generateVideoFromAdUnit(data, params), pmp, ext});
if (mediaType === 'native') return acc.concat({id: impId, native: generateNativeFromAdUnit(data, params), pmp, ext});
}, []);

return acc.concat(imps);
Expand All @@ -208,10 +215,11 @@ function generateBannerFromAdUnit(impId, data, params) {
const {position, placementId} = params;
const pos = position || 0;
const pmp = {};
const ext = {placementId};

if (placementId) pmp.deals = [{id: placementId}]

return data.sizes.map(([w, h], index) => ({id: `${impId}_${index}`, banner: {format: [{w, h}], w, h, pos}, pmp}));
return data.sizes.map(([w, h], index) => ({id: `${impId}_${index}`, banner: {format: [{w, h}], w, h, pos}, pmp, ext}));
}

function generateVideoFromAdUnit(data, params) {
Expand Down Expand Up @@ -254,19 +262,31 @@ function computeStartDelay(data, params) {
}

function generateNativeFromAdUnit(data, params) {
const placements = NATIVE_PLACEMENTS;
const {type} = data;
const presetFormatter = type && NATIVE_PRESET_FORMATTERS[data.type];
const nativeFields = presetFormatter ? presetFormatter(data) : data;

const assets = Object
.keys(data)
.keys(nativeFields)
.reduce((acc, placement) => {
const placementData = data[placement];
const assetInfo = placements[placement];
const placementData = nativeFields[placement];
const assetInfo = NATIVE_PLACEMENTS[placement];

if (!assetInfo) return acc;

const {id, name, type} = assetInfo;
const {required, len, sizes} = placementData;
const wmin = sizes && sizes[0];
const hmin = sizes && sizes[1];
const {required, len, sizes = []} = placementData;
let wmin;
let hmin;

if (isArray(sizes[0])) {
wmin = sizes[0][0];
hmin = sizes[0][1];
} else {
wmin = sizes[0];
hmin = sizes[1];
}

const content = {};

if (type) content.type = type;
Expand All @@ -284,6 +304,32 @@ function generateNativeFromAdUnit(data, params) {
};
}

function formatNativePresetImage(data) {
const sizes = data.sizes;

return {
image: {
required: true,
sizes
},
title: {
required: true
},
sponsoredBy: {
required: true
},
body: {
required: false
},
cta: {
required: false
},
icon: {
required: false
}
};
}

function generateSiteFromAdUnitContext(adUnitContext) {
if (!adUnitContext || !adUnitContext.refererInfo) return null;

Expand Down Expand Up @@ -448,7 +494,7 @@ function generateAdFromBid(bid, bidResponse, serverRequest) {
mediaType: bid.ext.adot.media_type,
};

if (isBidANative(bid)) return {...base, native: formatNativeData(bid.adm)};
if (isBidANative(bid)) return {...base, native: formatNativeData(bid)};

const size = getSizeFromBid(bid, impressionData);
const creative = getCreativeFromBid(bid, impressionData);
Expand All @@ -465,7 +511,7 @@ function generateAdFromBid(bid, bidResponse, serverRequest) {
};
}

function formatNativeData(adm) {
function formatNativeData({adm, price}) {
const parsedAdm = tryParse(adm);
const {assets, link: {url, clicktrackers}, imptrackers, jstracker} = parsedAdm.native;
const placements = NATIVE_PLACEMENTS;
Expand All @@ -480,7 +526,7 @@ function formatNativeData(adm) {
}, {
clickUrl: url,
clickTrackers: clicktrackers,
impressionTrackers: imptrackers,
impressionTrackers: imptrackers && imptrackers.map(impTracker => replaceAuctionPrice(impTracker, price)),
javascriptTrackers: jstracker && [jstracker]
});
}
Expand All @@ -503,10 +549,11 @@ function getSizeFromBid(bid, impressionData) {

function getCreativeFromBid(bid, impressionData) {
const shouldUseAdMarkup = !!bid.adm;
const price = bid.price;

return {
markup: shouldUseAdMarkup ? bid.adm : null,
markupUrl: !shouldUseAdMarkup ? bid.nurl : null,
markup: shouldUseAdMarkup ? replaceAuctionPrice(bid.adm, price) : null,
markupUrl: !shouldUseAdMarkup ? replaceAuctionPrice(bid.nurl, price) : null,
renderer: getRendererFromBid(bid, impressionData)
};
}
Expand Down
64 changes: 31 additions & 33 deletions modules/adotBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,39 +114,37 @@ const adUnit = {
code: 'test-div',
mediaTypes: {
native: {
native: {
image: {
// Field required status
required: false,
// Image dimensions supported by the native ad unit.
// Each ad unit size is formatted as follows: [width, height].
sizes: [100, 50]
},
title: {
// Field required status
required: false,
// Maximum length of the title
len: 140
},
sponsoredBy: {
// Field required status
required: false
},
clickUrl: {
// Field required status
required: false
},
body: {
// Field required status
required: false
},
icon: {
// Field required status
required: false,
// Icon dimensions supported by the native ad unit.
// Each ad unit size is formatted as follows: [width, height].
sizes: [50, 50]
}
image: {
// Field required status
required: false,
// Image dimensions supported by the native ad unit.
// Each ad unit size is formatted as follows: [width, height].
sizes: [100, 50]
},
title: {
// Field required status
required: false,
// Maximum length of the title
len: 140
},
sponsoredBy: {
// Field required status
required: false
},
clickUrl: {
// Field required status
required: false
},
body: {
// Field required status
required: false
},
icon: {
// Field required status
required: false,
// Icon dimensions supported by the native ad unit.
// Each ad unit size is formatted as follows: [width, height].
sizes: [50, 50]
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,17 @@ export const spec = {
});
}

let eids = [];
const criteoId = utils.deepAccess(bidRequests[0], `userId.criteoId`);
if (criteoId) {
eids.push({
source: 'criteo.com',
id: criteoId
let tpuids = [];
tpuids.push({
'provider': 'criteo',
'user_id': criteoId
});
payload.tpuids = tpuids;
}

let eids = [];
const tdid = utils.deepAccess(bidRequests[0], `userId.tdid`);
if (tdid) {
eids.push({
Expand Down
5 changes: 3 additions & 2 deletions modules/britepoolIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export const britepoolIdSubmodule = {
/**
* Performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [submoduleConfigParams]
* @param {SubmoduleConfig} [submoduleConfig]
* @param {ConsentData|undefined} consentData
* @returns {function(callback:function)}
*/
getId(submoduleConfigParams, consentData) {
getId(submoduleConfig, consentData) {
const submoduleConfigParams = (submoduleConfig && submoduleConfig.params) || {};
const { params, headers, url, getter, errors } = britepoolIdSubmodule.createParams(submoduleConfigParams, consentData);
let getterResponse = null;
if (typeof getter === 'function') {
Expand Down
20 changes: 18 additions & 2 deletions modules/cointrafficBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js'
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js'
import { config } from '../src/config.js'

const BIDDER_CODE = 'cointraffic';
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';
const DEFAULT_CURRENCY = 'EUR';
const ALLOWED_CURRENCIES = [
'EUR', 'USD', 'JPY', 'BGN', 'CZK', 'DKK', 'GBP', 'HUF', 'PLN', 'RON', 'SEK', 'CHF', 'ISK', 'NOK', 'HRK', 'RUB', 'TRY',
'AUD', 'BRL', 'CAD', 'CNY', 'HKD', 'IDR', 'ILS', 'INR', 'KRW', 'MXN', 'MYR', 'NZD', 'PHP', 'SGD', 'THB', 'ZAR',
];

export const spec = {
code: BIDDER_CODE,
Expand All @@ -29,9 +35,19 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes);
const currency =
config.getConfig(`currency.bidderCurrencyDefault.${BIDDER_CODE}`) ||
config.getConfig('currency.adServerCurrency') ||
DEFAULT_CURRENCY;

if (ALLOWED_CURRENCIES.indexOf(currency) === -1) {
utils.logError('Currency is not supported - ' + currency);
return;
}

const payload = {
placementId: bidRequest.params.placementId,
currency: currency,
sizes: sizes,
bidId: bidRequest.bidId,
referer: bidderRequest.refererInfo.referer,
Expand Down
5 changes: 4 additions & 1 deletion modules/cointrafficBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Maintainer: tech@cointraffic.io
```

# Description
The Cointraffic client module makes it easy to implement Cointraffic directly into your website. To get started, simply replace the ``placementId`` with your assigned tracker key. This is dependent on the size required by your account dashboard. For additional information on this module, please contact us at ``support@cointraffic.io``.
The Cointraffic client module makes it easy to implement Cointraffic directly into your website. To get started, simply replace the ``placementId`` with your assigned tracker key. This is dependent on the size required by your account dashboard.
We support response in different currencies. Supported currencies listed [here](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html).

For additional information on this module, please contact us at ``support@cointraffic.io``.

# Test Parameters
```
Expand Down
4 changes: 2 additions & 2 deletions modules/criteoIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export const criteoIdSubmodule = {
/**
* get the Criteo Id from local storages and initiate a new user sync
* @function
* @param {SubmoduleParams} [configParams]
* @param {SubmoduleConfig} [config]
* @param {ConsentData} [consentData]
* @returns {{id: {criteoId: string} | undefined}}}
*/
getId(configParams, consentData) {
getId(config, consentData) {
const hasGdprData = consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies;
const gdprConsentString = hasGdprData ? consentData.consentString : undefined;

Expand Down
4 changes: 2 additions & 2 deletions modules/haloIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const haloIdSubmodule = {
/**
* performs action to obtain id and return a value in the callback's response argument
* @function
* @param {SubmoduleParams} [configParams]
* @param {SubmoduleConfig} [config]
* @returns {IdResponse|undefined}
*/
getId(configParams) {
getId(config) {
const url = `https://id.halo.ad.gt/api/v1/pbhid`;

const resp = function (callback) {
Expand Down
Loading

0 comments on commit 12f5974

Please sign in to comment.