Skip to content

Commit

Permalink
merge branch 'master' into branch 'gdpr' + resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker committed Apr 27, 2018
2 parents 4bc0f9b + ebf5e61 commit 4a6e273
Show file tree
Hide file tree
Showing 24 changed files with 1,210 additions and 141 deletions.
12 changes: 6 additions & 6 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ export const spec = {
return !!(bid.params.mid);
},
buildRequests: function (validBidRequests, bidderRequest) {
var i, l, j, k, bid, _key, _value, reqParams;
var i, l, j, k, bid, _key, _value, reqParams, netRevenue;
var request = [];
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ], [ 'pt', null ] ];
var netRevenue = 'gross';
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ] ];
var bids = JSON.parse(JSON.stringify(validBidRequests));
for (i = 0, l = bids.length; i < l; i++) {
bid = bids[i];
if (bid.params.priceType === 'net') {
bid.params.pt = netRevenue = 'net';
if ((bid.params.priceType === 'net') || (bid.params.pt === 'net')) {
netRevenue = 'net';
}
for (j = 0, k = globalParams.length; j < k; j++) {
_key = globalParams[j][0];
Expand All @@ -35,7 +34,8 @@ export const spec = {
}

request.unshift('//' + globalParams[0][1] + '/adx/?rp=4');

netRevenue = netRevenue || 'gross';
request.push('pt=' + netRevenue);
request.push('stid=' + validBidRequests[0].auctionId);

if (bidderRequest && bidderRequest.gdprConsent) {
Expand Down
2 changes: 1 addition & 1 deletion modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const isBidRequestValid = bid =>
typeof bid.params.placementId === 'string' &&
bid.params.placementId.length > 0 &&
Array.isArray(bid.sizes) && bid.sizes.length > 0 &&
(isFullWidth(bid.params.format) ? bid.sizes.map(flattenSize).every(size => size === '300x250') : true) &&
(isFullWidth(bid.params.format) ? bid.sizes.map(flattenSize).some(size => size === '300x250') : true) &&
(isValidNonSizedFormat(bid.params.format) || bid.sizes.map(flattenSize).some(isValidSize));

/**
Expand Down
71 changes: 25 additions & 46 deletions modules/colossussspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,39 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes';
import * as utils from 'src/utils';

const BIDDER_CODE = 'colossusssp';
const URL = '//colossusssp.com/?c=o&m=multi';
const URL_SYNC = '//colossusssp.com/?c=o&m=cookie';

let sizeObj = {
'468x60': 1,
'728x90': 2,
'300x600': 10,
'300x250': 15,
'300x100': 19,
'320x50': 43,
'300x50': 44,
'300x300': 48,
'300x1050': 54,
'970x90': 55,
'970x250': 57,
'1000x90': 58,
'320x80': 59,
'640x480': 65,
'320x480': 67,
'320x320': 72,
'320x160': 73,
'480x300': 83,
'970x310': 94,
'970x210': 96,
'480x320': 101,
'768x1024': 102,
'1000x300': 113,
'320x100': 117,
'800x250': 118,
'200x600': 119
};
function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency) {
return false;
}

utils._each(sizeObj, (item, key) => sizeObj[item] = key);
switch (bid.mediaType) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl);
case NATIVE:
return Boolean(bid.native);
default:
return false;
}
}

export const spec = {
code: BIDDER_CODE,

supportedMediaTypes: [BANNER, VIDEO, NATIVE],
/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: (bid) => {
return (!isNaN(bid.params.placement_id) &&
((bid.params.sizes !== undefined && bid.params.sizes.length > 0 && bid.params.sizes.some((sizeIndex) => sizeObj[sizeIndex] !== undefined)) ||
(bid.sizes !== undefined && bid.sizes.length > 0 && bid.sizes.map((size) => `${size[0]}x${size[1]}`).some((size) => sizeObj[size] !== undefined))));
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placement_id));
},

/**
Expand Down Expand Up @@ -78,10 +63,12 @@ export const spec = {
};
for (let i = 0; i < validBidRequests.length; i++) {
let bid = validBidRequests[i];
let placement = {};
placement['placementId'] = bid.params.placement_id;
placement['bidId'] = bid.bidId;
placement['sizes'] = bid.sizes;
let placement = {
placementId: bid.params.placement_id,
bidId: bid.bidId,
sizes: bid.sizes,
traffic: bid.params.traffic || BANNER
};
placements.push(placement);
}
return {
Expand All @@ -103,15 +90,7 @@ export const spec = {
serverResponse = serverResponse.body;
for (let i = 0; i < serverResponse.length; i++) {
let resItem = serverResponse[i];
if (resItem.width && !isNaN(resItem.width) &&
resItem.height && !isNaN(resItem.height) &&
resItem.requestId && typeof resItem.requestId === 'string' &&
resItem.cpm && !isNaN(resItem.cpm) &&
resItem.ad && typeof resItem.ad === 'string' &&
resItem.ttl && !isNaN(resItem.ttl) &&
resItem.creativeId && typeof resItem.creativeId === 'string' &&
resItem.netRevenue && typeof resItem.netRevenue === 'boolean' &&
resItem.currency && typeof resItem.currency === 'string') {
if (isBidResponseValid(resItem)) {
response.push(resItem);
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/colossussspBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Module that connects to Colossus SSP demand sources
bids: [{
bidder: 'colossusssp',
params: {
placement_id: 0
placement_id: 0,
traffic: 'banner'
}
}]
}
Expand Down
177 changes: 177 additions & 0 deletions modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { config } from 'src/config';
import { EVENTS } from 'src/constants.json';

const CONSUMABLE_BIDDER_CODE = 'consumable'

const SYNC_TYPES = {
IFRAME: {
TAG: 'iframe',
TYPE: 'iframe'
},
IMAGE: {
TAG: 'img',
TYPE: 'image'
}
};

const pubapiTemplate = ({host, network, placement, alias}) => `//${host}/pubapi/3.0/${network}/${placement}/0/0/ADTECH;v=2;cmd=bid;cors=yes;alias=${alias};misc=${new Date().getTime()}`
const CONSUMABLE_URL = 'adserver-us.adtech.advertising.com';
const CONSUMABLE_TTL = 60;
const CONSUMABLE_NETWORK = '10947.1';

$$PREBID_GLOBAL$$.consumableGlobals = {
pixelsDropped: false
};

function parsePixelItems(pixels) {
let itemsRegExp = /<(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi;
let tagNameRegExp = /\w*(?=\s)/;
let srcRegExp = /src=("|')(.*?)\1/;
let pixelsItems = [];

if (pixels) {
let matchedItems = pixels.match(itemsRegExp);
if (matchedItems) {
matchedItems.forEach(item => {
let tagName = item.match(tagNameRegExp)[0];
let url = item.match(srcRegExp)[2];

if (tagName && url) {
pixelsItems.push({
type: tagName === SYNC_TYPES.IMAGE.TAG ? SYNC_TYPES.IMAGE.TYPE : SYNC_TYPES.IFRAME.TYPE,
url: url
});
}
});
}
}

return pixelsItems;
}

function _buildConsumableUrl(bid) {
const params = bid.params;

return pubapiTemplate({
host: CONSUMABLE_URL,
network: params.network || CONSUMABLE_NETWORK,
placement: parseInt(params.placement, 10)
});
}

function formatBidRequest(bid) {
let bidRequest;

bidRequest = {
url: _buildConsumableUrl(bid),
method: 'GET'
};

bidRequest.bidderCode = bid.bidder;
bidRequest.bidId = bid.bidId;
bidRequest.userSyncOn = bid.params.userSyncOn;
bidRequest.unitId = bid.params.unitId;
bidRequest.unitName = bid.params.unitName;
bidRequest.zoneId = bid.params.zoneId;
bidRequest.network = bid.params.network || CONSUMABLE_NETWORK;

return bidRequest;
}

function _parseBidResponse (response, bidRequest) {
let bidData;
try {
bidData = response.seatbid[0].bid[0];
} catch (e) {
return;
}

let cpm;

if (bidData.ext && bidData.ext.encp) {
cpm = bidData.ext.encp;
} else {
cpm = bidData.price;

if (cpm === null || isNaN(cpm)) {
utils.logError('Invalid cpm in bid response', CONSUMABLE_BIDDER_CODE, bid);
return;
}
}
cpm = cpm * (parseFloat(bidRequest.zoneId) / parseFloat(bidRequest.network));

let oad = bidData.adm;
let cb = bidRequest.network === '9599.1' ? 7654321 : Math.round(new Date().getTime());
let ad = '<script type=\'text/javascript\'>document.write(\'<div id=\"' + bidRequest.unitName + '-' + bidRequest.unitId + '\">\');</script>' + oad;
ad += '<script type=\'text/javascript\'>document.write(\'</div>\');</script>';
ad += '<script type=\'text/javascript\'>document.write(\'<div class=\"' + bidRequest.unitName + '\"></div>\');</script>';
ad += '<script type=\'text/javascript\'>document.write(\'<scr\'+\'ipt type=\"text/javascript\" src=\"https://yummy.consumable.com/' + bidRequest.unitId + '/' + bidRequest.unitName + '/widget/unit.js?cb=' + cb + '\" charset=\"utf-8\" async></scr\'+\'ipt>\');</script>'
if (response.ext && response.ext.pixels) {
if (config.getConfig('consumable.userSyncOn') !== EVENTS.BID_RESPONSE) {
ad += _formatPixels(response.ext.pixels);
}
}

return {
bidderCode: bidRequest.bidderCode,
requestId: bidRequest.bidId,
ad: ad,
cpm: cpm,
width: bidData.w,
height: bidData.h,
creativeId: bidData.crid,
pubapiId: response.id,
currency: response.cur,
dealId: bidData.dealid,
netRevenue: true,
ttl: CONSUMABLE_TTL
};
}

function _formatPixels (pixels) {
let formattedPixels = pixels.replace(/<\/?script( type=('|")text\/javascript('|")|)?>/g, '');

return '<script>var w=window,prebid;' +
'for(var i=0;i<10;i++){w = w.parent;prebid=w.$$PREBID_GLOBAL$$;' +
'if(prebid && prebid.consumableGlobals && !prebid.consumableGlobals.pixelsDropped){' +
'try{prebid.consumableGlobals.pixelsDropped=true;' + formattedPixels + 'break;}' +
'catch(e){continue;}' +
'}}</script>';
}

export const spec = {
code: CONSUMABLE_BIDDER_CODE,
isBidRequestValid: function(bid) {
return bid.params && bid.params.placement
},
buildRequests: function (bids) {
return bids.map(formatBidRequest);
},
interpretResponse: function ({body}, bidRequest) {
if (!body) {
utils.logError('Empty bid response', bidRequest.bidderCode, body);
} else {
let bid = _parseBidResponse(body, bidRequest);
if (bid) {
return bid;
}
}
},
getUserSyncs: function(options, bidResponses) {
let bidResponse = bidResponses[0];

if (config.getConfig('consumable.userSyncOn') === EVENTS.BID_RESPONSE) {
if (!$$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped && bidResponse.ext && bidResponse.ext.pixels) {
$$PREBID_GLOBAL$$.consumableGlobals.pixelsDropped = true;

return parsePixelItems(bidResponse.ext.pixels);
}
}

return [];
}
};

registerBidder(spec);
32 changes: 32 additions & 0 deletions modules/consumableBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Overview

Module Name: Consumable Bid Adapter

Module Type: Consumable Adapter

Maintainer: [email protected]

# Description

Module that connects to Consumable's demand sources

# Test Parameters
```javascript
var adUnits = [
{
code: 'test-ad-div',
sizes: [[300, 250]],
bids: [
{
bidder: 'consumable',
params: {
placement: '1234567',
unitId: '1234',
unitName: 'cnsmbl-300x250',
zoneId: '13136.52'
}
}
]
}
];
```
Loading

0 comments on commit 4a6e273

Please sign in to comment.