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
alpadotsh committed Aug 30, 2019
2 parents 9fae56a + a7ad5ef commit fd27d40
Show file tree
Hide file tree
Showing 17 changed files with 834 additions and 96 deletions.
11 changes: 7 additions & 4 deletions modules/adpod.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

import * as utils from '../src/utils';
import { addBidToAuction, doCallbacksIfTimedout, AUCTION_IN_PROGRESS, callPrebidCache } from '../src/auction';
import { addBidToAuction, doCallbacksIfTimedout, AUCTION_IN_PROGRESS, callPrebidCache, getPriceByGranularity, getPriceGranularity } from '../src/auction';
import { checkAdUnitSetup } from '../src/prebid';
import { checkVideoBidSetup } from '../src/video';
import { setupBeforeHookFnOnce, module } from '../src/hook';
Expand All @@ -23,6 +23,7 @@ import { ADPOD } from '../src/mediaTypes';
import Set from 'core-js/library/fn/set';
import find from 'core-js/library/fn/array/find';
import { auctionManager } from '../src/auctionManager';
import CONSTANTS from '../src/constants.json';

const from = require('core-js/library/fn/array/from');

Expand Down Expand Up @@ -119,7 +120,9 @@ function createDispatcher(timeoutDuration) {
function attachPriceIndustryDurationKeyToBid(bid, brandCategoryExclusion) {
let initialCacheKey = bidCacheRegistry.getInitialCacheKey(bid);
let duration = utils.deepAccess(bid, 'video.durationBucket');
let cpmFixed = bid.cpm.toFixed(2);
const granularity = getPriceGranularity(bid.mediaType);
let cpmFixed = getPriceByGranularity(granularity)(bid);

let pcd;

if (brandCategoryExclusion) {
Expand Down Expand Up @@ -424,10 +427,10 @@ export function callPrebidCacheAfterAuction(bids, callback) {
* @param {Object} bid
*/
export function sortByPricePerSecond(a, b) {
if (a.cpm / a.video.durationBucket < b.cpm / b.video.durationBucket) {
if (a.adserverTargeting[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] / a.video.durationBucket < b.adserverTargeting[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] / b.video.durationBucket) {
return 1;
}
if (a.cpm / a.video.durationBucket > b.cpm / b.video.durationBucket) {
if (a.adserverTargeting[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] / a.video.durationBucket > b.adserverTargeting[CONSTANTS.TARGETING_KEYS.PRICE_BUCKET] / b.video.durationBucket) {
return -1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const spec = {
accumulator[bid.bidId].TransactionID = bid.transactionId;
accumulator[bid.bidId].Width = size.width;
accumulator[bid.bidId].Height = size.height;
accumulator[bid.bidId].AvaiableSizes = sizesArray.join(',');
accumulator[bid.bidId].AvailableSizes = sizesArray.join(',');
return accumulator;
}, {}),
PageRefreshed: getPageRefreshed()
Expand Down
34 changes: 18 additions & 16 deletions modules/optimeraBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { registerBidder } from '../src/adapters/bidderFactory';
import { deepAccess } from '../src/utils';

const BIDDER_CODE = 'optimera';
const SCORES_BASE_URL = 'https://dyv1bugovvq1g.cloudfront.net/';
Expand All @@ -11,12 +12,11 @@ export const spec = {
* @param {bidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bidRequest) {
isBidRequestValid (bidRequest) {
if (typeof bidRequest.params !== 'undefined' && typeof bidRequest.params.clientID !== 'undefined') {
return true;
} else {
return false;
}
return false;
},
/**
* Make a server request from the list of BidRequests.
Expand All @@ -27,18 +27,19 @@ export const spec = {
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests) {
let optimeraHost = window.location.host;
let optimeraPathName = window.location.pathname;
buildRequests (validBidRequests) {
const optimeraHost = window.location.host;
const optimeraPathName = window.location.pathname;
if (typeof validBidRequests[0].params.clientID !== 'undefined') {
let clientID = validBidRequests[0].params.clientID;
let scoresURL = SCORES_BASE_URL + clientID + '/' + optimeraHost + optimeraPathName + '.js';
const { clientID } = validBidRequests[0].params;
const scoresURL = `${SCORES_BASE_URL + clientID}/${optimeraHost}${optimeraPathName}.js`;
return {
method: 'GET',
url: scoresURL,
payload: validBidRequests,
};
}
return {};
},
/**
* Unpack the response from the server into a list of bids.
Expand All @@ -49,24 +50,25 @@ export const spec = {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
let validBids = bidRequest.payload;
let bidResponses = [];
interpretResponse (serverResponse, bidRequest) {
const validBids = bidRequest.payload;
const bidResponses = [];
let dealId = '';
if (typeof serverResponse.body !== 'undefined') {
let scores = serverResponse.body;
for (let i = 0; i < validBids.length; i++) {
const scores = serverResponse.body;
for (let i = 0; i < validBids.length; i += 1) {
if (typeof validBids[i].params.clientID !== 'undefined') {
if (validBids[i].adUnitCode in scores) {
dealId = scores[validBids[i].adUnitCode];
const deviceDealId = deepAccess(scores, `device.${validBids[i].params.device}.${validBids[i].adUnitCode}`);
dealId = deviceDealId || scores[validBids[i].adUnitCode];
}
let bidResponse = {
const bidResponse = {
requestId: validBids[i].bidId,
ad: '<div></div>',
cpm: 0.01,
width: 0,
height: 0,
dealId: dealId,
dealId,
ttl: 300,
creativeId: '1',
netRevenue: '0',
Expand Down
6 changes: 4 additions & 2 deletions modules/optimeraBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Module that adds ad placement visibility scores for DFP.
{
bidder: 'optimera',
params: {
clientID: '9999'
clientID: '9999',
device: 'mo'
}
}]
},{
Expand All @@ -29,7 +30,8 @@ Module that adds ad placement visibility scores for DFP.
{
bidder: 'optimera',
params: {
clientID: '9999'
clientID: '9999',
device: 'mo'
}
}]
}];
Expand Down
8 changes: 8 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,14 @@ const OPEN_RTB_PROTOCOL = {
utils.deepSetValue(request, 'user.ext.digitrust', digiTrust);
}

// pass schain object if it is present
const schain = utils.deepAccess(bidRequests, '0.bids.0.schain');
if (schain) {
request.source.ext = {
schain: schain
};
}

if (!utils.isEmpty(aliases)) {
request.ext.prebid.aliases = aliases;
}
Expand Down
92 changes: 53 additions & 39 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,38 @@ function _blockedIabCategoriesValidation(payload, blockedIabCategories) {
}
}

function _handleDealCustomTargetings(payload, dctrArr, validBidRequests) {
var dctr = '';
var dctrLen;
// set dctr value in site.ext, if present in validBidRequests[0], else ignore
if (dctrArr.length > 0) {
if (validBidRequests[0].params.hasOwnProperty('dctr')) {
dctr = validBidRequests[0].params.dctr;
if (utils.isStr(dctr) && dctr.length > 0) {
var arr = dctr.split('|');
dctr = '';
arr.forEach(val => {
dctr += (val.length > 0) ? (val.trim() + '|') : '';
});
dctrLen = dctr.length;
if (dctr.substring(dctrLen, dctrLen - 1) === '|') {
dctr = dctr.substring(0, dctrLen - 1);
}
payload.site.ext = {
key_val: dctr.trim()
}
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
if (dctrArr.length > 1) {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value found in more than 1 adunits. Value from 1st adunit will be picked. Ignoring values from subsequent adunits');
}
} else {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}
}
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
Expand Down Expand Up @@ -779,11 +811,10 @@ export const spec = {
var conf = _initConf(refererInfo);
var payload = _createOrtbTemplate(conf);
var bidCurrency = '';
var dctr = '';
var dctrLen;
var dctrArr = [];
var bid;
var blockedIabCategories = [];

validBidRequests.forEach(originalBid => {
bid = utils.deepClone(originalBid);
bid.params.adSlot = bid.params.adSlot || '';
Expand Down Expand Up @@ -835,6 +866,21 @@ export const spec = {
payload.ext.wrapper.wp = 'pbjs';
payload.user.gender = (conf.gender ? conf.gender.trim() : UNDEFINED);
payload.user.geo = {};
payload.user.geo.lat = _parseSlotParam('lat', conf.lat);
payload.user.geo.lon = _parseSlotParam('lon', conf.lon);
payload.user.yob = _parseSlotParam('yob', conf.yob);
payload.device.geo = payload.user.geo;
payload.site.page = conf.kadpageurl.trim() || payload.site.page.trim();
payload.site.domain = _getDomainFromURL(payload.site.page);

// adding schain object
if (validBidRequests[0].schain) {
payload.source = {
ext: {
schain: validBidRequests[0].schain
}
};
}

// Attaching GDPR Consent Params
if (bidderRequest && bidderRequest.gdprConsent) {
Expand All @@ -849,43 +895,10 @@ export const spec = {
};
}

payload.user.geo.lat = _parseSlotParam('lat', conf.lat);
payload.user.geo.lon = _parseSlotParam('lon', conf.lon);
payload.user.yob = _parseSlotParam('yob', conf.yob);
payload.device.geo = payload.user.geo;
payload.site.page = conf.kadpageurl.trim() || payload.site.page.trim();
payload.site.domain = _getDomainFromURL(payload.site.page);

// set dctr value in site.ext, if present in validBidRequests[0], else ignore
if (dctrArr.length > 0) {
if (validBidRequests[0].params.hasOwnProperty('dctr')) {
dctr = validBidRequests[0].params.dctr;
if (utils.isStr(dctr) && dctr.length > 0) {
var arr = dctr.split('|');
dctr = '';
arr.forEach(val => {
dctr += (val.length > 0) ? (val.trim() + '|') : '';
});
dctrLen = dctr.length;
if (dctr.substring(dctrLen, dctrLen - 1) === '|') {
dctr = dctr.substring(0, dctrLen - 1);
}
payload.site.ext = {
key_val: dctr.trim()
}
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
if (dctrArr.length > 1) {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value found in more than 1 adunits. Value from 1st adunit will be picked. Ignoring values from subsequent adunits');
}
} else {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}
}

_handleDealCustomTargetings(payload, dctrArr, validBidRequests);
_handleEids(payload, validBidRequests);
_blockedIabCategoriesValidation(payload, blockedIabCategories);

return {
method: 'POST',
url: ENDPOINT,
Expand All @@ -902,6 +915,8 @@ export const spec = {
interpretResponse: (response, request) => {
const bidResponses = [];
var respCur = DEFAULT_CURRENCY;
let parsedRequest = JSON.parse(request.data);
let parsedReferrer = parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : '';
try {
if (response.body && response.body.seatbid && utils.isArray(response.body.seatbid)) {
// Supporting multiple bid responses for same adSize
Expand All @@ -910,7 +925,6 @@ export const spec = {
seatbidder.bid &&
utils.isArray(seatbidder.bid) &&
seatbidder.bid.forEach(bid => {
let parsedRequest = JSON.parse(request.data);
let newBid = {
requestId: bid.impid,
cpm: (parseFloat(bid.price) || 0).toFixed(2),
Expand All @@ -921,7 +935,7 @@ export const spec = {
currency: respCur,
netRevenue: NET_REVENUE,
ttl: 300,
referrer: parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : '',
referrer: parsedReferrer,
ad: bid.adm
};
if (parsedRequest.imp && parsedRequest.imp.length > 0) {
Expand Down
Loading

0 comments on commit fd27d40

Please sign in to comment.