Skip to content

Commit

Permalink
Merge pull request #8 from prebid/master
Browse files Browse the repository at this point in the history
Prebid 1.14 updates
  • Loading branch information
tpottersovrn authored Jun 8, 2018
2 parents cbcf727 + 0a50366 commit e1310df
Show file tree
Hide file tree
Showing 35 changed files with 11,689 additions and 3,500 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node_js:
env:
- BROWSERSTACK_USERNAME=info184
addons:
chrome: stable,
chrome: stable
browserstack:
username: info184
access_key:
Expand Down
10 changes: 5 additions & 5 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function newPluginsArray(browserstack) {
];
if (browserstack) {
plugins.push('karma-browserstack-launcher');
plugins.push('karma-firefox-launcher');
plugins.push('karma-opera-launcher');
plugins.push('karma-safari-launcher');
plugins.push('karma-script-launcher');
plugins.push('karma-ie-launcher');
}
plugins.push('karma-firefox-launcher');
plugins.push('karma-opera-launcher');
plugins.push('karma-safari-launcher');
plugins.push('karma-script-launcher');
plugins.push('karma-ie-launcher');
return plugins;
}

Expand Down
5 changes: 2 additions & 3 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ export const spec = {
bidRespones.push(bidObject);
}
}

return bidRespones;

function verifySize(adItem, validSizes) {
for (var j = 0, k = validSizes.length; j < k; j++) {
if (adItem.width === validSizes[j][0] &&
adItem.height === validSizes[j][1]) {
if (adItem.width == validSizes[j][0] &&
adItem.height == validSizes[j][1]) {
return true;
}
}
Expand Down
91 changes: 57 additions & 34 deletions modules/aolBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SYNC_TYPES = {
}
};

const pubapiTemplate = template`//${'host'}/pubapi/3.0/${'network'}/${'placement'}/${'pageid'}/${'sizeid'}/ADTECH;v=2;cmd=bid;cors=yes;alias=${'alias'};misc=${'misc'}${'bidfloor'}${'keyValues'}${'consentData'}`;
const pubapiTemplate = template`//${'host'}/pubapi/3.0/${'network'}/${'placement'}/${'pageid'}/${'sizeid'}/ADTECH;v=2;cmd=bid;cors=yes;alias=${'alias'};misc=${'misc'};${'dynamicParams'}`;
const nexageBaseApiTemplate = template`//${'host'}/bidRequest?`;
const nexageGetApiTemplate = template`dcn=${'dcn'}&pos=${'pos'}&cmd=bid${'dynamicParams'}`;
const MP_SERVER_MAP = {
Expand All @@ -47,6 +47,11 @@ $$PREBID_GLOBAL$$.aolGlobals = {
pixelsDropped: false
};

const NUMERIC_VALUES = {
TRUE: 1,
FALSE: 0
};

let showCpmAdjustmentWarning = (function() {
let showCpmWarning = true;

Expand Down Expand Up @@ -101,20 +106,6 @@ function parsePixelItems(pixels) {
return pixelsItems;
}

function formatMarketplaceBidFloor(bidFloor) {
return (typeof bidFloor !== 'undefined') ? `;bidfloor=${bidFloor.toString()}` : '';
}

function formatMarketplaceKeyValues(keyValues) {
let formattedKeyValues = '';

utils._each(keyValues, (value, key) => {
formattedKeyValues += `;kv${key}=${encodeURIComponent(value)}`;
});

return formattedKeyValues;
}

function _isMarketplaceBidder(bidder) {
return bidder === AOL_BIDDERS_CODES.AOL || bidder === AOL_BIDDERS_CODES.ONEDISPLAY;
}
Expand Down Expand Up @@ -268,10 +259,8 @@ export const spec = {
pageid: params.pageId || 0,
sizeid: params.sizeId || 0,
alias: params.alias || utils.getUniqueIdentifierStr(),
misc: new Date().getTime(), // cache busting,
bidfloor: formatMarketplaceBidFloor(params.bidFloor),
keyValues: formatMarketplaceKeyValues(params.keyValues),
consentData: this.formatMarketplaceConsentData(consentData)
misc: new Date().getTime(), // cache busting
dynamicParams: this.formatMarketplaceDynamicParams(params, consentData)
});
},
buildOneMobileGetUrl(bid, consentData) {
Expand All @@ -288,15 +277,29 @@ export const spec = {
host: bid.params.host || NEXAGE_SERVER
});
},
formatMarketplaceDynamicParams(params = {}, consentData) {
let queryParams = {};

if (params.bidFloor) {
queryParams.bidfloor = params.bidFloor;
}

Object.assign(queryParams, this.formatKeyValues(params.keyValues));
Object.assign(queryParams, this.formatConsentData(consentData));

let paramsFormatted = '';
utils._each(queryParams, (value, key) => {
paramsFormatted += `${key}=${encodeURIComponent(value)};`;
});

return paramsFormatted;
},
formatOneMobileDynamicParams(params = {}, consentData) {
if (this.isSecureProtocol()) {
params.secure = 1;
params.secure = NUMERIC_VALUES.TRUE;
}

if (this.isConsentRequired(consentData)) {
params.euconsent = consentData.consentString;
params.gdpr = 1;
}
Object.assign(params, this.formatConsentData(consentData));

let paramsFormatted = '';
utils._each(params, (value, key) => {
Expand All @@ -312,27 +315,47 @@ export const spec = {
};

if (this.isConsentRequired(consentData)) {
openRtbObject.user = {
ext: {
consent: consentData.consentString
}
};
openRtbObject.regs = {
ext: {
gdpr: 1
gdpr: NUMERIC_VALUES.TRUE
}
};

if (consentData.consentString) {
openRtbObject.user = {
ext: {
consent: consentData.consentString
}
};
}
}

return openRtbObject;
},
isConsentRequired(consentData) {
return !!(consentData && consentData.consentString && consentData.gdprApplies);
return !!(consentData && consentData.gdprApplies);
},
formatMarketplaceConsentData(consentData) {
let consentRequired = this.isConsentRequired(consentData);
formatKeyValues(keyValues) {
let keyValuesHash = {};

utils._each(keyValues, (value, key) => {
keyValuesHash[`kv${key}`] = value;
});

return keyValuesHash;
},
formatConsentData(consentData) {
let params = {};

if (this.isConsentRequired(consentData)) {
params.gdpr = NUMERIC_VALUES.TRUE;

if (consentData.consentString) {
params.euconsent = consentData.consentString;
}
}

return consentRequired ? `;euconsent=${consentData.consentString};gdpr=1` : '';
return params;
},

_parseBidResponse(response, bidRequest) {
Expand Down
23 changes: 23 additions & 0 deletions modules/brainyBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ export const spec = {
});

return bidResponses;
},

/**
* SyncURLがある場合にレスポンスを解析してURLを返す
* @param {object} syncOptions Syncの設定
* @param {object} serverResponses SSPからのレスポンス
* @return {object} 表示タイプとURLが入ったオブジェクト
*/
getUserSyncs: function(syncOptions, serverResponses) {
const syncs = [];
if (syncOptions.pixelEnabled) {
const brainyResponseObj = serverResponses[0].body;
if (!brainyResponseObj) {
return [];
}
if (brainyResponseObj.syncUrl && brainyResponseObj.syncUrl != 'null' && brainyResponseObj.syncUrl.length > 0) {
syncs.push({
type: 'image',
url: brainyResponseObj.syncUrl
});
}
}
return syncs;
}
};
registerBidder(spec);
8 changes: 7 additions & 1 deletion modules/madvertiseBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as utils from 'src/utils';
import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';

// use protocol relative urls for http or https
Expand Down Expand Up @@ -29,9 +30,10 @@ export const spec = {
},
/**
* @param {BidRequest[]} bidRequests
* @param bidderRequest
* @return ServerRequest[]
*/
buildRequests: function (bidRequests) {
buildRequests: function (bidRequests, bidderRequest) {
return bidRequests.map(bidRequest => {
bidRequest.startTime = new Date().getTime();

Expand All @@ -50,6 +52,10 @@ export const spec = {
src = src + '&u=' + navigator.userAgent;
}

if (bidderRequest && bidderRequest.gdprConsent) {
src = src + '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? '1' : '0') + '&consent[0][format]=' + config.getConfig('consentManagement.cmpApi') + '&consent[0][value]=' + bidderRequest.gdprConsent.consentString;
}

return {
method: 'GET',
url: MADVERTISE_ENDPOINT + src,
Expand Down
93 changes: 92 additions & 1 deletion modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { config } from 'src/config';

const BIDDER_CODE = 'medianet';
const BID_URL = '//prebid.media.net/rtb/prebid';
const SLOT_VISIBILITY = {
NOT_DETERMINED: 0,
ABOVE_THE_FOLD: 1,
BELOW_THE_FOLD: 2
};

$$PREBID_GLOBAL$$.medianetGlobals = {};

Expand Down Expand Up @@ -71,6 +76,31 @@ function getSize(size) {
}
}

function getWindowSize() {
return {
w: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || -1,
h: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || -1
}
}

function getCoordinates(id) {
const element = document.getElementById(id);
if (element && element.getBoundingClientRect) {
const rect = element.getBoundingClientRect();
let coordinates = {};
coordinates.top_left = {
y: rect.top,
x: rect.left
};
coordinates.bottom_right = {
y: rect.bottom,
x: rect.right
};
return coordinates
}
return null;
}

function extParams(params, gdpr) {
let ext = {
customer_id: params.cid,
Expand All @@ -80,6 +110,10 @@ function extParams(params, gdpr) {
if (ext.gdpr_applies) {
ext.gdpr_consent_string = gdpr.consentString || '';
}
let windowSize = spec.getWindowSize();
if (windowSize.w !== -1 && windowSize.h !== -1) {
ext.screen = windowSize;
}
return ext;
}

Expand All @@ -102,9 +136,64 @@ function slotParams(bidRequest) {
if (bidFloor) {
params.bidfloor = bidFloor;
}
const coordinates = getCoordinates(bidRequest.adUnitCode);
if (coordinates) {
let normCoordinates = normalizeCoordinates(coordinates);
params.ext.coordinates = normCoordinates;
params.ext.viewability = getSlotVisibility(coordinates.top_left, getMinSize(params.banner));
if (getSlotVisibility(normCoordinates.top_left, getMinSize(params.banner)) > 0.5) {
params.ext.visibility = SLOT_VISIBILITY.ABOVE_THE_FOLD;
} else {
params.ext.visibility = SLOT_VISIBILITY.BELOW_THE_FOLD;
}
} else {
params.ext.visibility = SLOT_VISIBILITY.NOT_DETERMINED;
}

return params;
}

function getMinSize(sizes) {
return sizes.reduce((min, size) => size.h * size.w < min.h * min.w ? size : min);
}

function getSlotVisibility(topLeft, size) {
let maxArea = size.w * size.h;
let windowSize = spec.getWindowSize();
let bottomRight = {
x: topLeft.x + size.w,
y: topLeft.y + size.h
};
if (maxArea === 0 || windowSize.w === -1 || windowSize.h === -1) {
return 0;
}

return getOverlapArea(topLeft, bottomRight, {x: 0, y: 0}, {x: windowSize.w, y: windowSize.h}) / maxArea;
}

// find the overlapping area between two rectangles
function getOverlapArea(topLeft1, bottomRight1, topLeft2, bottomRight2) {
// If no overlap, return 0
if ((topLeft1.x > bottomRight2.x || bottomRight1.x < topLeft2.x) || (topLeft1.y > bottomRight2.y || bottomRight1.y < topLeft2.y)) {
return 0;
}
// return overlapping area : [ min of rightmost/bottommost co-ordinates ] - [ max of leftmost/topmost co-ordinates ]
return ((Math.min(bottomRight1.x, bottomRight2.x) - Math.max(topLeft1.x, topLeft2.x)) * (Math.min(bottomRight1.y, bottomRight2.y) - Math.max(topLeft1.y, topLeft2.y)));
}

function normalizeCoordinates(coordinates) {
return {
top_left: {
x: coordinates.top_left.x + window.pageXOffset,
y: coordinates.top_left.y + window.pageYOffset,
},
bottom_right: {
x: coordinates.bottom_right.x + window.pageXOffset,
y: coordinates.bottom_right.y + window.pageYOffset,
}
}
}

function generatePayload(bidRequests, bidderRequests) {
return {
site: siteDetails(bidRequests[0].params.site),
Expand Down Expand Up @@ -204,6 +293,8 @@ export const spec = {
if (syncOptions.pixelEnabled) {
return filterUrlsByType(cookieSyncUrls, 'image');
}
}
},

getWindowSize,
};
registerBidder(spec);
Loading

0 comments on commit e1310df

Please sign in to comment.