diff --git a/modules/aardvarkBidAdapter.js b/modules/aardvarkBidAdapter.js deleted file mode 100644 index f52265e4d1d..00000000000 --- a/modules/aardvarkBidAdapter.js +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Adapter for requesting bids from RTK Aardvark - * To request an RTK Aardvark Header bidding account - * or for additional integration support please contact sales@rtk.io - */ - -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); -var Adapter = require('src/adapter.js').default; -var constants = require('src/constants.json'); -var adaptermanager = require('src/adaptermanager'); - -const AARDVARK_CALLBACK_NAME = 'aardvarkResponse'; -const AARDVARK_REQUESTS_MAP = 'aardvarkRequests'; -const AARDVARK_BIDDER_CODE = 'aardvark'; -const DEFAULT_REFERRER = 'thor.rtk.io'; -const DEFAULT_ENDPOINT = 'thor.rtk.io'; - -var endpoint = DEFAULT_ENDPOINT; - -function requestBids(bidderCode, callbackName, bidReqs) { - var ref = utils.getTopWindowLocation(); - var ai = ''; - const scs = []; - const bidIds = []; - - ref = ref ? ref.host : DEFAULT_REFERRER; - - for (var i = 0, l = bidReqs.length, bid, _ai, _sc, _endpoint; i < l; i += 1) { - bid = bidReqs[i]; - _ai = utils.getBidIdParameter('ai', bid.params); - _sc = utils.getBidIdParameter('sc', bid.params); - if (!_ai || !_ai.length || !_sc || !_sc.length) { continue; } - - _endpoint = utils.getBidIdParameter('host', bid.params); - if (_endpoint) { endpoint = _endpoint; } - - if (!ai.length) { ai = _ai; } - if (_sc) { scs.push(_sc); } - - bidIds.push(_sc + '=' + bid.bidId); - - // Create the bidIdsMap for easier mapping back later - $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][bid.bidId] = bid; - } - - if (!ai.length || !scs.length) { return utils.logWarn('Bad bid request params given for adapter $' + bidderCode + ' (' + AARDVARK_BIDDER_CODE + ')'); } - - adloader.loadScript([ - '//' + endpoint + '/', ai, '/', scs.join('_'), - '/aardvark/?jsonp=$$PREBID_GLOBAL$$.', callbackName, - '&rtkreferer=', ref, '&', bidIds.join('&') - ].join('')); -} - -function registerBidResponse(bidderCode, rawBidResponse) { - if (rawBidResponse.error) { return utils.logWarn('Aardvark bid received with an error, ignoring... [' + rawBidResponse.error + ']'); } - - if (!rawBidResponse.cid) { return utils.logWarn('Aardvark bid received without a callback id, ignoring...'); } - - var bidObj = $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][rawBidResponse.cid]; - if (!bidObj) { return utils.logWarn('Aardvark request not found: ' + rawBidResponse.cid); } - - if (bidObj.params.sc !== rawBidResponse.id) { return utils.logWarn('Aardvark bid received with a non matching shortcode ' + rawBidResponse.id + ' instead of ' + bidObj.params.sc); } - - var bidResponse = bidfactory.createBid(constants.STATUS.GOOD, bidObj); - bidResponse.bidderCode = bidObj.bidder; - bidResponse.cpm = rawBidResponse.cpm; - bidResponse.ad = rawBidResponse.adm + utils.createTrackPixelHtml(decodeURIComponent(rawBidResponse.nurl)); - bidResponse.width = bidObj.sizes[0][0]; - bidResponse.height = bidObj.sizes[0][1]; - - bidmanager.addBidResponse(bidObj.placementCode, bidResponse); - $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][rawBidResponse.cid].responded = true; -} - -function registerAardvarkCallback(bidderCode, callbackName) { - $$PREBID_GLOBAL$$[callbackName] = function(rtkResponseObj) { - rtkResponseObj.forEach(function(bidResponse) { - registerBidResponse(bidderCode, bidResponse); - }); - - for (var bidRequestId in $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode]) { - if ($$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode].hasOwnProperty(bidRequestId)) { - var bidRequest = $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][bidRequestId]; - if (!bidRequest.responded) { - var bidResponse = bidfactory.createBid(constants.STATUS.NO_BID, bidRequest); - bidResponse.bidderCode = bidRequest.bidder; - bidmanager.addBidResponse(bidRequest.placementCode, bidResponse); - } - } - } - }; -} - -const AardvarkAdapter = function() { - var baseAdapter = new Adapter(AARDVARK_BIDDER_CODE); - - $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP] = $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP] || {}; - - baseAdapter.callBids = function (params) { - const bidderCode = baseAdapter.getBidderCode(); - var callbackName = AARDVARK_CALLBACK_NAME; - - if (bidderCode !== AARDVARK_BIDDER_CODE) { callbackName = [AARDVARK_CALLBACK_NAME, bidderCode].join('_'); } - - $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode] = {}; - - registerAardvarkCallback(bidderCode, callbackName); - - return requestBids(bidderCode, callbackName, params.bids || []); - }; - - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode - }); -}; - -adaptermanager.registerBidAdapter(new AardvarkAdapter(), 'aardvark'); - -module.exports = AardvarkAdapter; diff --git a/modules/adbladeBidAdapter.js b/modules/adbladeBidAdapter.js deleted file mode 100644 index 50f50f515d9..00000000000 --- a/modules/adbladeBidAdapter.js +++ /dev/null @@ -1,135 +0,0 @@ -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); - -/** - * Adapter for requesting bids from Adblade - * To request an Adblade Header partner account - * or for additional integration support please - * register at http://www.adblade.com. - */ -var AdbladeAdapter = function AdbladeAdapter() { - 'use strict'; - - const BIDDER_CODE = 'adblade'; - const BASE_URI = '//rtb.adblade.com/prebidjs/bid?'; - const DEFAULT_BID_FLOOR = 0.0000000001; - - function _callBids(params) { - var bids = params.bids || []; - var referrer = utils.getTopWindowUrl(); - var loc = utils.getTopWindowLocation(); - var domain = loc.hostname; - var partnerId = 0; - var bidRequests = {}; - - if (bids.length > 0) { - partnerId = '' + bids[0].params.partnerId; - } - - utils._each(bids, function(bid) { - // make sure the "sizes" are an array of arrays - if (!(bid.sizes[0] instanceof Array)) { - bid.sizes = [bid.sizes]; - } - utils._each(bid.sizes, function(size) { - let key = size[0] + 'x' + size[1]; - - bidRequests[key] = bidRequests[key] || { - 'site': { - 'id': partnerId, - 'page': referrer, - 'domain': domain, - 'publisher': { - 'id': partnerId, - 'name': referrer, - 'domain': domain - } - }, - 'id': params.requestId, - 'imp': [], - 'device': { - 'ua': window.navigator.userAgent, - }, - 'cur': ['USD'], - 'user': {} - }; - - bidRequests[key].imp.push({ - 'id': bid.bidId, - 'bidfloor': bid.params.bidFloor || DEFAULT_BID_FLOOR, - 'tag': bid.placementCode, - 'banner': { - 'w': size[0], - 'h': size[1], - }, - 'secure': 0 + (loc.protocol === 'https') - }); - }); - }); - - utils._each(bidRequests, function (bidRequest) { - adloader.loadScript( - utils.tryAppendQueryString( - utils.tryAppendQueryString( - BASE_URI, - 'callback', - '$$PREBID_GLOBAL$$.adbladeResponse' - ), - 'json', - JSON.stringify( - bidRequest - ) - ) - ); - }); - } - - $$PREBID_GLOBAL$$.adbladeResponse = function (response) { - var auctionIdRe = /\$(%7B|\{)AUCTION_ID(%7D|\})/gi; - var auctionPriceRe = /\$(%7B|\{)AUCTION_PRICE(%7D|\})/gi; - var clickUrlRe = /\$(%7B|\{)CLICK_URL(%7D|\})/gi; - - if (typeof (response) === 'undefined' || !response.hasOwnProperty('seatbid') || utils.isEmpty(response.seatbid)) { - // handle empty bids - var bidsRequested = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === BIDDER_CODE).bids; - if (bidsRequested.length > 0) { - let bid = bidfactory.createBid(2); - bid.bidderCode = BIDDER_CODE; - bidmanager.addBidResponse(bidsRequested[0].placementCode, bid); - } - - return; - } - - utils._each(response.seatbid, function(seatbid) { - utils._each(seatbid.bid, function(seatbidBid) { - var bidRequest = utils.getBidRequest(seatbidBid.impid); - var ad = seatbidBid.adm + utils.createTrackPixelHtml(seatbidBid.nurl); - - ad = ad.replace(auctionIdRe, seatbidBid.impid); - ad = ad.replace(clickUrlRe, ''); - ad = ad.replace(auctionPriceRe, seatbidBid.price); - - let bid = bidfactory.createBid(1); - - bid.bidderCode = BIDDER_CODE; - bid.cpm = seatbidBid.price; - bid.ad = ad; - bid.width = seatbidBid.w; - bid.height = seatbidBid.h; - bidmanager.addBidResponse(bidRequest.placementCode, bid); - }); - }); - }; - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new AdbladeAdapter(), 'adblade'); - -module.exports = AdbladeAdapter; diff --git a/modules/adbundBidAdapter.js b/modules/adbundBidAdapter.js deleted file mode 100644 index a40fc2b8057..00000000000 --- a/modules/adbundBidAdapter.js +++ /dev/null @@ -1,69 +0,0 @@ -var CONSTANTS = require('src/constants.json'); -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); - -function AdBundAdapter() { - var timezone = (new Date()).getTimezoneOffset(); - var bidAPIs = [ - 'http://us-east-engine.adbund.xyz/prebid/ad/get', - 'http://us-west-engine.adbund.xyz/prebid/ad/get' - ]; - // Based on the time zone to select the interface to the server - var bidAPI = bidAPIs[timezone < 0 ? 0 : 1]; - - function _stringify(param) { - var result = []; - var key; - for (key in param) { - if (param.hasOwnProperty(key)) { - result.push(key + '=' + encodeURIComponent(param[key])); - } - } - return result.join('&'); - } - - function _createCallback(bid) { - return function (data) { - var response; - if (data && data.cpm) { - response = bidfactory.createBid(CONSTANTS.STATUS.GOOD); - response.bidderCode = 'adbund'; - Object.assign(response, data); - } else { - response = bidfactory.createBid(CONSTANTS.STATUS.NO_BID); - response.bidderCode = 'adbund'; - } - bidmanager.addBidResponse(bid.placementCode, response); - }; - } - - function _requestBids(bid) { - var info = { - referrer: utils.getTopWindowUrl(), - domain: utils.getTopWindowLocation().hostname, - ua: window.navigator.userAgent - }; - var param = Object.assign({}, bid.params, info); - param.sizes = JSON.stringify(param.sizes || bid.sizes); - param.callback = '$$PREBID_GLOBAL$$.adbundResponse'; - $$PREBID_GLOBAL$$.adbundResponse = _createCallback(bid); - adloader.loadScript(bidAPI + '?' + _stringify(param)); - } - - function _callBids(params) { - (params.bids || []).forEach(function (bid) { - _requestBids(bid); - }); - } - - return { - callBids: _callBids - }; -} - -adaptermanager.registerBidAdapter(new AdBundAdapter(), 'adbund'); - -module.exports = AdBundAdapter; diff --git a/modules/adbutlerBidAdapter.js b/modules/adbutlerBidAdapter.js deleted file mode 100644 index d6492a72e1c..00000000000 --- a/modules/adbutlerBidAdapter.js +++ /dev/null @@ -1,146 +0,0 @@ -/** - * @overview AdButler Prebid.js adapter. - * @author dkharton - */ - -'use strict'; - -var utils = require('src/utils.js'); -var adloader = require('src/adloader.js'); -var bidmanager = require('src/bidmanager.js'); -var bidfactory = require('src/bidfactory.js'); -var adaptermanager = require('src/adaptermanager'); - -var AdButlerAdapter = function AdButlerAdapter() { - function _callBids(params) { - var bids = params.bids || []; - var callbackData = {}; - var zoneCount = {}; - var pageID = Math.floor(Math.random() * 10e6); - - // Build and send bid requests - for (var i = 0; i < bids.length; i++) { - var bid = bids[i]; - var zoneID = utils.getBidIdParameter('zoneID', bid.params); - var callbackID; - - if (!(zoneID in zoneCount)) { - zoneCount[zoneID] = 0; - } - - // build callbackID to get placementCode later - callbackID = zoneID + '_' + zoneCount[zoneID]; - - callbackData[callbackID] = {}; - callbackData[callbackID].bidId = bid.bidId; - - var adRequest = buildRequest(bid, zoneCount[zoneID], pageID); - zoneCount[zoneID]++; - - adloader.loadScript(adRequest); - } - - // Define callback function for bid responses - $$PREBID_GLOBAL$$.adbutlerCB = function(aBResponseObject) { - var bidResponse = {}; - var callbackID = aBResponseObject.zone_id + '_' + aBResponseObject.place; - var width = parseInt(aBResponseObject.width); - var height = parseInt(aBResponseObject.height); - var isCorrectSize = false; - var isCorrectCPM = true; - var CPM; - var minCPM; - var maxCPM; - var bidObj = callbackData[callbackID] ? utils.getBidRequest(callbackData[callbackID].bidId) : null; - - if (bidObj) { - if (aBResponseObject.status === 'SUCCESS') { - CPM = aBResponseObject.cpm; - minCPM = utils.getBidIdParameter('minCPM', bidObj.params); - maxCPM = utils.getBidIdParameter('maxCPM', bidObj.params); - - // Ensure response CPM is within the given bounds - if (minCPM !== '' && CPM < parseFloat(minCPM)) { - isCorrectCPM = false; - } - if (maxCPM !== '' && CPM > parseFloat(maxCPM)) { - isCorrectCPM = false; - } - - // Ensure that response ad matches one of the placement sizes. - utils._each(bidObj.sizes, function(size) { - if (width === size[0] && height === size[1]) { - isCorrectSize = true; - } - }); - - if (isCorrectCPM && isCorrectSize) { - bidResponse = bidfactory.createBid(1, bidObj); - bidResponse.bidderCode = 'adbutler'; - bidResponse.cpm = CPM; - bidResponse.width = width; - bidResponse.height = height; - bidResponse.ad = aBResponseObject.ad_code; - bidResponse.ad += addTrackingPixels(aBResponseObject.tracking_pixels); - } else { - bidResponse = bidfactory.createBid(2, bidObj); - bidResponse.bidderCode = 'adbutler'; - } - } else { - bidResponse = bidfactory.createBid(2, bidObj); - bidResponse.bidderCode = 'adbutler'; - } - - bidmanager.addBidResponse(bidObj.placementCode, bidResponse); - } - }; - } - - function buildRequest(bid, adIndex, pageID) { - var accountID = utils.getBidIdParameter('accountID', bid.params); - var zoneID = utils.getBidIdParameter('zoneID', bid.params); - var keyword = utils.getBidIdParameter('keyword', bid.params); - var domain = utils.getBidIdParameter('domain', bid.params); - - if (typeof domain === 'undefined' || domain.length === 0) { - domain = 'servedbyadbutler.com'; - } - - var requestURI = location.protocol + '//' + domain + '/adserve/;type=hbr;'; - requestURI += 'ID=' + encodeURIComponent(accountID) + ';'; - requestURI += 'setID=' + encodeURIComponent(zoneID) + ';'; - requestURI += 'pid=' + encodeURIComponent(pageID) + ';'; - requestURI += 'place=' + encodeURIComponent(adIndex) + ';'; - - // append the keyword for targeting if one was passed in - if (keyword !== '') { - requestURI += 'kw=' + encodeURIComponent(keyword) + ';'; - } - requestURI += 'jsonpfunc=$$PREBID_GLOBAL$$.adbutlerCB;'; - requestURI += 'click=CLICK_MACRO_PLACEHOLDER'; - - return requestURI; - } - - function addTrackingPixels(trackingPixels) { - var trackingPixelMarkup = ''; - utils._each(trackingPixels, function(pixelURL) { - var trackingPixel = ''; - - trackingPixelMarkup += trackingPixel; - }); - return trackingPixelMarkup; - } - - // Export the callBids function, so that prebid.js can execute this function - // when the page asks to send out bid requests. - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new AdButlerAdapter(), 'adbutler'); - -module.exports = AdButlerAdapter; diff --git a/modules/adequantBidAdapter.js b/modules/adequantBidAdapter.js deleted file mode 100644 index a12369d0a59..00000000000 --- a/modules/adequantBidAdapter.js +++ /dev/null @@ -1,80 +0,0 @@ -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); -var utils = require('src/utils.js'); -var CONSTANTS = require('src/constants.json'); -var adaptermanager = require('src/adaptermanager'); - -function AdequantAdapter() { - var req_url_base = 'https://rex.adequant.com/rex/c2s_prebid?'; - - function _callBids(params) { - var req_url = []; - var publisher_id = null; - var sizes = []; - var cats = null; - var replies = []; - var placements = {}; - - var bids = params.bids || []; - for (var i = 0; i < bids.length; i++) { - var bid_request = bids[i]; - var br_params = bid_request.params || {}; - placements[bid_request.placementCode] = true; - - publisher_id = br_params.publisher_id.toString() || publisher_id; - var bidfloor = br_params.bidfloor || 0.01; - cats = br_params.cats || cats; - if (typeof (cats) === 'string') { cats = cats.split(' '); } - var br_sizes = utils.parseSizesInput(bid_request.sizes); - for (var j = 0; j < br_sizes.length; j++) { - sizes.push(br_sizes[j] + '_' + bidfloor); - replies.push(bid_request.placementCode); - } - } - // send out 1 bid request for all bids - if (publisher_id) { req_url.push('a=' + publisher_id); } - if (cats) { req_url.push('c=' + cats.join('+')); } - if (sizes) { req_url.push('s=' + sizes.join('+')); } - - adloader.loadScript(req_url_base + req_url.join('&'), function() { process_bids(replies, placements); }); - } - - function process_bids(replies, placements) { - var placement_code; - var bid; - const adequant_creatives = window.adequant_creatives; - if (adequant_creatives && adequant_creatives.seatbid) { - for (var i = 0; i < adequant_creatives.seatbid.length; i++) { - var bid_response = adequant_creatives.seatbid[i].bid[0]; - placement_code = replies[parseInt(bid_response.impid, 10) - 1]; - if (!placement_code || !placements[placement_code]) { continue; } - - bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD); - bid.bidderCode = 'adequant'; - bid.cpm = bid_response.price; - bid.ad = bid_response.adm; - bid.width = bid_response.w; - bid.height = bid_response.h; - bidmanager.addBidResponse(placement_code, bid); - placements[placement_code] = false; - } - } - for (placement_code in placements) { - if (placements[placement_code]) { - bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID); - bid.bidderCode = 'adequant'; - bidmanager.addBidResponse(placement_code, bid); - utils.logMessage('No bid response from Adequant for placement code ' + placement_code); - } - } - } - - return { - callBids: _callBids - }; -} - -adaptermanager.registerBidAdapter(new AdequantAdapter(), 'adequant'); - -module.exports = AdequantAdapter; diff --git a/modules/adformBidAdapter.js b/modules/adformBidAdapter.js deleted file mode 100644 index 69908e70888..00000000000 --- a/modules/adformBidAdapter.js +++ /dev/null @@ -1,171 +0,0 @@ -var utils = require('src/utils'); -var adloader = require('src/adloader'); -var bidmanager = require('src/bidmanager'); -var bidfactory = require('src/bidfactory'); -var STATUSCODES = require('src/constants.json').STATUS; -var adaptermanager = require('src/adaptermanager'); -var Adapter = require('src/adapter').default; - -const ADFORM_BIDDER_CODE = 'adform'; - -function AdformAdapter() { - let baseAdapter = new Adapter(ADFORM_BIDDER_CODE); - - function _callBids(params) { - var bid, _value, _key, i, j, k, l, reqParams; - var bids = params.bids; - var request = []; - var callbackName = '_adf_' + utils.getUniqueIdentifierStr(); - var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], ['fd', 1], [ 'url', null ], [ 'tid', null ], [ 'callback', '$$PREBID_GLOBAL$$.' + callbackName ] ]; - - for (i = 0, l = bids.length; i < l; i++) { - bid = bids[i]; - - for (j = 0, k = globalParams.length; j < k; j++) { - _key = globalParams[j][0]; - _value = bid[_key] || bid.params[_key]; - if (_value) { - bid[_key] = bid.params[_key] = null; - globalParams[j][1] = _value; - } - } - - reqParams = bid.params; - reqParams.transactionId = bid.transactionId; - request.push(formRequestUrl(reqParams)); - } - - request.unshift('//' + globalParams[0][1] + '/adx/?rp=4'); - - for (i = 1, l = globalParams.length; i < l; i++) { - _key = globalParams[i][0]; - _value = globalParams[i][1]; - if (_value) { - request.push(globalParams[i][0] + '=' + encodeURIComponent(_value)); - } - } - - $$PREBID_GLOBAL$$[callbackName] = handleCallback(bids); - - adloader.loadScript(request.join('&')); - }; - - function formRequestUrl(reqData) { - var key; - var url = []; - - for (key in reqData) { - if (reqData.hasOwnProperty(key) && reqData[key]) { url.push(key, '=', reqData[key], '&'); } - } - - return encode64(url.join('').slice(0, -1)); - } - - function handleCallback(bids) { - return function handleResponse(adItems) { - var bidObject; - var bidder = baseAdapter.getBidderCode(); - var adItem; - var bid; - for (var i = 0, l = adItems.length; i < l; i++) { - adItem = adItems[i]; - bid = bids[i]; - if (adItem && adItem.response === 'banner' && - verifySize(adItem, bid.sizes)) { - bidObject = bidfactory.createBid(STATUSCODES.GOOD, bid); - bidObject.bidderCode = bidder; - bidObject.cpm = adItem.win_bid; - bidObject.cur = adItem.win_cur; - bidObject.ad = adItem.banner; - bidObject.width = adItem.width; - bidObject.height = adItem.height; - bidObject.dealId = adItem.deal_id; - bidObject.transactionId = bid.transactionId; - bidmanager.addBidResponse(bid.placementCode, bidObject); - } else { - bidObject = bidfactory.createBid(STATUSCODES.NO_BID, bid); - bidObject.bidderCode = bidder; - bidmanager.addBidResponse(bid.placementCode, bidObject); - } - } - }; - - 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]) { - return true; - } - } - - return false; - } - } - - function encode64(input) { - var out = []; - var chr1; - var chr2; - var chr3; - var enc1; - var enc2; - var enc3; - var enc4; - var i = 0; - var _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_='; - - input = utf8_encode(input); - - while (i < input.length) { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - - if (isNaN(chr2)) { - enc3 = enc4 = 64; - } else if (isNaN(chr3)) { - enc4 = 64; - } - - out.push(_keyStr.charAt(enc1), _keyStr.charAt(enc2)); - if (enc3 !== 64) { out.push(_keyStr.charAt(enc3)); } - if (enc4 !== 64) { out.push(_keyStr.charAt(enc4)); } - } - - return out.join(''); - } - - function utf8_encode(string) { - string = string.replace(/\r\n/g, '\n'); - var utftext = ''; - - for (var n = 0; n < string.length; n++) { - var c = string.charCodeAt(n); - - if (c < 128) { - utftext += String.fromCharCode(c); - } else if ((c > 127) && (c < 2048)) { - utftext += String.fromCharCode((c >> 6) | 192); - utftext += String.fromCharCode((c & 63) | 128); - } else { - utftext += String.fromCharCode((c >> 12) | 224); - utftext += String.fromCharCode(((c >> 6) & 63) | 128); - utftext += String.fromCharCode((c & 63) | 128); - } - } - - return utftext; - } - - return Object.assign(this, baseAdapter, { - callBids: _callBids - }); -} - -adaptermanager.registerBidAdapter(new AdformAdapter(), ADFORM_BIDDER_CODE); -module.exports = AdformAdapter; diff --git a/modules/adkernelBidAdapter.js b/modules/adkernelBidAdapter.js deleted file mode 100644 index 855014c2411..00000000000 --- a/modules/adkernelBidAdapter.js +++ /dev/null @@ -1,310 +0,0 @@ -import bidmanager from 'src/bidmanager'; -import bidfactory from 'src/bidfactory'; -import * as utils from 'src/utils'; -import {ajax} from 'src/ajax'; -import Adapter from 'src/adapter'; -import adaptermanager from 'src/adaptermanager'; - -/** - * Adapter for requesting bids from AdKernel white-label platform - * @class - */ -const AdKernelAdapter = function AdKernelAdapter() { - const AJAX_REQ_PARAMS = { - contentType: 'text/plain', - withCredentials: true, - method: 'GET' - }; - const EMPTY_BID_RESPONSE = {'seatbid': [{'bid': []}]}; - - const VIDEO_TARGETING = ['mimes', 'minduration', 'maxduration', 'protocols', 'startdelay', 'linearity', 'sequence', - 'boxingallowed', 'playbackmethod', 'delivery', 'pos', 'api', 'ext']; - - let baseAdapter = new Adapter('adkernel'); - - /** - * Helper object to build multiple bid requests in case of multiple zones/ad-networks - * @constructor - */ - function RtbRequestDispatcher() { - const _dispatch = {}; - const originalBids = {}; - const syncedHostZones = {}; - const site = createSite(); - - // translate adunit info into rtb impression dispatched by host/zone - this.addImp = function (bid) { - let host = bid.params.host; - let zone = bid.params.zoneId; - - if (!(host in _dispatch)) { - _dispatch[host] = {}; - } - /* istanbul ignore else */ - if (!(zone in _dispatch[host])) { - _dispatch[host][zone] = []; - } - let imp = buildImp(bid); - // save rtb impression for specified ad-network host and zone - _dispatch[host][zone].push(imp); - originalBids[bid.bidId] = bid; - // perform user-sync - if (!(host in syncedHostZones)) { - syncedHostZones[host] = []; - } - if (syncedHostZones[host].indexOf(zone) === -1) { - syncedHostZones[host].push(zone); - } - }; - - function buildImp(bid) { - const size = getBidSize(bid); - const imp = { - 'id': bid.bidId, - 'tagid': bid.placementCode - }; - - if (bid.mediaType === 'video') { - imp.video = {w: size[0], h: size[1]}; - if (bid.params.video) { - Object.keys(bid.params.video) - .filter(param => VIDEO_TARGETING.includes(param)) - .forEach(param => imp.video[param] = bid.params.video[param]); - } - } else { - imp.banner = {w: size[0], h: size[1]}; - } - if (utils.getTopWindowLocation().protocol === 'https:') { - imp.secure = 1; - } - return imp; - } - - function getBidSize(bid) { - if (bid.mediaType === 'video') { - return bid.sizes; - } - return bid.sizes[0]; - } - - /** - * Main function to get bid requests - */ - this.dispatch = function (callback) { - utils._each(_dispatch, (zones, host) => { - utils.logMessage(`processing network ${host}`); - utils._each(zones, (impressions, zone) => { - utils.logMessage(`processing zone ${zone}`); - dispatchRtbRequest(host, zone, impressions, callback); - }); - }); - }; - /** - * Build flat user-sync queue from host->zones mapping - */ - this.buildUserSyncQueue = function() { - return Object.keys(syncedHostZones) - .reduce((m, k) => { - syncedHostZones[k].forEach((v) => m.push([k, v])); - return m; - }, []); - }; - - function dispatchRtbRequest(host, zone, impressions, callback) { - let url = buildEndpointUrl(host); - let rtbRequest = buildRtbRequest(impressions); - let params = buildRequestParams(zone, rtbRequest); - ajax(url, (bidResp) => { - bidResp = bidResp === '' ? EMPTY_BID_RESPONSE : JSON.parse(bidResp); - utils._each(rtbRequest.imp, (imp) => { - let bidFound = false; - utils._each(bidResp.seatbid[0].bid, (bid) => { - /* istanbul ignore else */ - if (!bidFound && bid.impid === imp.id) { - bidFound = true; - callback(originalBids[imp.id], imp, bid); - } - }); - if (!bidFound) { - callback(originalBids[imp.id], imp); - } - }); - }, params, AJAX_REQ_PARAMS); - } - - /** - * Builds complete rtb bid request - * @param imps collection of impressions - */ - function buildRtbRequest(imps) { - return { - 'id': utils.getUniqueIdentifierStr(), - 'imp': imps, - 'site': site, - 'at': 1, - 'device': { - 'ip': 'caller', - 'ua': 'caller' - } - }; - } - - /** - * Build ad-network specific endpoint url - */ - function buildEndpointUrl(host) { - return `${window.location.protocol}//${host}/rtbg`; - } - - function buildRequestParams(zone, rtbReq) { - return { - 'zone': encodeURIComponent(zone), - 'ad_type': 'rtb', - 'r': encodeURIComponent(JSON.stringify(rtbReq)) - }; - } - } - - /** - * Main module export function implementation - */ - baseAdapter.callBids = function (params) { - var bids = params.bids || []; - processBids(bids); - }; - - /** - * Process all bids grouped by network/zone - */ - function processBids(bids) { - const dispatcher = new RtbRequestDispatcher(); - // process individual bids - utils._each(bids, (bid) => { - if (!validateBidParams(bid.params)) { - utils.logError(`Incorrect configuration for adkernel bidder: ${bid.params}`); - bidmanager.addBidResponse(bid.placementCode, createEmptyBidObject(bid)); - } else { - dispatcher.addImp(bid); - } - }); - // start async usersync - processUserSyncQueue(dispatcher.buildUserSyncQueue()); - - // process bids grouped into bid requests - dispatcher.dispatch((bid, imp, bidResp) => { - let adUnitId = bid.placementCode; - if (bidResp) { - utils.logMessage(`got response for ${adUnitId}`); - let dimensions = getCreativeSize(imp, bidResp); - bidmanager.addBidResponse(adUnitId, createBidObject(bidResp, bid, dimensions.w, dimensions.h)); - } else { - utils.logMessage(`got empty response for ${adUnitId}`); - bidmanager.addBidResponse(adUnitId, createEmptyBidObject(bid)); - } - }); - } - - /** - * Evaluate creative size from response or from request - */ - function getCreativeSize(imp, bid) { - let dimensions = (bid.h && bid.w) ? bid : (imp.banner || imp.video); - return { - w: dimensions.w, - h: dimensions.h - }; - } - - /** - * Create bid object for the bid manager - */ - function createBidObject(resp, bid, width, height) { - let bidObj = Object.assign(bidfactory.createBid(1, bid), { - bidderCode: bid.bidder, - width: width, - height: height, - cpm: parseFloat(resp.price) - }); - if (bid.mediaType === 'video') { - bidObj.vastUrl = resp.nurl; - bidObj.mediaType = 'video'; - } else { - bidObj.ad = formatAdMarkup(resp); - } - return bidObj; - } - - /** - * Create empty bid object for the bid manager - */ - function createEmptyBidObject(bid) { - return Object.assign(bidfactory.createBid(2, bid), { - bidderCode: bid.bidder - }); - } - - /** - * Format creative with optional nurl call - */ - function formatAdMarkup(bid) { - var adm = bid.adm; - if ('nurl' in bid) { - adm += utils.createTrackPixelHtml(`${bid.nurl}&px=1`); - } - return adm; - } - - function validateBidParams(params) { - return typeof params.host !== 'undefined' && typeof params.zoneId !== 'undefined'; - } - - /** - * Creates site description object - */ - function createSite() { - var location = utils.getTopWindowLocation(); - return { - 'domain': location.hostname, - 'page': location.href.split('?')[0] - }; - } - - /** - * Recursively process user-sync queue - */ - function processUserSyncQueue(queue) { - if (queue.length === 0) { - return; - } - let entry = queue.pop(); - insertUserSync(entry[0], entry[1], () => processUserSyncQueue(queue)); - } - - /** - * Insert single iframe user-sync - */ - function insertUserSync(host, zone, callback) { - var iframe = utils.createInvisibleIframe(); - iframe.src = `//sync.adkernel.com/user-sync?zone=${zone}&r=%2F%2F${host}%2Fuser-synced%3Fuid%3D%7BUID%7D`; - utils.addEventHandler(iframe, 'load', callback); - try { - document.body.appendChild(iframe); - } catch (error) { - /* istanbul ignore next */ - utils.logError(error); - } - } - - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - getBidderCode: baseAdapter.getBidderCode - }); -}; - -adaptermanager.registerBidAdapter(new AdKernelAdapter(), 'adkernel', { - supportedMediaTypes: ['video'] -}); -adaptermanager.aliasBidAdapter('adkernel', 'headbidding'); - -module.exports = AdKernelAdapter; diff --git a/modules/admediaBidAdapter.js b/modules/admediaBidAdapter.js deleted file mode 100644 index 4382870eef3..00000000000 --- a/modules/admediaBidAdapter.js +++ /dev/null @@ -1,107 +0,0 @@ -import { getBidRequest } from 'src/utils'; -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); -var utils = require('src/utils.js'); -var CONSTANTS = require('src/constants.json'); -var adaptermanager = require('src/adaptermanager'); - -/** - * Adapter for requesting bids from AdMedia. - * - */ -var AdmediaAdapter = function AdmediaAdapter() { - function _callBids(params) { - var bids; - const bidderUrl = (window.location.protocol) + '//b.admedia.com/banner/prebid/bidder/?'; - bids = params.bids || []; - for (var i = 0; i < bids.length; i++) { - var request_obj = {}; - var bid = bids[i]; - - if (bid.params.aid) { - request_obj.aid = bid.params.aid; - } else { - utils.logError('required param aid is missing', 'admedia'); - continue; - } - - // optional page_url macro - if (bid.params.page_url) { - request_obj.page_url = bid.params.page_url; - } - - // if set, return a test ad for all aids - if (bid.params.test_ad === 1) { - request_obj.test_ad = 1; - } - - var parsedSizes = utils.parseSizesInput(bid.sizes); - var parsedSizesLength = parsedSizes.length; - if (parsedSizesLength > 0) { - // first value should be "size" - request_obj.size = parsedSizes[0]; - if (parsedSizesLength > 1) { - // any subsequent values should be "promo_sizes" - var promo_sizes = []; - for (var j = 1; j < parsedSizesLength; j++) { - promo_sizes.push(parsedSizes[j]); - } - - request_obj.promo_sizes = promo_sizes.join(','); - } - } - - // detect urls - request_obj.siteDomain = window.location.host; - request_obj.sitePage = window.location.href; - request_obj.siteRef = document.referrer; - request_obj.topUrl = utils.getTopWindowUrl(); - - request_obj.callback = '$$PREBID_GLOBAL$$'; - request_obj.callbackId = bid.bidId; - - var endpoint = bidderUrl + utils.parseQueryStringParameters(request_obj); - - // utils.logMessage('Admedia request built: ' + endpoint); - - adloader.loadScript(endpoint); - } - } - - // expose the callback to global object - $$PREBID_GLOBAL$$.admediaHandler = function(response) { - var bidObject = {}; - var callback_id = response.callback_id; - var placementCode = ''; - var bidObj = getBidRequest(callback_id); - if (bidObj) { - placementCode = bidObj.placementCode; - } - - if (bidObj && response.cpm > 0 && !!response.ad) { - bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD); - bidObject.bidderCode = bidObj.bidder; - bidObject.cpm = parseFloat(response.cpm); - bidObject.ad = response.ad; - bidObject.width = response.width; - bidObject.height = response.height; - } else { - bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID); - bidObject.bidderCode = bidObj.bidder; - utils.logMessage('No prebid response from Admedia for placement code ' + placementCode); - } - - bidmanager.addBidResponse(placementCode, bidObject); - }; - - // Export the callBids function, so that prebid.js can execute this function - // when the page asks to send out bid requests. - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new AdmediaAdapter(), 'admedia'); - -module.exports = AdmediaAdapter; diff --git a/modules/admixerBidAdapter.js b/modules/admixerBidAdapter.js deleted file mode 100644 index 71220732540..00000000000 --- a/modules/admixerBidAdapter.js +++ /dev/null @@ -1,88 +0,0 @@ -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var Ajax = require('src/ajax'); -var utils = require('src/utils.js'); -var adaptermanager = require('src/adaptermanager'); - -/** - * Adapter for requesting bids from Admixer. - * - * @returns {{callBids: _callBids,responseCallback: _responseCallback}} - */ -var AdmixerAdapter = function AdmixerAdapter() { - var invUrl = '//inv-nets.admixer.net/prebid.aspx'; - var invVastUrl = '//inv-nets.admixer.net/videoprebid.aspx'; - - function _callBids(data) { - var bids = data.bids || []; - for (var i = 0, ln = bids.length; i < ln; i++) { - var bid = bids[i]; - var params = { - 'sizes': utils.parseSizesInput(bid.sizes).join('-'), - 'zone': bid.params && bid.params.zone, - 'callback_uid': bid.placementCode - }; - if (params.zone) { - if (bid.mediaType === 'video') { - var videoParams = {}; - if (typeof bid.video === 'object') { - Object.assign(videoParams, bid.video); - } - Object.assign(videoParams, params); - _requestBid(invVastUrl, params); - } else { - _requestBid(invUrl, params); - } - } else { - var bidObject = bidfactory.createBid(2); - bidObject.bidderCode = 'admixer'; - bidmanager.addBidResponse(params.callback_uid, bidObject); - } - } - } - - function _requestBid(url, params) { - Ajax.ajax(url, _responseCallback, params, {method: 'GET', withCredentials: true}); - } - - function _responseCallback(adUnit) { - try { - adUnit = JSON.parse(adUnit); - } catch (_error) { - adUnit = {result: {cpm: 0}}; - utils.logError(_error); - } - var adUnitCode = adUnit.callback_uid; - var bid = adUnit.result; - var bidObject; - if (bid.cpm > 0) { - bidObject = bidfactory.createBid(1); - bidObject.bidderCode = 'admixer'; - bidObject.cpm = bid.cpm; - if (bid.vastUrl) { - bidObject.mediaType = 'video'; - bidObject.vastUrl = bid.vastUrl; - bidObject.descriptionUrl = bid.vastUrl; - } else { - bidObject.ad = bid.ad; - } - bidObject.width = bid.width; - bidObject.height = bid.height; - } else { - bidObject = bidfactory.createBid(2); - bidObject.bidderCode = 'admixer'; - } - bidmanager.addBidResponse(adUnitCode, bidObject); - } - - return { - callBids: _callBids, - responseCallback: _responseCallback - }; -}; - -adaptermanager.registerBidAdapter(new AdmixerAdapter(), 'admixer', { - supportedMediaTypes: ['video'] -}); - -module.exports = AdmixerAdapter; diff --git a/modules/adsupplyBidAdapter.js b/modules/adsupplyBidAdapter.js deleted file mode 100644 index 041437cce98..00000000000 --- a/modules/adsupplyBidAdapter.js +++ /dev/null @@ -1,90 +0,0 @@ -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); -var utils = require('src/utils'); -var adaptermanager = require('src/adaptermanager'); - -const ADSUPPLY_CODE = 'adsupply'; - -var AdSupplyAdapter = function AdSupplyAdapter() { - function _validateParams(params) { - if (!params || !params.siteId || !params.zoneId || !params.endpointUrl || !params.clientId) { - return false; - } - - if (typeof params.zoneId !== 'number' || params.zoneId <= 0) { - return false; - } - - return true; - } - - function _getRequestUrl(bid) { - var referrerUrl = encodeURIComponent(window.document.referrer); - var rand = encodeURIComponent(Math.floor(Math.random() * 100000 + 1)); - var time = encodeURIComponent(new Date().getTimezoneOffset()); - return '//' + bid.params.endpointUrl + '/banner.engine?id=' + bid.params.siteId + '&z=' + bid.params.zoneId + '&rand=' + rand + '&ver=async' + '&time=' + time + '&referrerurl=' + referrerUrl + '&abr=false' + '&hbt=1&cid=' + encodeURIComponent(bid.params.clientId); - } - - $$PREBID_GLOBAL$$.adSupplyResponseHandler = function (bidId) { - if (!bidId) return; - - var bidRequest = utils.getBidRequest(bidId); - - if (!bidRequest || !bidRequest.params) return; - - var clientId = bidRequest.params.clientId; - var zoneProp = 'b' + bidRequest.params.zoneId; - - if (!window[clientId] || !window[clientId][zoneProp]) return; - - var media = window[clientId][zoneProp].Media; - - if (!media) return; - - if (!media.Url || !media.Ecpm || typeof media.Ecpm !== 'number' || media.Ecpm <= 0) { - var noFillbject = bidfactory.createBid(2, bidRequest); - noFillbject.bidderCode = ADSUPPLY_CODE; - bidmanager.addBidResponse(bidRequest.placementCode, noFillbject); - } else { - var bidObject = bidfactory.createBid(1, bidRequest); - bidObject.bidderCode = ADSUPPLY_CODE; - bidObject.cpm = media.Ecpm; - bidObject.ad = ''; - bidObject.width = media.Width; - bidObject.height = media.Height; - bidmanager.addBidResponse(bidRequest.placementCode, bidObject); - } - }; - - function _makeCallBackHandler(bidId) { - return function () { - $$PREBID_GLOBAL$$.adSupplyResponseHandler(bidId); - }; - } - - function _callBids(params) { - var bids = params.bids || []; - for (var i = 0; i < bids.length; i++) { - var bid = bids[i]; - if (!_validateParams(bid.params)) continue; - - var clientId = bid.params.clientId; - var zoneProp = 'b' + bid.params.zoneId; - window[clientId] = window[clientId] || {}; - window.window[clientId][zoneProp] = window.window[clientId][zoneProp] || {}; - window.window[clientId][zoneProp].Media = {}; - - var requestUrl = _getRequestUrl(bid); - adloader.loadScript(requestUrl, _makeCallBackHandler(bid.bidId)); - } - } - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new AdSupplyAdapter(), 'adsupply'); - -module.exports = AdSupplyAdapter; diff --git a/modules/adxcgBidAdapter.js b/modules/adxcgBidAdapter.js deleted file mode 100644 index ccb0287a866..00000000000 --- a/modules/adxcgBidAdapter.js +++ /dev/null @@ -1,139 +0,0 @@ -import bidfactory from 'src/bidfactory'; -import bidmanager from 'src/bidmanager'; -import * as utils from 'src/utils'; -import { STATUS } from 'src/constants'; -import adaptermanager from 'src/adaptermanager'; -import { ajax } from 'src/ajax'; -import * as url from 'src/url'; - -/** - * Adapter for requesting bids from Adxcg - * updated from latest prebid repo on 2017.08.30 - */ -function AdxcgAdapter() { - let bidRequests = {}; - - function _callBids(params) { - if (params.bids && params.bids.length > 0) { - let adZoneIds = []; - let prebidBidIds = []; - let sizes = []; - - params.bids.forEach(bid => { - bidRequests[bid.bidId] = bid; - adZoneIds.push(utils.getBidIdParameter('adzoneid', bid.params)); - prebidBidIds.push(bid.bidId); - sizes.push(utils.parseSizesInput(bid.sizes).join('|')); - }); - - let location = utils.getTopWindowLocation(); - let secure = location.protocol == 'https:'; - - let requestUrl = url.parse(location.href); - requestUrl.search = null; - requestUrl.hash = null; - - let adxcgRequestUrl = url.format({ - protocol: secure ? 'https' : 'http', - hostname: secure ? 'ad-emea-secure.adxcg.net' : 'ad-emea.adxcg.net', - pathname: '/get/adi', - search: { - renderformat: 'javascript', - ver: 'r20141124', - adzoneid: adZoneIds.join(','), - format: sizes.join(','), - prebidBidIds: prebidBidIds.join(','), - url: escape(url.format(requestUrl)), - secure: secure ? '1' : '0' - } - }); - - utils.logMessage(`submitting request: ${adxcgRequestUrl}`); - ajax(adxcgRequestUrl, handleResponse, null, { - withCredentials: true - }); - } - } - - function handleResponse(response) { - let adxcgBidReponseList; - - try { - adxcgBidReponseList = JSON.parse(response); - utils.logMessage(`adxcgBidReponseList: ${JSON.stringify(adxcgBidReponseList)}`); - } catch (error) { - adxcgBidReponseList = []; - utils.logError(error); - } - - adxcgBidReponseList.forEach(adxcgBidReponse => { - let bidRequest = bidRequests[adxcgBidReponse.bidId]; - delete bidRequests[adxcgBidReponse.bidId]; - - let bid = bidfactory.createBid(STATUS.GOOD, bidRequest); - - bid.creative_id = adxcgBidReponse.creativeId; - bid.code = 'adxcg'; - bid.bidderCode = 'adxcg'; - bid.cpm = adxcgBidReponse.cpm; - - if (adxcgBidReponse.ad) { - bid.ad = adxcgBidReponse.ad; - } else if (adxcgBidReponse.vastUrl) { - bid.vastUrl = adxcgBidReponse.vastUrl; - bid.descriptionUrl = adxcgBidReponse.vastUrl; - bid.mediaType = 'video'; - } else if (adxcgBidReponse.nativeResponse) { - bid.mediaType = 'native'; - - let nativeResponse = adxcgBidReponse.nativeResponse; - - bid.native = { - clickUrl: escape(nativeResponse.link.url), - impressionTrackers: nativeResponse.imptrackers - }; - - nativeResponse.assets.forEach(asset => { - if (asset.title && asset.title.text) { - bid.native.title = asset.title.text; - } - - if (asset.img && asset.img.url) { - bid.native.image = asset.img.url; - } - - if (asset.data && asset.data.label == 'DESC' && asset.data.value) { - bid.native.body = asset.data.value; - } - - if (asset.data && asset.data.label == 'SPONSORED' && asset.data.value) { - bid.native.sponsoredBy = asset.data.value; - } - }); - } - - bid.width = adxcgBidReponse.width; - bid.height = adxcgBidReponse.height; - - utils.logMessage(`submitting bid[${bidRequest.placementCode}]: ${JSON.stringify(bid)}`); - bidmanager.addBidResponse(bidRequest.placementCode, bid); - }); - - Object.keys(bidRequests) - .map(bidId => bidRequests[bidId].placementCode) - .forEach(placementCode => { - utils.logMessage(`creating no_bid bid for: ${placementCode}`); - bidmanager.addBidResponse(placementCode, bidfactory.createBid(STATUS.NO_BID)); - }); - }; - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new AdxcgAdapter(), 'adxcg', { - supportedMediaTypes: ['video', 'native'] -}); - -module.exports = AdxcgAdapter; diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js deleted file mode 100644 index 0ba497c5eed..00000000000 --- a/modules/adyoulikeBidAdapter.js +++ /dev/null @@ -1,199 +0,0 @@ -import Adapter from 'src/adapter'; -import bidfactory from 'src/bidfactory'; -import bidmanager from 'src/bidmanager'; -import * as utils from 'src/utils'; -import { format } from 'src/url'; -import { ajax } from 'src/ajax'; -import { STATUS } from 'src/constants'; -import adaptermanager from 'src/adaptermanager'; - -var AdyoulikeAdapter = function AdyoulikeAdapter() { - const _VERSION = '0.1'; - - const baseAdapter = new Adapter('adyoulike'); - - baseAdapter.callBids = function (bidRequest) { - const bidRequests = {}; - const bids = bidRequest.bids || []; - - const validBids = bids.filter(valid); - validBids.forEach(bid => { bidRequests[bid.params.placement] = bid; }); - - const placements = validBids.map(bid => bid.params.placement); - if (!utils.isEmpty(placements)) { - const body = createBody(placements); - const endpoint = createEndpoint(); - ajax(endpoint, - (response) => { - handleResponse(bidRequests, response); - }, body, { - contentType: 'text/json', - withCredentials: true - }); - } - }; - - /* Create endpoint url */ - function createEndpoint() { - return format({ - protocol: (document.location.protocol === 'https:') ? 'https' : 'http', - host: 'hb-api.omnitagjs.com', - pathname: '/hb-api/prebid', - search: createEndpointQS() - }); - } - - /* Create endpoint query string */ - function createEndpointQS() { - const qs = {}; - - const ref = getReferrerUrl(); - if (ref) { - qs.RefererUrl = encodeURIComponent(ref); - } - - const can = getCanonicalUrl(); - if (can) { - qs.CanonicalUrl = encodeURIComponent(can); - } - - return qs; - } - - /* Create request body */ - function createBody(placements) { - const body = { - Version: _VERSION, - Placements: placements, - }; - - // performance isn't supported by mobile safari iOS7. window.performance works, but - // evaluates to true on a unit test which expects false. - // - // try/catch was added to un-block the Prebid 0.25 release, but the adyoulike adapter - // maintainers should revisit this and see if it's really what they want. - try { - if (performance && performance.navigation) { - body.PageRefreshed = performance.navigation.type === performance.navigation.TYPE_RELOAD; - } - } catch (e) { - body.PageRefreshed = false; - } - - return JSON.stringify(body); - } - - /* Response handler */ - function handleResponse(bidRequests, response) { - let responses = []; - try { - responses = JSON.parse(response); - } catch (error) { utils.logError(error); } - - const bidResponses = {}; - responses.forEach(response => { - bidResponses[response.Placement] = response; - }); - - Object.keys(bidRequests).forEach(placement => { - addResponse(placement, bidRequests[placement], bidResponses[placement]); - }); - } - - /* Check that a bid has required parameters */ - function valid(bid) { - const sizes = getSize(bid.sizes); - if (!bid.params.placement || !sizes.width || !sizes.height) { - return false; - } - return true; - } - - /* Get current page referrer url */ - function getReferrerUrl() { - let referer = ''; - if (window.self !== window.top) { - try { - referer = window.top.document.referrer; - } catch (e) { } - } else { - referer = document.referrer; - } - return referer; - } - - /* Get current page canonical url */ - function getCanonicalUrl() { - let link; - if (window.self !== window.top) { - try { - link = window.top.document.head.querySelector('link[rel="canonical"][href]'); - } catch (e) { } - } else { - link = document.head.querySelector('link[rel="canonical"][href]'); - } - - if (link) { - return link.href; - } - return ''; - } - - /* Get parsed size from request size */ - function getSize(requestSizes) { - const parsed = {}; - const size = utils.parseSizesInput(requestSizes)[0]; - - if (typeof size !== 'string') { - return parsed; - } - - const parsedSize = size.toUpperCase().split('X'); - const width = parseInt(parsedSize[0], 10); - if (width) { - parsed.width = width; - } - - const height = parseInt(parsedSize[1], 10); - if (height) { - parsed.height = height; - } - - return parsed; - } - - /* Create bid from response */ - function createBid(placementId, bidRequest, response) { - let bid; - if (!response || !response.Banner) { - bid = bidfactory.createBid(STATUS.NO_BID, bidRequest); - } else { - bid = bidfactory.createBid(STATUS.GOOD, bidRequest); - const size = getSize(bidRequest.sizes); - bid.width = size.width; - bid.height = size.height; - bid.cpm = response.Price; - bid.ad = response.Banner; - } - - bid.bidderCode = baseAdapter.getBidderCode(); - - return bid; - } - - /* Add response to bidmanager */ - function addResponse(placementId, bidRequest, response) { - const bid = createBid(placementId, bidRequest, response); - const placement = bidRequest.placementCode; - bidmanager.addBidResponse(placement, bid); - } - - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - }); -}; - -adaptermanager.registerBidAdapter(new AdyoulikeAdapter(), 'adyoulike'); - -module.exports = AdyoulikeAdapter; diff --git a/modules/aerservBidAdapter.js b/modules/aerservBidAdapter.js deleted file mode 100644 index 64a02e77325..00000000000 --- a/modules/aerservBidAdapter.js +++ /dev/null @@ -1,117 +0,0 @@ -import bidfactory from 'src/bidfactory'; -import bidmanager from 'src/bidmanager'; -import * as utils from 'src/utils'; -import {ajax} from 'src/ajax'; -import {STATUS} from 'src/constants'; -import adaptermanager from 'src/adaptermanager'; - -const BIDDER_CODE = 'aerserv'; - -const AerServAdapter = function AerServAdapter() { - const ENVIRONMENTS = { - local: '127.0.0.1:8080', - dev: 'dev-ads.aerserv.com', - stage: 'staging-ads.aerserv.com', - prod: 'ads.aerserv.com' - }; - - const BANNER_PATH = '/as/json/pbjs/v1?'; - const VIDEO_PATH = '/as/json/pbjsvast/v1?'; - const REQUIRED_PARAMS = ['plc']; - - function _isResponseValid(bidRequest, response) { - return ((bidRequest.mediaType === 'video' && response.vastUrl) || (bidRequest.mediaType !== 'video' && response.adm)) && - response.cpm && response.cpm > 0; - } - - function _createBid(bidRequest, response) { - if (_isResponseValid(bidRequest, response)) { - let bid = bidfactory.createBid(1, bidRequest); - bid.bidderCode = BIDDER_CODE; - bid.cpm = response.cpm; - bid.width = response.w; - bid.height = response.h; - if (bidRequest.mediaType === 'video') { - bid.vastUrl = response.vastUrl; - bid.descriptionUrl = response.vastUrl; - bid.mediaType = 'video'; - } else { - bid.ad = response.adm; - } - bidmanager.addBidResponse(bidRequest.placementCode, bid); - } else { - bidmanager.addBidResponse(bidRequest.placementCode, bidfactory.createBid(STATUS.NO_BID, bidRequest)); - } - } - - function _getFirstSize(sizes) { - let sizeObj = {}; - if (utils.isArray(sizes) && sizes.length > 0 && utils.isArray(sizes[0]) && sizes[0].length === 2) { - sizeObj['vpw'] = sizes[0][0]; - sizeObj['vph'] = sizes[0][1]; - } - return sizeObj; - } - - function _buildQueryParameters(bid, requestParams) { - Object.keys(bid.params).filter(param => param !== 'video') - .forEach(param => requestParams[param] = bid.params[param]); - - if (bid.mediaType === 'video') { - let videoDimensions = _getFirstSize(bid.sizes); - Object.keys(videoDimensions).forEach(param => requestParams[param] = videoDimensions[param]); - Object.keys(bid.params.video || {}).forEach(param => requestParams[param] = bid.params.video[param]); - } - - return utils.parseQueryStringParameters(requestParams); - } - - function _handleResponse(bidRequest) { - return response => { - if (!response && response.length <= 0) { - bidmanager.addBidResponse(bidRequest.placementCode, bidfactory.createBid(STATUS.NO_BID, bidRequest)); - utils.logError('Empty response'); - return; - } - - try { - response = JSON.parse(response); - } catch (e) { - bidmanager.addBidResponse(bidRequest.placementCode, bidfactory.createBid(STATUS.NO_BID, bidRequest)); - utils.logError('Invalid JSON in response'); - return; - } - - _createBid(bidRequest, response); - }; - } - - function _callBids(bidRequests) { - let currentUrl = (window.parent !== window) ? document.referrer : window.location.href; - currentUrl = currentUrl && encodeURIComponent(currentUrl); - - let bids = bidRequests.bids || []; - bids.forEach(bid => { - if (utils.hasValidBidRequest(bid.params, REQUIRED_PARAMS, BIDDER_CODE)) { - let env = ENVIRONMENTS[bid.params['env']] || ENVIRONMENTS['prod']; - let requestPath = bid.mediaType === 'video' ? VIDEO_PATH : BANNER_PATH; - let pageParameters = {url: currentUrl}; - let parameterStr = _buildQueryParameters(bid, pageParameters); - - let url = `//${env}${requestPath}${parameterStr}`; - utils.logMessage('sending request to: ' + url); - ajax(url, _handleResponse(bid), null, {withCredentials: true}); - } else { - bidmanager.addBidResponse(bid.placementCode, bidfactory.createBid(STATUS.NO_BID, bid)); - } - }); - } - - return { - callBids: _callBids - } -}; - -adaptermanager.registerBidAdapter(new AerServAdapter(), BIDDER_CODE, {supportedMediaTypes: ['video']}); - -module.exports = AerServAdapter; diff --git a/modules/aolBidAdapter.js b/modules/aolBidAdapter.js deleted file mode 100644 index 4506ac1512e..00000000000 --- a/modules/aolBidAdapter.js +++ /dev/null @@ -1,336 +0,0 @@ -const utils = require('src/utils.js'); -const ajax = require('src/ajax.js').ajax; -const bidfactory = require('src/bidfactory.js'); -const bidmanager = require('src/bidmanager.js'); -const constants = require('src/constants.json'); -const adaptermanager = require('src/adaptermanager'); -const BaseAdapter = require('src/adapter').default; - -const AOL_BIDDERS_CODES = { - aol: 'aol', - onemobile: 'onemobile', - onedisplay: 'onedisplay' -}; - -$$PREBID_GLOBAL$$.aolGlobals = { - pixelsDropped: false -}; - -const AolAdapter = function AolAdapter() { - let showCpmAdjustmentWarning = true; - const pubapiTemplate = template`${'protocol'}://${'host'}/pubapi/3.0/${'network'}/${'placement'}/${'pageid'}/${'sizeid'}/ADTECH;v=2;cmd=bid;cors=yes;alias=${'alias'}${'bidfloor'};misc=${'misc'}`; - const nexageBaseApiTemplate = template`${'protocol'}://${'host'}/bidRequest?`; - const nexageGetApiTemplate = template`dcn=${'dcn'}&pos=${'pos'}&cmd=bid${'ext'}`; - const MP_SERVER_MAP = { - us: 'adserver-us.adtech.advertising.com', - eu: 'adserver-eu.adtech.advertising.com', - as: 'adserver-as.adtech.advertising.com' - }; - const NEXAGE_SERVER = 'hb.nexage.com'; - const SYNC_TYPES = { - iframe: 'IFRAME', - img: 'IMG' - }; - - let domReady = (() => { - let readyEventFired = false; - return fn => { - let idempotentFn = () => { - if (readyEventFired) { - return; - } - readyEventFired = true; - return fn(); - }; - - if (document.readyState === 'complete') { - return idempotentFn(); - } - - document.addEventListener('DOMContentLoaded', idempotentFn, false); - window.addEventListener('load', idempotentFn, false); - }; - })(); - - function dropSyncCookies(pixels) { - if (!$$PREBID_GLOBAL$$.aolGlobals.pixelsDropped) { - let pixelElements = parsePixelItems(pixels); - renderPixelElements(pixelElements); - $$PREBID_GLOBAL$$.aolGlobals.pixelsDropped = true; - } - } - - 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 tagNameMatches = item.match(tagNameRegExp); - let sourcesPathMatches = item.match(srcRegExp); - if (tagNameMatches && sourcesPathMatches) { - pixelsItems.push({ - tagName: tagNameMatches[0].toUpperCase(), - src: sourcesPathMatches[2] - }); - } - }); - } - } - - return pixelsItems; - } - - function renderPixelElements(pixelsElements) { - pixelsElements.forEach((element) => { - switch (element.tagName) { - case SYNC_TYPES.img: - return renderPixelImage(element); - case SYNC_TYPES.iframe: - return renderPixelIframe(element); - } - }); - } - - function renderPixelImage(pixelsItem) { - let image = new Image(); - image.src = pixelsItem.src; - } - - function renderPixelIframe(pixelsItem) { - let iframe = document.createElement('iframe'); - iframe.width = 1; - iframe.height = 1; - iframe.style.display = 'none'; - iframe.src = pixelsItem.src; - if (document.readyState === 'interactive' || - document.readyState === 'complete') { - document.body.appendChild(iframe); - } else { - domReady(() => { - document.body.appendChild(iframe); - }); - } - } - - function template(strings, ...keys) { - return function(...values) { - let dict = values[values.length - 1] || {}; - let result = [strings[0]]; - keys.forEach(function(key, i) { - let value = Number.isInteger(key) ? values[key] : dict[key]; - result.push(value, strings[i + 1]); - }); - return result.join(''); - }; - } - - function _buildMarketplaceUrl(bid) { - const params = bid.params; - const serverParam = params.server; - let regionParam = params.region || 'us'; - let server; - - if (!MP_SERVER_MAP.hasOwnProperty(regionParam)) { - utils.logWarn(`Unknown region '${regionParam}' for AOL bidder.`); - regionParam = 'us'; // Default region. - } - - if (serverParam) { - server = serverParam; - } else { - server = MP_SERVER_MAP[regionParam]; - } - - // Set region param, used by AOL analytics. - params.region = regionParam; - - return pubapiTemplate({ - protocol: (document.location.protocol === 'https:') ? 'https' : 'http', - host: server, - network: params.network, - placement: parseInt(params.placement), - pageid: params.pageId || 0, - sizeid: params.sizeId || 0, - alias: params.alias || utils.getUniqueIdentifierStr(), - bidfloor: (typeof params.bidFloor !== 'undefined') - ? `;bidfloor=${params.bidFloor.toString()}` : '', - misc: new Date().getTime() // cache busting - }); - } - - function _buildNexageApiUrl(bid) { - let {dcn, pos} = bid.params; - let nexageApi = nexageBaseApiTemplate({ - protocol: (document.location.protocol === 'https:') ? 'https' : 'http', - host: bid.params.host || NEXAGE_SERVER - }); - if (dcn && pos) { - let ext = ''; - utils._each(bid.params.ext, (value, key) => { - ext += `&${key}=${encodeURIComponent(value)}`; - }); - nexageApi += nexageGetApiTemplate({dcn, pos, ext}); - } - return nexageApi; - } - - function _addErrorBidResponse(bid, response = {}) { - const bidResponse = bidfactory.createBid(2, bid); - bidResponse.bidderCode = bid.bidder; - bidResponse.reason = response.nbr; - bidResponse.raw = response; - bidmanager.addBidResponse(bid.placementCode, bidResponse); - } - - function _addBidResponse(bid, response) { - let bidData; - - try { - bidData = response.seatbid[0].bid[0]; - } catch (e) { - _addErrorBidResponse(bid, response); - 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 price in bid response', AOL_BIDDERS_CODES.aol, bid); - _addErrorBidResponse(bid, response); - return; - } - } - - let ad = bidData.adm; - if (response.ext && response.ext.pixels) { - if (bid.params.userSyncOn === constants.EVENTS.BID_RESPONSE) { - dropSyncCookies(response.ext.pixels); - } else { - let formattedPixels = response.ext.pixels.replace(/<\/?script( type=('|")text\/javascript('|")|)?>/g, ''); - - ad += ''; - } - } - - const bidResponse = bidfactory.createBid(1, bid); - bidResponse.bidderCode = bid.bidder; - bidResponse.ad = ad; - bidResponse.cpm = cpm; - bidResponse.width = bidData.w; - bidResponse.height = bidData.h; - bidResponse.creativeId = bidData.crid; - bidResponse.pubapiId = response.id; - bidResponse.currencyCode = response.cur; - if (bidData.dealid) { - bidResponse.dealId = bidData.dealid; - } - - bidmanager.addBidResponse(bid.placementCode, bidResponse); - } - - function _isMarketplaceBidder(bidder) { - return bidder === AOL_BIDDERS_CODES.aol || bidder === AOL_BIDDERS_CODES.onedisplay; - } - - function _isNexageBidder(bidder) { - return bidder === AOL_BIDDERS_CODES.aol || bidder === AOL_BIDDERS_CODES.onemobile; - } - - function _isNexageRequestPost(bid) { - if (_isNexageBidder(bid.bidder) && bid.params.id && bid.params.imp && bid.params.imp[0]) { - let imp = bid.params.imp[0]; - return imp.id && imp.tagid && - ((imp.banner && imp.banner.w && imp.banner.h) || - (imp.video && imp.video.mimes && imp.video.minduration && imp.video.maxduration)); - } - } - - function _isNexageRequestGet(bid) { - return _isNexageBidder(bid.bidder) && bid.params.dcn && bid.params.pos; - } - - function _isMarketplaceRequest(bid) { - return _isMarketplaceBidder(bid.bidder) && bid.params.placement && bid.params.network; - } - - function _callBids(params) { - utils._each(params.bids, bid => { - let apiUrl; - let data = null; - let options = { - withCredentials: true - }; - let isNexageRequestPost = _isNexageRequestPost(bid); - let isNexageRequestGet = _isNexageRequestGet(bid); - let isMarketplaceRequest = _isMarketplaceRequest(bid); - - if (isNexageRequestGet || isNexageRequestPost) { - apiUrl = _buildNexageApiUrl(bid); - if (isNexageRequestPost) { - data = bid.params; - options.customHeaders = { - 'x-openrtb-version': '2.2' - }; - options.method = 'POST'; - options.contentType = 'application/json'; - } - } else if (isMarketplaceRequest) { - apiUrl = _buildMarketplaceUrl(bid); - } - - if (apiUrl) { - ajax(apiUrl, response => { - // Needs to be here in case bidderSettings are defined after requestBids() is called - if (showCpmAdjustmentWarning && - $$PREBID_GLOBAL$$.bidderSettings && $$PREBID_GLOBAL$$.bidderSettings.aol && - typeof $$PREBID_GLOBAL$$.bidderSettings.aol.bidCpmAdjustment === 'function' - ) { - utils.logWarn( - 'bidCpmAdjustment is active for the AOL adapter. ' + - 'As of Prebid 0.14, AOL can bid in net – please contact your accounts team to enable.' - ); - } - showCpmAdjustmentWarning = false; // warning is shown at most once - - if (!response && response.length <= 0) { - utils.logError('Empty bid response', AOL_BIDDERS_CODES.aol, bid); - _addErrorBidResponse(bid, response); - return; - } - - try { - response = JSON.parse(response); - } catch (e) { - utils.logError('Invalid JSON in bid response', AOL_BIDDERS_CODES.aol, bid); - _addErrorBidResponse(bid, response); - return; - } - - _addBidResponse(bid, response); - }, data, options); - } - }); - } - - return Object.assign(this, new BaseAdapter(AOL_BIDDERS_CODES.aol), { - callBids: _callBids - }); -}; - -adaptermanager.registerBidAdapter(new AolAdapter(), AOL_BIDDERS_CODES.aol); -adaptermanager.aliasBidAdapter(AOL_BIDDERS_CODES.aol, AOL_BIDDERS_CODES.onedisplay); -adaptermanager.aliasBidAdapter(AOL_BIDDERS_CODES.aol, AOL_BIDDERS_CODES.onemobile); - -module.exports = AolAdapter; diff --git a/modules/appnexusAstBidAdapter.js b/modules/appnexusAstBidAdapter.js index 326d423d192..ceea14232cc 100644 --- a/modules/appnexusAstBidAdapter.js +++ b/modules/appnexusAstBidAdapter.js @@ -26,6 +26,7 @@ const SOURCE = 'pbjs'; export const spec = { code: BIDDER_CODE, + aliases: ['brealtime', 'pagescience', 'defymedia', 'gourmetads', 'matomy', 'featureforward', 'oftmedia'], supportedMediaTypes: [VIDEO, NATIVE], /** diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js deleted file mode 100644 index 3d6549542dc..00000000000 --- a/modules/appnexusBidAdapter.js +++ /dev/null @@ -1,233 +0,0 @@ -import { getBidRequest } from 'src/utils'; -import adaptermanager from 'src/adaptermanager'; - -var CONSTANTS = require('src/constants'); -var utils = require('src/utils'); -var adloader = require('src/adloader'); -var bidmanager = require('src/bidmanager'); -var bidfactory = require('src/bidfactory'); -var Adapter = require('src/adapter').default; - -var AppNexusAdapter; -AppNexusAdapter = function AppNexusAdapter() { - var baseAdapter = new Adapter('appnexus'); - var usersync = false; - - baseAdapter.callBids = function (params) { - // var bidCode = baseAdapter.getBidderCode(); - - var anArr = params.bids; - - // var bidsCount = anArr.length; - - // set expected bids count for callback execution - // bidmanager.setExpectedBidsCount(bidCode, bidsCount); - - for (var i = 0; i < anArr.length; i++) { - var bidRequest = anArr[i]; - var callbackId = bidRequest.bidId; - adloader.loadScript(buildJPTCall(bidRequest, callbackId)); - - // store a reference to the bidRequest from the callback id - // bidmanager.pbCallbackMap[callbackId] = bidRequest; - } - }; - - function buildJPTCall(bid, callbackId) { - // determine tag params - var placementId = utils.getBidIdParameter('placementId', bid.params); - - // memberId will be deprecated, use member instead - var memberId = utils.getBidIdParameter('memberId', bid.params); - var member = utils.getBidIdParameter('member', bid.params); - var inventoryCode = utils.getBidIdParameter('invCode', bid.params); - var query = utils.getBidIdParameter('query', bid.params); - var referrer = utils.getBidIdParameter('referrer', bid.params); - var altReferrer = utils.getBidIdParameter('alt_referrer', bid.params); - var jptCall = '//ib.adnxs.com/jpt?'; - - jptCall = utils.tryAppendQueryString(jptCall, 'callback', '$$PREBID_GLOBAL$$.handleAnCB'); - jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); - jptCall = utils.tryAppendQueryString(jptCall, 'psa', '0'); - jptCall = utils.tryAppendQueryString(jptCall, 'id', placementId); - if (member) { - jptCall = utils.tryAppendQueryString(jptCall, 'member', member); - } else if (memberId) { - jptCall = utils.tryAppendQueryString(jptCall, 'member', memberId); - utils.logMessage('appnexus.callBids: "memberId" will be deprecated soon. Please use "member" instead'); - } - - jptCall = utils.tryAppendQueryString(jptCall, 'code', inventoryCode); - jptCall = utils.tryAppendQueryString(jptCall, 'traffic_source_code', (utils.getBidIdParameter('trafficSourceCode', bid.params))); - - // sizes takes a bit more logic - var sizeQueryString = ''; - var parsedSizes = utils.parseSizesInput(bid.sizes); - - // combine string into proper querystring for impbus - var parsedSizesLength = parsedSizes.length; - if (parsedSizesLength > 0) { - // first value should be "size" - sizeQueryString = 'size=' + parsedSizes[0]; - if (parsedSizesLength > 1) { - // any subsequent values should be "promo_sizes" - sizeQueryString += '&promo_sizes='; - for (var j = 1; j < parsedSizesLength; j++) { - sizeQueryString += parsedSizes[j] += ','; - } - - // remove trailing comma - if (sizeQueryString && sizeQueryString.charAt(sizeQueryString.length - 1) === ',') { - sizeQueryString = sizeQueryString.slice(0, sizeQueryString.length - 1); - } - } - } - - if (sizeQueryString) { - jptCall += sizeQueryString + '&'; - } - - // this will be deprecated soon - var targetingParams = utils.parseQueryStringParameters(query); - - if (targetingParams) { - // don't append a & here, we have already done it in parseQueryStringParameters - jptCall += targetingParams; - } - - // append custom attributes: - var paramsCopy = Object.assign({}, bid.params); - - // delete attributes already used - delete paramsCopy.placementId; - delete paramsCopy.memberId; - delete paramsCopy.invCode; - delete paramsCopy.query; - delete paramsCopy.referrer; - delete paramsCopy.alt_referrer; - delete paramsCopy.member; - - // get the reminder - var queryParams = utils.parseQueryStringParameters(paramsCopy); - - // append - if (queryParams) { - jptCall += queryParams; - } - - // append referrer - if (referrer === '') { - referrer = utils.getTopWindowUrl(); - } - - jptCall = utils.tryAppendQueryString(jptCall, 'referrer', referrer); - jptCall = utils.tryAppendQueryString(jptCall, 'alt_referrer', altReferrer); - - // remove the trailing "&" - if (jptCall.lastIndexOf('&') === jptCall.length - 1) { - jptCall = jptCall.substring(0, jptCall.length - 1); - } - - // @if NODE_ENV='debug' - utils.logMessage('jpt request built: ' + jptCall); - - // @endif - - // append a timer here to track latency - bid.startTime = new Date().getTime(); - - return jptCall; - } - - // expose the callback to the global object: - $$PREBID_GLOBAL$$.handleAnCB = function (jptResponseObj) { - var bidCode; - - if (jptResponseObj && jptResponseObj.callback_uid) { - var responseCPM; - var id = jptResponseObj.callback_uid; - var placementCode = ''; - var bidObj = getBidRequest(id); - if (bidObj) { - bidCode = bidObj.bidder; - - placementCode = bidObj.placementCode; - - // set the status - bidObj.status = CONSTANTS.STATUS.GOOD; - } - - // @if NODE_ENV='debug' - utils.logMessage('JSONP callback function called for ad ID: ' + id); - - // @endif - var bid = []; - if (jptResponseObj.result && jptResponseObj.result.cpm && jptResponseObj.result.cpm !== 0) { - responseCPM = parseInt(jptResponseObj.result.cpm, 10); - - // CPM response from /jpt is dollar/cent multiplied by 10000 - // in order to avoid using floats - // switch CPM to "dollar/cent" - responseCPM = responseCPM / 10000; - - // store bid response - // bid status is good (indicating 1) - var adId = jptResponseObj.result.creative_id; - bid = bidfactory.createBid(1, bidObj); - bid.creative_id = adId; - bid.bidderCode = bidCode; - bid.cpm = responseCPM; - bid.adUrl = jptResponseObj.result.ad; - bid.width = jptResponseObj.result.width; - bid.height = jptResponseObj.result.height; - bid.dealId = jptResponseObj.result.deal_id; - - bidmanager.addBidResponse(placementCode, bid); - } else { - // no response data - // @if NODE_ENV='debug' - utils.logMessage('No prebid response from AppNexus for placement code ' + placementCode); - - // @endif - // indicate that there is no bid for this placement - bid = bidfactory.createBid(2, bidObj); - bid.bidderCode = bidCode; - bidmanager.addBidResponse(placementCode, bid); - } - - if (!usersync) { - var iframe = utils.createInvisibleIframe(); - iframe.src = '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html'; - try { - document.body.appendChild(iframe); - } catch (error) { - utils.logError(error); - } - usersync = true; - } - } else { - // no response data - // @if NODE_ENV='debug' - utils.logMessage('No prebid response for placement %%PLACEMENT%%'); - - // @endif - } - }; - - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - buildJPTCall: buildJPTCall - }); -}; - -adaptermanager.registerBidAdapter(new AppNexusAdapter(), 'appnexus'); -adaptermanager.aliasBidAdapter('appnexus', 'brealtime'); -adaptermanager.aliasBidAdapter('appnexus', 'pagescience'); -adaptermanager.aliasBidAdapter('appnexus', 'defymedia'); -adaptermanager.aliasBidAdapter('appnexus', 'gourmetads'); -adaptermanager.aliasBidAdapter('appnexus', 'matomy'); -adaptermanager.aliasBidAdapter('appnexus', 'featureforward'); -adaptermanager.aliasBidAdapter('appnexus', 'oftmedia'); - -module.exports = AppNexusAdapter; diff --git a/modules/atomxBidAdapter.js b/modules/atomxBidAdapter.js deleted file mode 100644 index 69bb04a227b..00000000000 --- a/modules/atomxBidAdapter.js +++ /dev/null @@ -1,81 +0,0 @@ -var CONSTANTS = require('src/constants.json'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); -var Ajax = require('src/ajax'); -var utils = require('src/utils.js'); -var adaptermanager = require('src/adaptermanager'); - -/** - * Adapter for requesting bids from Atomx. - * - * @returns {{callBids: _callBids, responseCallback: _responseCallback}} - */ -var AtomxAdapter = function AtomxAdapter() { - function _callBids(data) { - if (!window.atomx_prebid) { - adloader.loadScript(window.location.protocol + '//s.ato.mx/b.js', function() { _bid(data); }, true); - } else { - _bid(data); - } - } - - function _bid(data) { - var url = window.atomx_prebid(); - var bids = data.bids || []; - for (var i = 0, ln = bids.length; i < ln; i++) { - var bid = bids[i]; - if (bid.params && bid.params.id) { - var sizes = utils.parseSizesInput(bid.sizes); - for (var j = 0; j < sizes.length; j++) { - Ajax.ajax(url, _responseCallback.bind(this, bid), { - id: bid.params.id, - size: sizes[j], - prebid: bid.placementCode - }, {method: 'GET', noDecodeWholeURL: true}); - } - } else { - var bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bid); - bidObject.bidderCode = 'atomx'; - bidmanager.addBidResponse(bid.placementCode, bidObject); - } - } - } - - function _responseCallback(bid, data) { - var bidObject; - try { - data = JSON.parse(data); - - if (data.cpm && data.cpm > 0) { - bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bid); - bidObject.bidderCode = 'atomx'; - bidObject.cpm = data.cpm * 1000; - if (data.adm) { - bidObject.ad = data.adm; - } else { - bidObject.adUrl = data.url; - } - bidObject.width = data.width; - bidObject.height = data.height; - bidmanager.addBidResponse(bid.placementCode, bidObject); - return; - } - } catch (_error) { - utils.logError(_error); - } - - bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bid); - bidObject.bidderCode = 'atomx'; - bidmanager.addBidResponse(bid.placementCode, bidObject); - } - - return { - callBids: _callBids, - responseCallback: _responseCallback - }; -}; - -adaptermanager.registerBidAdapter(new AtomxAdapter(), 'atomx'); - -module.exports = AtomxAdapter; diff --git a/modules/audienceNetworkBidAdapter.js b/modules/audienceNetworkBidAdapter.js deleted file mode 100644 index de2e3aaff6b..00000000000 --- a/modules/audienceNetworkBidAdapter.js +++ /dev/null @@ -1,257 +0,0 @@ -/** - * @file AudienceNetwork adapter. - */ -import { ajax } from 'src/ajax'; -import { createBid } from 'src/bidfactory'; -import { addBidResponse } from 'src/bidmanager'; -import { STATUS } from 'src/constants.json'; -import { format } from 'src/url'; -import { logError } from 'src/utils'; -import Adapter from 'src/adapter'; -import adaptermanager from 'src/adaptermanager'; - -const { setBidderCode, getBidderCode } = new Adapter('audienceNetwork'); - -/** - * Does this bid request contain valid parameters? - * @param {Object} bid - * @returns {Boolean} - */ -const validateBidRequest = bid => - typeof bid.params === 'object' && - typeof bid.params.placementId === 'string' && - bid.params.placementId.length > 0 && - Array.isArray(bid.sizes) && bid.sizes.length > 0 && - (isVideo(bid.params.format) || bid.sizes.map(flattenSize).some(isValidSize)); - -/** - * Flattens a 2-element [W, H] array as a 'WxH' string, - * otherwise passes value through. - * @param {Array|String} size - * @returns {String} - */ -const flattenSize = size => - (Array.isArray(size) && size.length === 2) ? `${size[0]}x${size[1]}` : size; - -/** - * Expands a 'WxH' string as a 2-element [W, H] array - * @param {String} size - * @returns {Array} - */ -const expandSize = size => size.split('x').map(Number); - -/** - * Is this a valid slot size? - * @param {String} size - * @returns {Boolean} - */ -const isValidSize = size => ['300x250', '320x50'].includes(size); - -/** - * Is this a video format? - * @param {String} format - * @returns {Boolean} - */ -const isVideo = format => format === 'video'; - -/** - * Which SDK version should be used for this format? - * @param {String} format - * @returns {String} - */ -const sdkVersion = format => isVideo(format) ? '' : '5.5.web'; - -/** - * Does the search part of the URL contain "anhb_testmode" - * and therefore indicate testmode should be used? - * @returns {String} "true" or "false" - */ -const isTestmode = () => Boolean( - window && window.location && - typeof window.location.search === 'string' && - window.location.search.indexOf('anhb_testmode') !== -1 -).toString(); - -/** - * Parse JSON-as-string into an Object, default to empty. - * @param {String} JSON-as-string - * @returns {Object} - */ -const parseJson = jsonAsString => { - let data = {}; - try { - data = JSON.parse(jsonAsString); - } catch (err) {} - return data; -}; - -/** - * Generate ad HTML for injection into an iframe - * @param {String} placementId - * @param {String} format - * @param {String} bidId - * @returns {String} HTML - */ -const createAdHtml = (placementId, format, bidId) => { - const nativeStyle = format === 'native' ? '' : ''; - const nativeContainer = format === 'native' ? '
' : ''; - return `${nativeStyle} `; -}; - -/** - * Creates a "good" Bid object with the given bid ID and CPM. - * @param {String} placementId - * @param {String} size - * @param {String} format - * @param {String} bidId - * @param {Number} cpmCents - * @param {String} pageurl - * @returns {Object} Bid - */ -const createSuccessBidResponse = (placementId, size, format, bidId, cpmCents, pageurl) => { - const bid = createBid(STATUS.GOOD, { bidId }); - // Prebid attributes - bid.bidderCode = getBidderCode(); - bid.cpm = cpmCents / 100; - bid.ad = createAdHtml(placementId, format, bidId); - [bid.width, bid.height] = expandSize(size); - - // Audience Network attributes - bid.hb_bidder = 'fan'; - bid.fb_bidid = bidId; - bid.fb_format = format; - bid.fb_placementid = placementId; - // Video attributes - if (isVideo(format)) { - const vast = `https://an.facebook.com/v1/instream/vast.xml?placementid=${placementId}&pageurl=${pageurl}&playerwidth=${bid.width}&playerheight=${bid.height}&bidid=${bidId}`; - bid.mediaType = 'video'; - bid.vastUrl = vast; - bid.descriptionUrl = vast; - } - return bid; -}; - -/** - * Creates a "no bid" Bid object. - * @returns {Object} Bid - */ -const createFailureBidResponse = () => { - const bid = createBid(STATUS.NO_BID); - bid.bidderCode = getBidderCode(); - return bid; -}; - -/** - * Fetch bids for given parameters. - * @param {Object} bidRequest - * @param {Array} params.bids - list of bids - * @param {String} params.bids[].placementCode - Prebid placement identifier - * @param {Object} params.bids[].params - * @param {String} params.bids[].params.placementId - Audience Network placement identifier - * @param {String} params.bids[].params.format - Optional format, one of 'video', 'native' or 'fullwidth' if set - * @param {Array} params.bids[].sizes - list of desired advert sizes - * @param {Array} params.bids[].sizes[] - Size arrays [h,w]: should include one of [300, 250], [320, 50]: first matched size is used - * @returns {void} - */ -const callBids = bidRequest => { - // Build lists of adUnitCodes, placementids, adformats and sizes - const adUnitCodes = []; - const placementids = []; - const adformats = []; - const sizes = []; - const sdk = []; - - bidRequest.bids - .filter(validateBidRequest) - .forEach(bid => bid.sizes - .map(flattenSize) - .filter(size => isValidSize(size) || isVideo(bid.params.format)) - .slice(0, 1) - .forEach(size => { - adUnitCodes.push(bid.placementCode); - placementids.push(bid.params.placementId); - adformats.push(bid.params.format || size); - sizes.push(size); - sdk.push(sdkVersion(bid.params.format)); - }) - ); - - if (placementids.length) { - // Build URL - const testmode = isTestmode(); - const pageurl = encodeURIComponent(location.href); - const search = { - placementids, - adformats, - testmode, - pageurl, - sdk - }; - const video = adformats.findIndex(isVideo); - if (video !== -1) { - [search.playerwidth, search.playerheight] = expandSize(sizes[video]); - } - const url = format({ - protocol: 'https', - host: 'an.facebook.com', - pathname: '/v2/placementbid.json', - search - }); - // Request - ajax(url, res => { - // Handle response - const data = parseJson(res); - if (data.errors && data.errors.length) { - const noBid = createFailureBidResponse(); - adUnitCodes.forEach(adUnitCode => addBidResponse(adUnitCode, noBid)); - data.errors.forEach(logError); - } else { - // For each placementId in bids Object - Object.keys(data.bids) - // extract Array of bid responses - .map(placementId => data.bids[placementId]) - // flatten - .reduce((a, b) => a.concat(b), []) - // call addBidResponse - .forEach((bid, i) => - addBidResponse(adUnitCodes[i], createSuccessBidResponse( - bid.placement_id, - sizes[i], - adformats[i], - bid.bid_id, - bid.bid_price_cents, - pageurl - )) - ); - } - }, null, { withCredentials: true }); - } else { - // No valid bids - logError('No valid bids requested'); - } -}; - -/** - * @class AudienceNetwork - * @type {Object} - * @property {Function} callBids - fetch bids for given parameters - * @property {Function} setBidderCode - used for bidder aliasing - * @property {Function} getBidderCode - unique 'audienceNetwork' identifier - */ -function AudienceNetwork() { - return Object.assign(this, { - callBids, - setBidderCode, - getBidderCode - }); -} - -adaptermanager.registerBidAdapter(new AudienceNetwork(), 'audienceNetwork', { - supportedMediaTypes: ['video'] -}); - -module.exports = AudienceNetwork; diff --git a/modules/beachfrontBidAdapter.js b/modules/beachfrontBidAdapter.js deleted file mode 100644 index 0193df6a3ac..00000000000 --- a/modules/beachfrontBidAdapter.js +++ /dev/null @@ -1,135 +0,0 @@ -import Adapter from 'src/adapter'; -import bidfactory from 'src/bidfactory'; -import bidmanager from 'src/bidmanager'; -import * as utils from 'src/utils'; -import { ajax } from 'src/ajax'; -import { STATUS } from 'src/constants'; -import adaptermanager from 'src/adaptermanager'; - -const ENDPOINT = '//reachms.bfmio.com/bid.json?exchange_id='; - -function BeachfrontAdapter() { - var baseAdapter = new Adapter('beachfront'); - - baseAdapter.callBids = function (bidRequests) { - const bids = bidRequests.bids || []; - bids.forEach(function(bid) { - var bidRequest = getBidRequest(bid); - var RTBDataParams = prepareAndSaveRTBRequestParams(bid); - if (!RTBDataParams) { - var error = 'No bid params'; - utils.logError(error); - if (bid && bid.placementCode) { - bidmanager.addBidResponse(bid.placementCode, createBid(bid, STATUS.NO_BID)); - } - return; - } - var BID_URL = ENDPOINT + RTBDataParams.appId; - ajax(BID_URL, handleResponse(bidRequest), JSON.stringify(RTBDataParams), { - contentType: 'text/plain', - withCredentials: true - }); - }); - }; - - function getBidRequest(bid) { - if (!bid || !bid.params || !bid.params.appId) { - return; - } - - var bidRequest = bid; - bidRequest.width = parseInt(bid.sizes[0], 10) || undefined; - bidRequest.height = parseInt(bid.sizes[1], 10) || undefined; - return bidRequest; - } - - function prepareAndSaveRTBRequestParams(bid) { - if (!bid || !bid.params || !bid.params.appId || !bid.params.bidfloor) { - return; - } - - function fetchDeviceType() { - return ((/(ios|ipod|ipad|iphone|android)/i).test(global.navigator.userAgent) ? 1 : ((/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(global.navigator.userAgent) ? 1 : 2)); - } - - var bidRequestObject = { - isPrebid: true, - appId: bid.params.appId, - domain: document.location.hostname, - imp: [{ - video: { - w: bid.width, - h: bid.height - }, - bidfloor: bid.params.bidfloor - }], - site: { - page: utils.getTopWindowLocation().host - }, - device: { - ua: navigator.userAgent, - devicetype: fetchDeviceType() - }, - cur: ['USD'] - }; - return bidRequestObject; - } - - /* Notify Prebid of bid responses so bids can get in the auction */ - function handleResponse(bidRequest) { - return function(response) { - var parsed; - if (response) { - try { - parsed = JSON.parse(response); - } catch (error) { - utils.logError(error); - } - } else { - utils.logWarn('No bid response'); - } - - if (!parsed || parsed.error || !parsed.url || !parsed.bidPrice) { - utils.logWarn('No Valid Bid'); - bidmanager.addBidResponse(bidRequest.placementCode, createBid(bidRequest, STATUS.NO_BID)); - return; - } - - var newBid = {}; - newBid.price = parsed.bidPrice; - newBid.url = parsed.url; - newBid.bidId = bidRequest.bidId; - bidmanager.addBidResponse(bidRequest.placementCode, createBid(bidRequest, STATUS.GOOD, newBid)); - }; - } - - function createBid(bidRequest, status, tag) { - var bid = bidfactory.createBid(status, tag); - bid.code = baseAdapter.getBidderCode(); - bid.bidderCode = bidRequest.bidder; - if (!tag || status !== STATUS.GOOD) { - return bid; - } - - bid.cpm = tag.price; - bid.creative_id = tag.cmpId; - bid.width = bidRequest.width; - bid.height = bidRequest.height; - bid.descriptionUrl = tag.url; - bid.vastUrl = tag.url; - bid.mediaType = 'video'; - - return bid; - } - - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode - }); -} - -adaptermanager.registerBidAdapter(new BeachfrontAdapter(), 'beachfront', { - supportedMediaTypes: ['video'] -}); - -module.exports = BeachfrontAdapter; diff --git a/modules/bidfluenceBidAdapter.js b/modules/bidfluenceBidAdapter.js deleted file mode 100644 index 73b548a4993..00000000000 --- a/modules/bidfluenceBidAdapter.js +++ /dev/null @@ -1,58 +0,0 @@ -const bidmanager = require('src/bidmanager'); -const bidfactory = require('src/bidfactory'); -const utils = require('src/utils'); -const adloader = require('src/adloader'); -const adaptermanager = require('src/adaptermanager'); - -var BidfluenceAdapter = function BidfluenceAdapter() { - const scriptUrl = '//cdn.bidfluence.com/forge.js'; - - $$PREBID_GLOBAL$$.bfPbjsCB = function (bfr) { - var bidRequest = utils.getBidRequest(bfr.cbID); - var bidObject = null; - if (bfr.cpm > 0) { - bidObject = bidfactory.createBid(1, bidRequest); - bidObject.bidderCode = 'bidfluence'; - bidObject.cpm = bfr.cpm; - bidObject.ad = bfr.ad; - bidObject.width = bfr.width; - bidObject.height = bfr.height; - } else { - bidObject = bidfactory.createBid(2, bidRequest); - bidObject.bidderCode = 'bidfluence'; - } - - bidmanager.addBidResponse(bfr.placementCode, bidObject); - }; - - function _callBids(params) { - var bfbids = params.bids || []; - for (var i = 0; i < bfbids.length; i++) { - var bid = bfbids[i]; - call(bid); - } - } - function call(bid) { - var adunitId = utils.getBidIdParameter('adunitId', bid.params); - var publisherId = utils.getBidIdParameter('pubId', bid.params); - var reservePrice = utils.getBidIdParameter('reservePrice', bid.params); - var pbjsBfobj = { - placementCode: bid.placementCode, - cbID: bid.bidId - }; - - var cb = function () { - /* globals FORGE */ - FORGE.init([adunitId, publisherId, pbjsBfobj, reservePrice]); - }; - - adloader.loadScript(scriptUrl, cb); - } - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new BidfluenceAdapter(), 'bidfluence'); - -module.exports = BidfluenceAdapter; diff --git a/modules/brightcomBidAdapter.js b/modules/brightcomBidAdapter.js deleted file mode 100644 index f1256edeab8..00000000000 --- a/modules/brightcomBidAdapter.js +++ /dev/null @@ -1,205 +0,0 @@ -var CONSTANTS = require('src/constants.json'); -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); - -/** - * Adapter for requesting bids from Brightcom - */ -var BrightcomAdapter = function BrightcomAdapter() { - // Set Brightcom Bidder URL - var brightcomUrl = 'hb.iselephant.com/auc/ortb'; - - // Define the bidder code - var brightcomBidderCode = 'brightcom'; - - // Define the callback function - var brightcomCallbackFunction = 'window.$$PREBID_GLOBAL$$=window.$$PREBID_GLOBAL$$||window.parent.$$PREBID_GLOBAL$$||window.top.$$PREBID_GLOBAL$$;window.$$PREBID_GLOBAL$$.brightcomResponse'; - - // Manage the requested and received ad units' codes, to know which are invalid (didn't return) - const reqAdUnitsCode = []; - const resAdUnitsCode = []; - - function _callBids(params) { - var bidRequests = params.bids || []; - - // Get page data - var siteDomain = window.location.host; - var sitePage = window.location.href; - - // Prepare impressions object - var brightcomImps = []; - - // Prepare a variable for publisher id - var pubId = ''; - - // Go through the requests and build array of impressions - utils._each(bidRequests, function(bid) { - // Get impression details - var tagId = utils.getBidIdParameter('tagId', bid.params); - var ref = utils.getBidIdParameter('ref', bid.params); - var adWidth = 0; - var adHeight = 0; - - // If no publisher id is set, use the current - if (pubId === '') { - // Get the current publisher id (if it doesn't exist, it'll return '') - pubId = utils.getBidIdParameter('pubId', bid.params); - } - - // Brightcom supports only 1 size per impression - // Check if the array contains 1 size or array of sizes - if (bid.sizes.length === 2 && typeof bid.sizes[0] === 'number' && typeof bid.sizes[1] === 'number') { - // The array contains 1 size (the items are the values) - adWidth = bid.sizes[0]; - adHeight = bid.sizes[1]; - } else { - // The array contains array of sizes, use the first size - adWidth = bid.sizes[0][0]; - adHeight = bid.sizes[0][1]; - } - - // Build the impression - var imp = { - id: utils.getUniqueIdentifierStr(), - banner: { - w: adWidth, - h: adHeight - }, - tagid: tagId - }; - - // If ref exists, create it (in the "ext" object) - if (ref !== '') { - imp.ext = { - refoverride: ref - }; - } - - // Add current impression to collection - brightcomImps.push(imp); - // Add mapping to current bid via impression id - // bidmanager.pbCallbackMap[imp.id] = bid; - - // Add current ad unit's code to tracking - reqAdUnitsCode.push(bid.placementCode); - }); - - // Build the bid request - var brightcomBidReq = { - id: utils.getUniqueIdentifierStr(), - imp: brightcomImps, - site: { - publisher: { - id: pubId - }, - domain: siteDomain, - page: sitePage - } - }; - - // Add timeout data, if available - var PREBID_TIMEOUT = PREBID_TIMEOUT || 0; - var curTimeout = PREBID_TIMEOUT; - if (curTimeout > 0) { - brightcomBidReq.tmax = curTimeout; - } - - // Define the bid request call URL - var bidRequestCallUrl = 'https://' + brightcomUrl + - '?callback=' + encodeURIComponent(brightcomCallbackFunction) + - '&request=' + encodeURIComponent(JSON.stringify(brightcomBidReq)); - - // Add the call to get the bid - adloader.loadScript(bidRequestCallUrl); - } - - // expose the callback to the global object: - $$PREBID_GLOBAL$$.brightcomResponse = function(brightcomResponseObj) { - var bid = {}; - - // Make sure response is valid - if ( - (brightcomResponseObj) && (brightcomResponseObj.id) && - (brightcomResponseObj.seatbid) && (brightcomResponseObj.seatbid.length !== 0) && - (brightcomResponseObj.seatbid[0].bid) && (brightcomResponseObj.seatbid[0].bid.length !== 0) - ) { - // Go through the received bids - brightcomResponseObj.seatbid[0].bid.forEach(function(curBid) { - // Get the bid request data - var bidRequest = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'brightcom').bids[0]; // this assumes a single request only - - // Make sure the bid exists - if (bidRequest) { - var placementCode = bidRequest.placementCode; - bidRequest.status = CONSTANTS.STATUS.GOOD; - - curBid.placementCode = placementCode; - curBid.size = bidRequest.sizes; - - // Get the creative - var responseCreative = curBid.adm; - // Build the NURL element - var responseNurl = ''; - // Build the ad to display: - var responseAd = decodeURIComponent(responseCreative + responseNurl); - - // Create a valid bid - bid = bidfactory.createBid(1); - - // Set the bid data - bid.creative_id = curBid.Id; - bid.bidderCode = brightcomBidderCode; - bid.cpm = parseFloat(curBid.price); - - // Brightcom tag is in `; - } - } else { - // width and height are only relevant with non-native requests. - // native requests will always return a 2x2 zone size. - bidObject.width = bidResponse.width; - bidObject.height = bidResponse.height; - bidObject.ad = bidResponse.creative; - } - } else { - bidObject = _invalidBidResponse(); - } - return bidObject; - } - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new CriteoAdapter(), 'criteo'); - -module.exports = CriteoAdapter; diff --git a/modules/currency.js b/modules/currency.js index 1d0286ed569..0c2b87a6bc3 100644 --- a/modules/currency.js +++ b/modules/currency.js @@ -2,7 +2,6 @@ import bidfactory from 'src/bidfactory'; import { STATUS } from 'src/constants'; import { ajax } from 'src/ajax'; import * as utils from 'src/utils'; -import bidmanager from 'src/bidmanager'; import { config } from 'src/config'; const DEFAULT_CURRENCY_RATE_URL = 'http://currency.prebid.org/latest.json'; @@ -13,9 +12,6 @@ var conversionCache = {}; var currencyRatesLoaded = false; var adServerCurrency = 'USD'; -// Used as reference to the original bidmanager.addBidResponse -var originalBidResponse; - export var currencySupportEnabled = false; export var currencyRates = {}; var bidderCurrencyDefault = {}; @@ -81,13 +77,6 @@ function initCurrency(url) { conversionCache = {}; currencySupportEnabled = true; - if (!originalBidResponse) { - utils.logInfo('Installing addBidResponse decorator for currency module', arguments); - - originalBidResponse = bidmanager.addBidResponse; - bidmanager.addBidResponse = addBidResponseDecorator(bidmanager.addBidResponse); - } - if (!currencyRates.conversions) { ajax(url, function (response) { try { @@ -103,13 +92,6 @@ function initCurrency(url) { } function resetCurrency() { - if (originalBidResponse) { - utils.logInfo('Uninstalling addBidResponse decorator for currency module', arguments); - - bidmanager.addBidResponse = originalBidResponse; - originalBidResponse = undefined; - } - adServerCurrency = 'USD'; conversionCache = {}; currencySupportEnabled = false; diff --git a/modules/districtmDMXBidAdapter.js b/modules/districtmDMXBidAdapter.js deleted file mode 100644 index 1eed5f2150e..00000000000 --- a/modules/districtmDMXBidAdapter.js +++ /dev/null @@ -1,56 +0,0 @@ -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adLoader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); - -var DistrictmAdaptor = function districtmAdaptor() { - let districtmUrl = window.location.protocol + '//prebid.districtm.ca/lib.js'; - this.callBids = params => { - if (!window.hb_dmx_res) { - adLoader.loadScript(districtmUrl, () => { - this.sendBids(params); - }); - } else { - this.sendBids(params); - } - return params; - }; - - this.handlerRes = function(response, bidObject) { - let bid; - if (parseFloat(response.result.cpm) > 0) { - bid = bidfactory.createBid(1, bidObject); - bid.bidderCode = bidObject.bidder; - bid.cpm = response.result.cpm; - bid.width = response.result.width; - bid.height = response.result.height; - bid.ad = response.result.banner; - bidmanager.addBidResponse(bidObject.placementCode, bid); - } else { - bid = bidfactory.createBid(2, bidObject); - bid.bidderCode = bidObject.bidder; - bidmanager.addBidResponse(bidObject.placementCode, bid); - } - - return bid; - }; - - this.sendBids = function(params) { - var bids = params.bids; - for (var i = 0; i < bids.length; i++) { - bids[i].params.sizes = window.hb_dmx_res.auction.fixSize(bids[i].sizes); - } - window.hb_dmx_res.auction.run(window.hb_dmx_res.ssp, bids, this.handlerRes); - return bids; - }; - - return { - callBids: this.callBids, - sendBids: this.sendBids, - handlerRes: this.handlerRes - }; -}; - -adaptermanager.registerBidAdapter(new DistrictmAdaptor(), 'districtmDMX'); - -module.exports = DistrictmAdaptor; diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js deleted file mode 100644 index 9c09fd3b782..00000000000 --- a/modules/eplanningBidAdapter.js +++ /dev/null @@ -1,310 +0,0 @@ -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adaptermanager = require('src/adaptermanager'); - -function EPlanningAdapter() { - (function() { - const win = window; - const doc = win.document; - const pbjsVar = win.$$PREBID_GLOBAL$$; - const _global = {}; - const _default = { 'sv': 'ads.us.e-planning.net', 't': 0 }; - var rnd; - const FILE = 'file'; - const CALLBACK_FUNCTION = 'hbpb.rH'; - const NULL_SIZE = '1x1'; - const _csRequested = []; - const PROTO = location.protocol === 'https:' ? 'https:' : 'http:'; - const ISV = 'aklc.img.e-planning.net'; - function Hbpb() { - var slots = (function() { - var _data = []; - function Slot(slotId) { - var data = _data[slotId]; - function hasAds() { - return _data[slotId].ads.length; - } - function getSizes() { - return data.sizes; - } - function getSizesString() { - const s = []; - var i; - const sizes = getSizes(); - if (sizes && sizes.length) { - if (typeof sizes[0] === 'object') { - for (i = 0; i < sizes.length; i++) { - s.push(sizes[i][0] + 'x' + sizes[i][1]); - } - } else { - s.push(sizes[0] + 'x' + sizes[1]); - } - } else { - return NULL_SIZE; - } - return s.join(','); - } - return { - getPlacementCode: function() { - return data.placementCode; - }, - getString: function() { - return this.getPlacementCode() + ':' + getSizesString(); - }, - addAd: function(ad) { - _data[slotId].ads.push(ad); - }, - getFormatedResponse: function() { - var ad; - const that = this; - if (hasAds()) { - ad = data.ads[0]; - return { - 'placementCode': that.getPlacementCode(), - 'ad': { - 'ad': ad.adm, - 'cpm': ad.pr, - 'width': ad.size.w, - 'height': ad.size.h - } - }; - } else { - return { 'placementCode': that.getPlacementCode() }; - } - } - }; - } - function findAll() { - var i = 0; - const r = []; - for (i = 0; i < _data.length; i++) { - r.push(new Slot(i)); - } - return r; - } - return { - add: function(slot) { - slot.ads = []; - _data.push(slot); - }, - get: function(slotId) { - return new Slot(slotId); - }, - getString: function() { - const _slots = []; - var i; - var slot; - for (i = 0; i < _data.length; i++) { - slot = this.get(i); - _slots.push(slot.getString()); - } - return _slots.join('+'); - }, - findByPlacementCode: function(placementCode) { - var i; - const _slots = findAll(); - for (i = 0; i < _slots.length; i++) { - if (_slots[i].getPlacementCode() === placementCode) { - return _slots[i]; - } - } - }, - getFormatedResponse: function() { - const _slots = findAll(); - var i; - const r = []; - for (i = 0; i < _slots.length; i++) { - r.push(_slots[i].getFormatedResponse()); - } - return { - 'bids': r - }; - } - }; - })(); - function call(params) { - var i; - const bids = params.bids; - for (i = 0; i < bids.length; i++) { - slots.add({ - _raw: bids[i], - placementCode: bids[i].placementCode, - sizes: bids[i].sizes - }); - setGlobalParam('sv', bids[i]); - setGlobalParam('ci', bids[i]); - setGlobalParam('t', bids[i]); - } - doRequest(); - } - function setGlobalParam(param, bid) { - if (!_global[param]) { - if (bid && bid.params && bid.params[param]) { - _global[param] = bid.params[param]; - } - } - } - function getGlobalParam(param) { - return (_global[param] || _default[param]); - } - function getRandom() { - if (!rnd) { - rnd = Math.random(); - } - return rnd; - } - function getDocURL() { - return escape(win.location.href || FILE); - } - function getReferrerURL() { - return doc.referrer; - } - function getCallbackFunction() { - return CALLBACK_FUNCTION; - } - function doRequest() { - const clienteId = getGlobalParam('ci'); - var url; - const dfpClienteId = '1'; - const sec = 'ROS'; - const params = []; - const t = getGlobalParam('t'); - if (clienteId && !t) { - url = PROTO + '//' + getGlobalParam('sv') + '/hb/1/' + clienteId + '/' + dfpClienteId + '/' + (win.location.hostname || FILE) + '/' + sec + '?'; - params.push('rnd=' + getRandom()); - params.push('e=' + slots.getString()); - if (getDocURL()) { - params.push('ur=' + getDocURL()); - } - if (getReferrerURL()) { - params.push('fr=' + getReferrerURL()); - } - params.push('cb=' + getCallbackFunction()); - params.push('r=pbjs'); - url += params.join('&'); - load(url); - } else if (t) { - url = PROTO + '//' + ISV + '/layers/t_pbjs_' + t + '.js'; - load(url); - } - } - function load(url) { - var script = doc.createElement('script'); - script.src = url; - doc.body.appendChild(script); - } - function callback(response) { - if (pbjsVar && pbjsVar.processEPlanningResponse && typeof pbjsVar.processEPlanningResponse === 'function') { - pbjsVar.processEPlanningResponse(response); - } - } - function syncUsers(cs) { - var i, e, d; - for (i = 0; i < cs.length; i++) { - if (typeof cs[i] === 'string' && _csRequested.indexOf(cs[i]) === -1) { - (new Image()).src = cs[i]; - _csRequested.push(cs[i]); - } else if (typeof cs[i] === 'object' && _csRequested.indexOf(cs[i].u) === -1) { - if (cs[i].j) { - e = doc.createElement('script'); - e.src = cs[i].u; - } else if (cs[i].ifr) { - e = doc.createElement('iframe'); - e.src = cs[i].u; - e.style.width = e.style.height = '1px'; - e.display = 'none'; - } - if (cs[i].data) { - for (d in cs[i].data) { - if (cs[i].data.hasOwnProperty(d)) { - e.setAttribute('data-' + d, cs[i].data[d]); - } - } - } - doc.body.appendChild(e); - _csRequested.push(cs[i].u); - } - } - } - function rH(response) { - var slot, i, o; - if (response && response.sp && response.sp.length) { - for (i = 0; i < response.sp.length; i++) { - if (response.sp[i].a) { - slot = slots.findByPlacementCode(response.sp[i].k); - if (slot) { - for (o = 0; o < response.sp[i].a.length; o++) { - slot.addAd({ - 'adm': response.sp[i].a[o].adm, - 'pr': response.sp[i].a[o].pr, - 'size': { - 'w': response.sp[i].a[o].w, - 'h': response.sp[i].a[o].h - } - }); - } - } - } - } - callback(slots.getFormatedResponse()); - } - if (response && response.cs && response.cs.length) { - syncUsers(response.cs); - } - } - return { - call: function(params) { - return call(params); - }, - rH: function(response) { - return rH(response); - } - }; - } - win.hbpb = win.hbpb || new Hbpb(); - })(); - - window.$$PREBID_GLOBAL$$ = window.$$PREBID_GLOBAL$$ || {}; - window.$$PREBID_GLOBAL$$.processEPlanningResponse = function(response) { - var bids, bidObject, i; - if (response) { - bids = response.bids; - for (i = 0; i < bids.length; i++) { - if (bids[i].ad) { - bidObject = getBidObject(bids[i]); - bidmanager.addBidResponse(bids[i].placementCode, bidObject); - } else { - bidObject = bidfactory.createBid(2); - bidObject.bidderCode = 'eplanning'; - bidmanager.addBidResponse(bids[i].placementCode, bidObject); - } - } - } - }; - - function getBidObject(bid) { - const bidObject = bidfactory.createBid(1); - var i; - bidObject.bidderCode = 'eplanning'; - for (i in bid.ad) { - if (bid.ad.hasOwnProperty(i)) { - bidObject[i] = bid.ad[i]; - } - } - return bidObject; - } - - function _callBids(params) { - if (window.hbpb) { - window.hbpb.call(params); - } - } - - return { - callBids: _callBids - }; -} - -adaptermanager.registerBidAdapter(new EPlanningAdapter(), 'eplanning'); - -module.exports = EPlanningAdapter; diff --git a/modules/essensBidAdapter.js b/modules/essensBidAdapter.js deleted file mode 100644 index 1b4df4d1685..00000000000 --- a/modules/essensBidAdapter.js +++ /dev/null @@ -1,170 +0,0 @@ -const CONSTANTS = require('src/constants.json') -const utils = require('src/utils.js') -const bidfactory = require('src/bidfactory.js') -const bidmanager = require('src/bidmanager.js') -const adloader = require('src/adloader') -const Adapter = require('src/adapter.js').default -const adaptermanager = require('src/adaptermanager') - -// Essens Prebid Adapter -function EssensAdapter () { - let baseAdapter = new Adapter('essens') - - const ENDPOINT = 'bid.essrtb.com/bid/prebid_call' - - let receivedBidRequests = {} - - baseAdapter.callBids = function (bidRequest) { - if (!bidRequest) { - utils.logError('empty bid request received') - return - } - receivedBidRequests = bidRequest - - const bids = bidRequest.bids || [] - - const essensBids = bids - .filter(bid => isPlacementBidComplete(bid)) - .map(bid => { - let essensBid = {} - essensBid.impressionId = bid.bidId - essensBid.sizes = utils.parseSizesInput(bid.sizes) - essensBid.placementId = bid.params.placementId - - if (bid.params.dealId) { - essensBid.deal = bid.params.dealId - } - - if (bid.params.floorPrice) { - essensBid.floorPrice = bid.params.floorPrice - } - - return essensBid - }) - - const bidderRequestId = bidRequest.bidderRequestId - const cur = ['USD'] - const urlParam = utils.getTopWindowUrl() - const uaParam = getUa() - - if (!utils.isEmpty(essensBids)) { - const payloadJson = {bidderRequestId: bidderRequestId, cur: cur, url: urlParam, ua: uaParam, imp: essensBids} - - const scriptUrl = '//' + ENDPOINT + '?callback=$$PREBID_GLOBAL$$.essensResponseHandler' + - '&bid=' + encodeURIComponent(JSON.stringify(payloadJson)) - adloader.loadScript(scriptUrl) - } else { - sendEmptyResponseForAllPlacement() - } - - function isPlacementBidComplete (bid) { - if (bid.bidId && bid.params && bid.params.placementId) { - return true - } else { - utils.logError('bid requires missing essential params for essens') - } - } - - function getUa () { - return window.navigator.userAgent - } - } - - function sendEmptyResponseForAllPlacement () { - if (receivedBidRequests && receivedBidRequests.bids) { - receivedBidRequests.bids.forEach(registerEmptyResponse) - } - } - - function registerEmptyResponse (bidRequest) { - const bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest) - bid.bidderCode = 'essens' - bidmanager.addBidResponse(bidRequest.placementCode, bid) - } - - $$PREBID_GLOBAL$$.essensResponseHandler = function (essensResponse) { - utils.logInfo('received bid request from Essens') - if (!isValidResponse(essensResponse)) { - sendEmptyResponseForAllPlacement() - return - } - - registerBids(essensResponse) - - function isValidResponse (essensResponse) { - return !!(essensResponse && essensResponse.id && essensResponse.seatbid) - } - - function registerBids (essensResponses) { - const requestHasResponse = [] - - if (essensResponses.seatbid.length > 0) { - essensResponses.seatbid.filter(isValidSeat).forEach( - seat => seat.bid.forEach(sendResponse)) - } - - receivedBidRequests.bids.filter(request => !hasResponse(request)) - .forEach(registerEmptyResponse) - - function sendResponse (bidCandidate) { - const bidRequest = getBidRequest(bidCandidate.impid) - - const bidsToBeRegister = getBid(bidRequest, bidCandidate) - - if (bidsToBeRegister) { - requestHasResponse.push(bidRequest) - bidmanager.addBidResponse(bidRequest.placementCode, bidsToBeRegister) - } - } - - function hasResponse (request) { - return utils.contains(requestHasResponse, request) - } - - function isValidSeat (seatbid) { - return ((seatbid.bid && seatbid.bid.length !== 0)) - } - - function getBidRequest (id) { - return receivedBidRequests.bids.find(bid => bid.bidId === id) - } - } - - function getBid (pbBidReq, bidCandidate) { - if (!validBid(bidCandidate)) { - return - } - const bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD, pbBidReq) - - bid.creative_id = bidCandidate.crid - bid.adUrl = bidCandidate.ext.adUrl - bid.bidderCode = 'essens' - bid.cpm = parseFloat(bidCandidate.price) - bid.width = parseInt(bidCandidate.w) - bid.height = parseInt(bidCandidate.h) - - if (bidCandidate.dealid) { - bid.dealId = bidCandidate.dealid - } - return bid - } - - function validBid (bid) { - return !!((bid.price && - bid.crid && bid.ext && bid.ext.adUrl && - bid.w && - bid.h && - bid.impid)) - } - } - - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - getBidderCode: baseAdapter.getBidderCode - }) -} - -adaptermanager.registerBidAdapter(new EssensAdapter(), 'essens') - -module.exports = EssensAdapter diff --git a/modules/featureforwardBidAdapter.js b/modules/featureforwardBidAdapter.js deleted file mode 100644 index 34d7dddba49..00000000000 --- a/modules/featureforwardBidAdapter.js +++ /dev/null @@ -1,92 +0,0 @@ -import {createBid} from 'src/bidfactory'; -import {addBidResponse} from 'src/bidmanager'; -import {registerBidAdapter} from 'src/adaptermanager'; -import {logError, getTopWindowLocation} from 'src/utils'; -import {ajax} from 'src/ajax'; -import {STATUS} from 'src/constants'; - -function FeatureForwardAdapter() { - const bidUrl = window.location.protocol + '//prmbdr.featureforward.com/newbidder/bidder1_prm.php?'; - const ajaxOptions = { - method: 'POST', - withCredentials: true, - contentType: 'text/plain' - }; - - function _callBids(bidderRequest) { - var i = 0; - bidderRequest.bids.forEach(bidRequest => { - try { - while (bidRequest.sizes[i] !== undefined) { - var params = Object.assign({}, environment(), bidRequest.params, {'size': bidRequest.sizes[i]}); - var postRequest = JSON.stringify(params); - var url = bidUrl; - i++; - ajax(url, (bidResponse) => { - bidResponseAvailable(bidRequest, bidResponse); - }, postRequest, ajaxOptions); - } - } catch (e) { - // register passback on any exceptions while attempting to fetch response. - logError('featureforward.requestBid', 'ERROR', e); - bidResponseAvailable(bidRequest); - } - }); - } - - function environment() { - return { - ca: 'BID', - 'if': 0, - url: getTopWindowLocation().href, - refurl: referrer(), - ew: document.documentElement.clientWidth, - eh: document.documentElement.clientHeight, - ln: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage) - }; - } - - function referrer() { - try { - return window.top.document.referrer; - } catch (e) { - return document.referrer; - } - } - - function bidResponseAvailable(bidRequest, rawResponse) { - if (rawResponse) { - var bidResponse = parse(rawResponse); - if (bidResponse) { - var bid = createBid(STATUS.GOOD, bidRequest); - bid.bidderCode = bidRequest.bidder; - bid.cpm = bidResponse.bidCpm; - bid.ad = bidResponse.html; - bid.width = bidResponse.width; - bid.height = bidResponse.height; - addBidResponse(bidRequest.placementCode, bid); - return; - } - } - var passback = createBid(STATUS.NO_BID, bidRequest); - passback.bidderCode = bidRequest.bidder; - addBidResponse(bidRequest.placementCode, passback); - } - - function parse(rawResponse) { - try { - return JSON.parse(rawResponse); - } catch (ex) { - logError('featureforward.safeParse', 'ERROR', ex); - return null; - } - } - - return { - callBids: _callBids - }; -} - -registerBidAdapter(new FeatureForwardAdapter(), 'featureforward'); - -module.exports = FeatureForwardAdapter; diff --git a/modules/fidelityBidAdapter.js b/modules/fidelityBidAdapter.js deleted file mode 100644 index 73ee9d44ddd..00000000000 --- a/modules/fidelityBidAdapter.js +++ /dev/null @@ -1,102 +0,0 @@ -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); -var STATUS = require('src/constants').STATUS; -var adaptermanager = require('src/adaptermanager'); - -var FidelityAdapter = function FidelityAdapter() { - var FIDELITY_BIDDER_NAME = 'fidelity'; - var FIDELITY_SERVER_NAME = 'x.fidelity-media.com'; - - function _callBids(params) { - var bids = params.bids || []; - bids.forEach(function (currentBid) { - var server = currentBid.params.server || FIDELITY_SERVER_NAME; - var m3_u = window.location.protocol + '//' + server + '/delivery/hb.php?'; - m3_u += 'callback=window.$$PREBID_GLOBAL$$.fidelityResponse'; - m3_u += '&requestid=' + utils.getUniqueIdentifierStr(); - m3_u += '&impid=' + currentBid.bidId; - m3_u += '&zoneid=' + currentBid.params.zoneid; - m3_u += '&cb=' + Math.floor(Math.random() * 99999999999); - m3_u += document.charset ? '&charset=' + document.charset : (document.characterSet ? '&charset=' + document.characterSet : ''); - - var loc; - try { - loc = window.top !== window ? document.referrer : window.location.href; - } catch (e) { - loc = document.referrer; - } - loc = currentBid.params.loc || loc; - m3_u += '&loc=' + encodeURIComponent(loc); - - var subid = currentBid.params.subid || 'hb'; - m3_u += '&subid=' + subid; - if (document.referrer) m3_u += '&referer=' + encodeURIComponent(document.referrer); - if (currentBid.params.click) m3_u += '&ct0=' + encodeURIComponent(currentBid.params.click); - m3_u += '&flashver=' + encodeURIComponent(getFlashVersion()); - - adloader.loadScript(m3_u); - }); - } - - function getFlashVersion() { - var plugins, plugin, result; - - if (navigator.plugins && navigator.plugins.length > 0) { - plugins = navigator.plugins; - for (var i = 0; i < plugins.length && !result; i++) { - plugin = plugins[i]; - if (plugin.name.indexOf('Shockwave Flash') > -1) { - result = plugin.description.split('Shockwave Flash ')[1]; - } - } - } - return result || ''; - } - - function addBlankBidResponses(placementsWithBidsBack) { - var allFidelityBidRequests = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === FIDELITY_BIDDER_NAME); - - if (allFidelityBidRequests && allFidelityBidRequests.bids) { - utils._each(allFidelityBidRequests.bids, function (fidelityBid) { - if (!utils.contains(placementsWithBidsBack, fidelityBid.placementCode)) { - // Add a no-bid response for this placement. - var bid = bidfactory.createBid(STATUS.NO_BID, fidelityBid); - bid.bidderCode = FIDELITY_BIDDER_NAME; - bidmanager.addBidResponse(fidelityBid.placementCode, bid); - } - }); - } - } - - $$PREBID_GLOBAL$$.fidelityResponse = function(responseObj) { - if (!responseObj || !responseObj.seatbid || responseObj.seatbid.length === 0 || !responseObj.seatbid[0].bid || responseObj.seatbid[0].bid.length === 0) { - addBlankBidResponses([]); - return; - } - - var bid = responseObj.seatbid[0].bid[0]; - var status = bid.adm ? STATUS.GOOD : STATUS.NO_BID; - var requestObj = utils.getBidRequest(bid.impid); - - var bidResponse = bidfactory.createBid(status); - bidResponse.bidderCode = FIDELITY_BIDDER_NAME; - if (status === STATUS.GOOD) { - bidResponse.cpm = parseFloat(bid.price); - bidResponse.ad = bid.adm; - bidResponse.width = parseInt(bid.width); - bidResponse.height = parseInt(bid.height); - } - var placementCode = requestObj && requestObj.placementCode; - bidmanager.addBidResponse(placementCode, bidResponse); - }; - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new FidelityAdapter(), 'fidelity'); - -module.exports = FidelityAdapter; diff --git a/modules/getintentBidAdapter.js b/modules/getintentBidAdapter.js deleted file mode 100644 index 72f1c1a0073..00000000000 --- a/modules/getintentBidAdapter.js +++ /dev/null @@ -1,78 +0,0 @@ -import { STATUS } from 'src/constants'; -import adaptermanager from 'src/adaptermanager'; - -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); - -var GetIntentAdapter = function GetIntentAdapter() { - var headerBiddingStaticJS = window.location.protocol + '//cdn.adhigh.net/adserver/hb.js'; - - function _callBids(params) { - if (typeof window.gi_hb === 'undefined') { - adloader.loadScript(headerBiddingStaticJS, function() { - bid(params); - }, true); - } else { - bid(params); - } - } - - function addOptional(params, request, props) { - for (var i = 0; i < props.length; i++) { - if (params.hasOwnProperty(props[i])) { - request[props[i]] = params[props[i]]; - } - } - } - - function bid(params) { - var bids = params.bids || []; - for (var i = 0; i < bids.length; i++) { - var bidRequest = bids[i]; - var request = { - pid: bidRequest.params.pid, // required - tid: bidRequest.params.tid, // required - known: bidRequest.params.known || 1, - is_video: bidRequest.mediaType === 'video', - video: bidRequest.params.video || {}, - size: bidRequest.sizes[0].join('x'), - }; - addOptional(bidRequest.params, request, ['cur', 'floor']); - (function (r, br) { - window.gi_hb.makeBid(r, function(bidResponse) { - if (bidResponse.no_bid === 1) { - var nobid = bidfactory.createBid(STATUS.NO_BID); - nobid.bidderCode = br.bidder; - bidmanager.addBidResponse(br.placementCode, nobid); - } else { - var bid = bidfactory.createBid(STATUS.GOOD); - var size = bidResponse.size.split('x'); - bid.bidderCode = br.bidder; - bid.cpm = bidResponse.cpm; - bid.width = size[0]; - bid.height = size[1]; - if (br.mediaType === 'video') { - bid.vastUrl = bidResponse.vast_url; - bid.descriptionUrl = bidResponse.vast_url; - bid.mediaType = 'video'; - } else { - bid.ad = bidResponse.ad; - } - bidmanager.addBidResponse(br.placementCode, bid); - } - }); - })(request, bidRequest); - } - } - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new GetIntentAdapter(), 'getintent', { - supportedMediaTypes: ['video'] -}); - -module.exports = GetIntentAdapter; diff --git a/modules/gumgumBidAdapter.js b/modules/gumgumBidAdapter.js deleted file mode 100644 index 17cc04c9752..00000000000 --- a/modules/gumgumBidAdapter.js +++ /dev/null @@ -1,176 +0,0 @@ -const bidfactory = require('src/bidfactory'); -const bidmanager = require('src/bidmanager'); -const utils = require('src/utils'); -const adloader = require('src/adloader'); -var adaptermanager = require('src/adaptermanager'); - -const BIDDER_CODE = 'gumgum'; -const CALLBACKS = {}; - -const GumgumAdapter = function GumgumAdapter() { - const bidEndpoint = `https://g2.gumgum.com/hbid/imp`; - - let topWindow; - let topScreen; - let pageViewId; - const requestCache = {}; - const throttleTable = {}; - const defaultThrottle = 3e4; - const dtCredentials = { member: 'YcXr87z2lpbB' }; - - try { - topWindow = global.top; - topScreen = topWindow.screen; - } catch (error) { - return utils.logError(error); - } - - function _getTimeStamp() { - return new Date().getTime(); - } - - function _getDigiTrustQueryParams() { - function getDigiTrustId () { - var digiTrustUser = (window.DigiTrust && window.DigiTrust.getUser) ? window.DigiTrust.getUser(dtCredentials) : {}; - return (digiTrustUser && digiTrustUser.success && digiTrustUser.identity) || ''; - }; - - let digiTrustId = getDigiTrustId(); - // Verify there is an ID and this user has not opted out - if (!digiTrustId || (digiTrustId.privacy && digiTrustId.privacy.optout)) { - return {}; - } - return { - 'dt': digiTrustId.id - }; - } - - function _callBids({ bids }) { - const browserParams = { - vw: topWindow.innerWidth, - vh: topWindow.innerHeight, - sw: topScreen.width, - sh: topScreen.height, - pu: topWindow.location.href, - ce: navigator.cookieEnabled, - dpr: topWindow.devicePixelRatio || 1 - }; - - utils._each(bids, bidRequest => { - const { bidId - , params = {} - , placementCode - } = bidRequest; - const timestamp = _getTimeStamp(); - const trackingId = params.inScreen; - const nativeId = params.native; - const slotId = params.inSlot; - const bid = { tmax: $$PREBID_GLOBAL$$.cbTimeout }; - - /* slot/native ads need the placement id */ - switch (true) { - case !!(params.inImage): bid.pi = 1; break; - case !!(params.inScreen): bid.pi = 2; break; - case !!(params.inSlot): bid.pi = 3; break; - case !!(params.native): bid.pi = 5; break; - default: return utils.logWarn( - `[GumGum] No product selected for the placement ${placementCode}` + - ', please check your implementation.' - ); - } - - /* throttle based on the latest request for this product */ - const productId = bid.pi; - const requestKey = productId + '|' + placementCode; - const throttle = throttleTable[productId]; - const latestRequest = requestCache[requestKey]; - if (latestRequest && throttle && (timestamp - latestRequest) < throttle) { - return utils.logWarn( - `[GumGum] The refreshes for "${placementCode}" with the params ` + - `${JSON.stringify(params)} should be at least ${throttle / 1e3}s apart.` - ); - } - /* update the last request */ - requestCache[requestKey] = timestamp; - - /* tracking id is required for in-image and in-screen */ - if (trackingId) bid.t = trackingId; - /* native ads require a native placement id */ - if (nativeId) bid.ni = nativeId; - /* slot ads require a slot id */ - if (slotId) bid.si = slotId; - - /* include the pageViewId, if any */ - if (pageViewId) bid.pv = pageViewId; - - const cachedBid = Object.assign({ - placementCode, - id: bidId - }, bid); - - const callback = { jsonp: `$$PREBID_GLOBAL$$.handleGumGumCB['${bidId}']` }; - CALLBACKS[bidId] = _handleGumGumResponse(cachedBid); - const query = Object.assign(callback, browserParams, bid, _getDigiTrustQueryParams()); - const bidCall = `${bidEndpoint}?${utils.parseQueryStringParameters(query)}`; - adloader.loadScript(bidCall); - }); - } - - const _handleGumGumResponse = cachedBidRequest => (bidResponse = {}) => { - const { pi: productId - } = cachedBidRequest; - const { ad = {} - , pag = {} - , thms: throttle - } = bidResponse; - /* cache the pageViewId */ - if (pag && pag.pvid) pageViewId = pag.pvid; - if (ad && ad.id) { - /* set the new throttle */ - throttleTable[productId] = throttle || defaultThrottle; - /* create the bid */ - const bid = bidfactory.createBid(1); - const { t: trackingId - } = pag; - bidResponse.request = cachedBidRequest; - const encodedResponse = encodeURIComponent(JSON.stringify(bidResponse)); - const gumgumAdLoader = ``; - Object.assign(bid, { - cpm: ad.price, - ad: gumgumAdLoader, - width: ad.width, - height: ad.height, - bidderCode: BIDDER_CODE - }); - bidmanager.addBidResponse(cachedBidRequest.placementCode, bid); - } else { - const noBid = bidfactory.createBid(2); - noBid.bidderCode = BIDDER_CODE; - bidmanager.addBidResponse(cachedBidRequest.placementCode, noBid); - } - delete CALLBACKS[cachedBidRequest.id]; - }; - - window.$$PREBID_GLOBAL$$.handleGumGumCB = CALLBACKS; - - return { - callBids: _callBids - }; -}; - -adaptermanager.registerBidAdapter(new GumgumAdapter(), 'gumgum'); - -module.exports = GumgumAdapter; diff --git a/modules/hiromediaBidAdapter.js b/modules/hiromediaBidAdapter.js deleted file mode 100644 index f99b3553dfc..00000000000 --- a/modules/hiromediaBidAdapter.js +++ /dev/null @@ -1,374 +0,0 @@ -/** - * Adapter for HIRO Media - * - * @module HiroMediaAdapter - * - * @requires src/ajax - * @requires src/bidfactory - * @requires src/bidmanager - * @requires src/constants - * @requires src/utils - */ -var Ajax = require('src/ajax'); -var bidfactory = require('src/bidfactory'); -var bidmanager = require('src/bidmanager'); -var utils = require('src/utils'); -var STATUS = require('src/constants').STATUS; -var adaptermanager = require('src/adaptermanager'); - -var HiroMediaAdapter = function HiroMediaAdapter() { - 'use strict'; - - /** - * Bidder code - * - * @memberof module:HiroMediaAdapter~ - * @constant {string} - * @private - */ - var BIDDER_CODE = 'hiromedia'; - - /** - * Adapter version - * - * @memberof module:HiroMediaAdapter~ - * @constant {number} - * @private - */ - var ADAPTER_VERSION = 3; - - /** - * Default bid param values - * - * @memberof module:HiroMediaAdapter~ - * @constant {array.document.location.protocol
- * The returned string is either http://
or https://
- * @returns {string}
- */
- getPageProtocol() {
- if (!this.pageProtocol) {
- this.pageProtocol = (utils.getTopWindowLocation().protocol === 'http:' ? 'http:' : 'https:');
- }
- return this.pageProtocol;
- },
-
- getEventUrl(evtName, extraDetails) {
- let eventsEndpoint = CONSTANTS.EVENTS_ENDPOINT_URL + '?table=' + ((evtName === this.errorEventName) ? 'mbwError' : 'mbwEvent');
- let queryStringParams = this.eventQueryStringParams(extraDetails);
- const appId = extraDetails && extraDetails.appId;
- let queryStringParamsWithAID = `${queryStringParams}&aid=${appId}_${evtName}_other&evtName=${evtName}`;
- return eventsEndpoint + '&' + queryStringParamsWithAID;
- },
-
- /**
- * Reports an event to IA's servers.
- * @param {string} evtName - event name as string.
- * @param {object} extraDetails - e.g., a JS exception JSON object.
- * @param shouldSendOnlyToNewEndpoint
- */
- reportEvent(evtName, extraDetails) {
- const url = this.getEventUrl(evtName, extraDetails);
- this.createTrackingPixel(url);
- },
- defaults: Helpers.defaultsQsParams,
-
- /**
- * Ia Event Reporting Query String Parameters, not including App Id.
- * @param {object} extraDetails - e.g., a JS exception JSON object.
- * @return {string} IA event contcatenated queryString parameters.
- */
- eventQueryStringParams(extraDetails) {
- const toQS = Object.assign({}, this.defaults, {realAppId: extraDetails && extraDetails.appId, timestamp: Date.now()});
- return formatQS(toQS);
- },
-
- /**
- * Creates a tracking pixel by prepending the page's protocol to the URL sent as the param.
- * @param {string} urlWithoutProtocol - the URL to send the tracking pixel to, without the protocol as a prefix.
- */
- createTrackingPixel(urlWithoutProtocol) {
- Tracker.fire([this.getPageProtocol() + urlWithoutProtocol]);
- }
-};
-
-/**
- * Url generator - generates a request URL
- * @type {{defaultsParams: *, serverParamNameBySettingParamName: {referrer: string, keywords: string, appId: string, portal: string, age: string, gender: string, isSecured: (boolean|null)}, toServerParams: (function(*)), unwantedValues: *[], getUrlParams: (function(*=))}}
- */
-const Url = {
- defaultsParams: Object.assign({}, Helpers.defaultsQsParams, {f: CONSTANTS.DISPLAY_AD, fs: false, ref: iaRef}),
- serverParamNameBySettingParamName: {
- referrer: 'ref',
- keywords: 'k',
- appId: 'aid',
- portal: 'po',
- age: 'a',
- gender: 'g',
- },
- unwantedValues: ['', null, undefined],
-
- /**
- * Maps publisher params to server params
- * @param params: object {k:v}
- * @returns object {k:v}
- */
- toServerParams(params) {
- const serverParams = {};
- for (const paramName in params) {
- if (params.hasOwnProperty(paramName) && this.serverParamNameBySettingParamName.hasOwnProperty(paramName)) {
- serverParams[this.serverParamNameBySettingParamName[paramName]] = params[paramName];
- } else {
- serverParams[paramName] = params[paramName];
- }
- }
-
- serverParams.isSecured = Reporter.getPageProtocol() === 'https:' || null;
- return serverParams;
- },
-
- /**
- * Prepare querty string to ad server
- * @param params: object {k:v}
- * @returns : object {k:v}
- */
- getUrlParams(params) {
- const serverParams = this.toServerParams(params);
- const toQueryString = Object.assign({}, this.defaultsParams, serverParams);
- for (const paramName in toQueryString) {
- if (toQueryString.hasOwnProperty(paramName) && this.unwantedValues.indexOf(toQueryString[paramName]) !== -1) {
- delete toQueryString[paramName];
- }
- }
- toQueryString.fs = params.spotType === CONSTANTS.SPOT_TYPES.INTERSTITIAL;
-
- if (params.spotType === CONSTANTS.SPOT_TYPES.RECTANGLE) {
- toQueryString.rw = CONSTANTS.RECTANGLE_SIZE.W;
- toQueryString.rh = CONSTANTS.RECTANGLE_SIZE.H;
- }
-
- if (typeof $$PREBID_GLOBAL$$ !== 'undefined') {
- toQueryString.bco = $$PREBID_GLOBAL$$.cbTimeout || config.getConfig('bidderTimeout');
- }
-
- toQueryString.timestamp = Date.now();
- delete toQueryString.qa;
- return toQueryString;
- }
-};
-
-/**
- * Http helper to extract metadata
- * @type {{headers: *[], getBidHeaders: (function(*))}}
- */
-const Http = {
- headers: [
- CONSTANTS.RESPONSE_HEADERS_NAME.PRICING_VALUE,
- CONSTANTS.RESPONSE_HEADERS_NAME.AD_H,
- CONSTANTS.RESPONSE_HEADERS_NAME.AD_W
- ],
-
- /**
- * Extract headers data
- * @param xhr: XMLHttpRequest
- * @returns {}
- */
- getBidHeaders(xhr) {
- const headersData = {};
- this.headers.forEach(headerName => headersData[headerName] = xhr.getResponseHeader(headerName));
- return headersData;
- }
-};
-
-/**
- * InnerActiveAdapter for requesting bids
- * @class
- */
-class InnerActiveAdapter {
- constructor() {
- this.iaAdapter = new Adapter(CONSTANTS.ADAPTER_NAME);
- this.setBidderCode = this.iaAdapter.setBidderCode.bind(this);
-
- this.bidByBidId = {};
- }
-
- /**
- * validate if bid request is valid
- * @param adSettings: object
- * @returns {boolean}
- * @private
- */
- _isValidRequest(adSettings) {
- if (adSettings && adSettings.appId && adSettings.spotType) {
- return true;
- }
- utils.logError('bid requires appId');
- return false;
- }
-
- /**
- * Store the bids in a Map object (k: bidId, v: bid)to check later if won
- * @param bid
- * @returns bid object
- * @private
- */
- _storeBidRequestDetails(bid) {
- this.bidByBidId[bid.bidId] = bid;
- return bid;
- }
-
- /**
- * @param bidStatus: int ("STATUS": {"GOOD": 1,"NO_BID": 2})
- * @param bidResponse: object
- * @returns {type[]}
- * @private
- */
- _getBidDetails(bidStatus, bidResponse, bidId) {
- let bid = bidFactory.createBid(bidStatus, bidResponse);
- bid.code = CONSTANTS.ADAPTER_NAME;
- bid.bidderCode = bid.code;
- if (bidStatus === STATUS.GOOD) {
- bid = Object.assign(bid, bidResponse);
- this._setBidCpm(bid, bidId);
- }
- return bid;
- }
-
- _setBidCpm(bid, bidId) {
- const storedBid = this.bidByBidId[bidId];
- if (storedBid) {
- bid.cpm = (storedBid.params && storedBid.params.qa && storedBid.params.qa.cpm) || bid.cpm;
- bid.cpm = (bid.cpm !== null && !isNaN(bid.cpm)) ? parseFloat(bid.cpm) : 0.0;
- }
- }
-
- /**
- * Validate if response is valid
- * @param responseAsJson : object
- * @param headersData: {}
- * @returns {boolean}
- * @private
- */
- _isValidBidResponse(responseAsJson, headersData) {
- return (responseAsJson && responseAsJson.ad && responseAsJson.ad.html && headersData && headersData[CONSTANTS.RESPONSE_HEADERS_NAME.PRICING_VALUE] > 0);
- }
-
- /**
- * When response is received
- * @param response: string(json format)
- * @param xhr: XMLHttpRequest
- * @param bidId: string
- * @private
- */
- _onResponse(response, xhr, bidId) {
- const bid = this.bidByBidId[bidId];
- const [w, h] = bid.sizes[0];
- const size = {w, h};
- let responseAsJson;
- const headersData = Http.getBidHeaders(xhr);
- try {
- responseAsJson = JSON.parse(response);
- } catch (error) {
- utils.logError(error);
- }
-
- if (!this._isValidBidResponse(responseAsJson, headersData)) {
- let errorMessage = `response failed for ${CONSTANTS.ADAPTER_NAME} adapter`;
- utils.logError(errorMessage);
- const passback = responseAsJson && responseAsJson.config && responseAsJson.config.passback;
- if (passback) {
- Tracker.fire([passback]);
- }
- Reporter.reportEvent('HBPreBidNoAd', bid.params);
- return bidManager.addBidResponse(bid.placementCode, this._getBidDetails(STATUS.NO_BID));
- }
- const bidResponse = {
- cpm: headersData[CONSTANTS.RESPONSE_HEADERS_NAME.PRICING_VALUE] * 1000,
- width: parseFloat(headersData[CONSTANTS.RESPONSE_HEADERS_NAME.AD_W]) || size.w,
- ad: this._getAd(responseAsJson.ad.html, responseAsJson.config.tracking, bid.params),
- height: parseFloat(headersData[CONSTANTS.RESPONSE_HEADERS_NAME.AD_H]) || size.h
- };
- const auctionBid = this._getBidDetails(STATUS.GOOD, bidResponse, bidId);
- bid.adId = auctionBid.adId;
- this.bidByBidId[bidId] = bid;
- bidManager.addBidResponse(bid.placementCode, auctionBid);
- }
-
- /**
- * Returns the ad HTML template
- * @param adHtml: string {ad server creative}
- * @param tracking: object {impressions, clicks}
- * @param bidParams: object
- * @returns {string}: create template
- * @private
- */
- _getAd(adHtml, tracking, bidParams) {
- let impressionsHtml = '';
- if (tracking && Array.isArray(tracking.impressions)) {
- let impressions = tracking.impressions;
- impressions.push(Reporter.getEventUrl('HBPreBidImpression', bidParams, false));
- impressions.forEach(impression => impression && (impressionsHtml += utils.createTrackPixelHtml(impression)));
- }
- adHtml = impressionsHtml + adHtml.replace(/
-
-
-
-
-