diff --git a/src/adapters/adequant.js b/src/adapters/adequant.js index f01b0c4932f..c15dbf07d8e 100644 --- a/src/adapters/adequant.js +++ b/src/adapters/adequant.js @@ -33,18 +33,18 @@ module.exports = function() { 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); }); + adloader.loadScript(req_url_base+req_url.join('&'), function() { process_bids(replies, placements, bids); }); } - function process_bids(replies, placements) { + function process_bids(replies, placements, bids) { var placement_code, bid, adequant_creatives = window.adequant_creatives; if (adequant_creatives && adequant_creatives.seatbid) { for (var i=0; i bid.placementCode === placement_code).bidId; + bid = bidfactory.createBid(1, bidRequestId); bid.bidderCode = 'adequant'; bid.cpm = bid_response.price; bid.ad = bid_response.adm; @@ -55,8 +55,9 @@ module.exports = function() { } } for (placement_code in placements) { + const bidRequestId = bids.find(bid => bid.placementCode === placement_code).bidId; if (placements[placement_code]) { - bid = bidfactory.createBid(2); + bid = bidfactory.createBid(2, bidRequestId); bid.bidderCode = 'adequant'; bidmanager.addBidResponse(placement_code, bid); } diff --git a/src/adapters/adform.js b/src/adapters/adform.js index 001d084ab32..10ce3918886 100644 --- a/src/adapters/adform.js +++ b/src/adapters/adform.js @@ -67,7 +67,7 @@ function AdformAdapter() { if (adItem && adItem.response === 'banner' && verifySize(adItem, bid.sizes)) { - bidObject = bidfactory.createBid(1); + bidObject = bidfactory.createBid(1, bid.bidId); bidObject.bidderCode = bidder; bidObject.cpm = adItem.win_bid; bidObject.cur = adItem.win_cur; @@ -76,7 +76,7 @@ function AdformAdapter() { bidObject.height = adItem.height; bidmanager.addBidResponse(bid.placementCode, bidObject); } else { - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(2, bid.bidId); bidObject.bidderCode = bidder; bidmanager.addBidResponse(bid.placementCode, bidObject); } diff --git a/src/adapters/aol.js b/src/adapters/aol.js index c064ec114a2..9925d7512e4 100644 --- a/src/adapters/aol.js +++ b/src/adapters/aol.js @@ -73,7 +73,7 @@ var AolAdapter = function AolAdapter() { // clean up--we no longer need to store the bid delete bidsMap[context.alias]; - var bidResponse = bidfactory.createBid(1); + var bidResponse = bidfactory.createBid(1, bid.bidId); var ad = response.getCreative(); if (typeof response.getPixels() !== 'undefined') { ad += response.getPixels(); @@ -105,7 +105,7 @@ var AolAdapter = function AolAdapter() { // clean up--we no longer need to store the bid delete bidsMap[context.alias]; - var bidResponse = bidfactory.createBid(2); + var bidResponse = bidfactory.createBid(2, bid.bidId); bidResponse.bidderCode = ADTECH_BIDDER_NAME; bidResponse.reason = response.getNbr(); bidResponse.raw = response.getResponse(); diff --git a/src/adapters/appnexus.js b/src/adapters/appnexus.js index b052ae61e2c..e4acccc8dc6 100644 --- a/src/adapters/appnexus.js +++ b/src/adapters/appnexus.js @@ -1,4 +1,4 @@ -import { findBidderRequestByBidId } from '../utils.js'; +import { findBidRequest } from '../utils.js'; var CONSTANTS = require('../constants.json'); var utils = require('../utils.js'); @@ -13,7 +13,7 @@ AppNexusAdapter = function AppNexusAdapter() { baseAdapter.callBids = function (params) { params.bids.map(bid => { - const callbackId = bid.adId; + const callbackId = bid.bidId; adloader.loadScript(buildJPTCall(bid, callbackId)); }); }; @@ -139,7 +139,7 @@ AppNexusAdapter = function AppNexusAdapter() { var responseCPM; var id = jptResponseObj.callback_uid; var placementCode = ''; - var bidObj = findBidderRequestByBidId({ adId: id }); + var bidObj = findBidRequest({ bidId: id }); if (bidObj) { @@ -167,7 +167,7 @@ AppNexusAdapter = function AppNexusAdapter() { //store bid response //bid status is good (indicating 1) var adId = jptResponseObj.result.creative_id; - bid = bidfactory.createBid(1, adId); + bid = bidfactory.createBid(1, id); bid.creative_id = adId; bid.bidderCode = bidCode; bid.cpm = responseCPM; diff --git a/src/adapters/brightcom.js b/src/adapters/brightcom.js index ce1ad38f700..afa4d75da56 100644 --- a/src/adapters/brightcom.js +++ b/src/adapters/brightcom.js @@ -138,7 +138,7 @@ var BrightcomAdapter = function BrightcomAdapter() { brightcomResponseObj.seatbid[0].bid.forEach(function(curBid) { // Get the bid request data - const auction = findAuctionByBidderCode({ bidderCode: 'brightcom' }); + const auction = auction || pbjs.auctionManager.getSingleAuction(); var bidRequest = auction.getBidderRequests().find(bidSet => bidSet.bidderCode === 'brightcom').bids[0]; // this assumes a single request only // Make sure the bid exists diff --git a/src/adapters/nginad.js b/src/adapters/nginad.js index e5b82d328c9..5e56c13bfb0 100644 --- a/src/adapters/nginad.js +++ b/src/adapters/nginad.js @@ -1,3 +1,5 @@ +import { findBidderRequestByBidId } from '../utils'; + var CONSTANTS = require('../constants.json'); var utils = require('../utils.js'); var bidfactory = require('../bidfactory.js'); @@ -142,8 +144,7 @@ var NginAdAdapter = function NginAdAdapter() { var id = nginadBid.impid; // try to fetch the bid request we sent NginAd - var bidObj = auction.getBidderRequests().find(bidSet => bidSet.bidderCode === 'nginad').bids - .find(bid => bid.bidId === id); + var bidObj = findBidderRequestByBidId({ adId: id }); if (!bidObj) { return handleErrorResponse(nginadBid, defaultPlacementForBadBid); } diff --git a/src/adapters/pubmatic.js b/src/adapters/pubmatic.js index 4ae81941f72..8015ff39ecf 100644 --- a/src/adapters/pubmatic.js +++ b/src/adapters/pubmatic.js @@ -18,9 +18,9 @@ var PubmaticAdapter = function PubmaticAdapter() { bids = params.bids; for (var i = 0; i < bids.length; i++) { var bid = bids[i]; - //bidmanager.pbCallbackMap['' + bid.params.adSlot] = bid; _pm_pub_id = _pm_pub_id || bid.params.publisherId; _pm_optimize_adslots.push(bid.params.adSlot); + _createHandlePubmaticCallback(bid); } // Load pubmatic script in an iframe, because they call document.write @@ -73,57 +73,59 @@ var PubmaticAdapter = function PubmaticAdapter() { return content; } - pbjs.handlePubmaticCallback = function (response) { - var i; - var adUnit; - var adUnitInfo; - var bid; - var bidResponseMap = (response && response.bidDetailsMap) || {}; - var bidInfoMap = (response && response.progKeyValueMap) || {}; - var dimensions; - - for (i = 0; i < bids.length; i++) { - var adResponse; - bid = bids[i].params; - - adUnit = bidResponseMap[bid.adSlot] || {}; - - // adUnitInfo example: bidstatus=0;bid=0.0000;bidid=39620189@320x50;wdeal= - - // if using DFP GPT, the params string comes in the format: - // "bidstatus;1;bid;5.0000;bidid;hb_test@468x60;wdeal;" - // the code below detects and handles this. - if (bidInfoMap[bid.adSlot].indexOf('=') === -1) { - bidInfoMap[bid.adSlot] = bidInfoMap[bid.adSlot].replace(/([a-z]+);(.[^;]*)/ig, '$1=$2'); + function _createHandlePubmaticCallback(bidRequest) { + pbjs.handlePubmaticCallback = function (response) { + var i; + var adUnit; + var adUnitInfo; + var bid; + var bidResponseMap = (response && response.bidDetailsMap) || {}; + var bidInfoMap = (response && response.progKeyValueMap) || {}; + var dimensions; + + for (i = 0; i < bids.length; i++) { + var adResponse; + bid = bids[i].params; + + adUnit = bidResponseMap[bid.adSlot] || {}; + + // adUnitInfo example: bidstatus=0;bid=0.0000;bidid=39620189@320x50;wdeal= + + // if using DFP GPT, the params string comes in the format: + // "bidstatus;1;bid;5.0000;bidid;hb_test@468x60;wdeal;" + // the code below detects and handles this. + if (bidInfoMap[bid.adSlot].indexOf('=') === -1) { + bidInfoMap[bid.adSlot] = bidInfoMap[bid.adSlot].replace(/([a-z]+);(.[^;]*)/ig, '$1=$2'); + } + + adUnitInfo = (bidInfoMap[bid.adSlot] || '').split(';').reduce(function (result, pair) { + var parts = pair.split('='); + result[parts[0]] = parts[1]; + return result; + }, {}); + + if (adUnitInfo.bidstatus === '1') { + dimensions = adUnitInfo.bidid.split('@')[1].split('x'); + adResponse = bidfactory.createBid(1, bidRequest.bidId); + adResponse.bidderCode = 'pubmatic'; + adResponse.adSlot = bid.adSlot; + adResponse.cpm = Number(adUnitInfo.bid); + adResponse.ad = unescape(adUnit.creative_tag); // jshint ignore:line + adResponse.ad += utils.createTrackPixelHtml(decodeURIComponent(adUnit.tracking_url)); + adResponse.width = dimensions[0]; + adResponse.height = dimensions[1]; + adResponse.dealId = adUnitInfo.wdeal; + + bidmanager.addBidResponse(bids[i].placementCode, adResponse); + } else { + // Indicate an ad was not returned + adResponse = bidfactory.createBid(2); + adResponse.bidderCode = 'pubmatic'; + bidmanager.addBidResponse(bids[i].placementCode, adResponse); + } } - - adUnitInfo = (bidInfoMap[bid.adSlot] || '').split(';').reduce(function (result, pair) { - var parts = pair.split('='); - result[parts[0]] = parts[1]; - return result; - }, {}); - - if (adUnitInfo.bidstatus === '1') { - dimensions = adUnitInfo.bidid.split('@')[1].split('x'); - adResponse = bidfactory.createBid(1); - adResponse.bidderCode = 'pubmatic'; - adResponse.adSlot = bid.adSlot; - adResponse.cpm = Number(adUnitInfo.bid); - adResponse.ad = unescape(adUnit.creative_tag); // jshint ignore:line - adResponse.ad += utils.createTrackPixelHtml(decodeURIComponent(adUnit.tracking_url)); - adResponse.width = dimensions[0]; - adResponse.height = dimensions[1]; - adResponse.dealId = adUnitInfo.wdeal; - - bidmanager.addBidResponse(bids[i].placementCode, adResponse); - } else { - // Indicate an ad was not returned - adResponse = bidfactory.createBid(2); - adResponse.bidderCode = 'pubmatic'; - bidmanager.addBidResponse(bids[i].placementCode, adResponse); - } - } - }; + }; + } return { callBids: _callBids diff --git a/src/adapters/pulsepoint.js b/src/adapters/pulsepoint.js index 318fbde501a..23d4ee422b6 100644 --- a/src/adapters/pulsepoint.js +++ b/src/adapters/pulsepoint.js @@ -43,7 +43,7 @@ var PulsePointAdapter = function PulsePointAdapter() { function bidResponseAvailable(bidRequest, bidResponse) { if (bidResponse) { var adSize = bidRequest.params.cf.toUpperCase().split('X'); - var bid = bidfactory.createBid(1); + var bid = bidfactory.createBid(1, bidRequest.bidId); bid.bidderCode = bidRequest.bidder; bid.cpm = bidResponse.bidCpm; bid.ad = bidResponse.html; @@ -51,7 +51,7 @@ var PulsePointAdapter = function PulsePointAdapter() { bid.height = adSize[1]; bidmanager.addBidResponse(bidRequest.placementCode, bid); } else { - var passback = bidfactory.createBid(2); + var passback = bidfactory.createBid(2, bidRequest.bidId); passback.bidderCode = bidRequest.bidder; bidmanager.addBidResponse(bidRequest.placementCode, passback); } diff --git a/src/adapters/sovrn.js b/src/adapters/sovrn.js index d5d4f643205..0ac4006078d 100644 --- a/src/adapters/sovrn.js +++ b/src/adapters/sovrn.js @@ -1,3 +1,5 @@ +import { findBidRequest } from '../utils'; + var CONSTANTS = require('../constants.json'); var utils = require('../utils.js'); var bidfactory = require('../bidfactory.js'); @@ -104,8 +106,7 @@ var SovrnAdapter = function SovrnAdapter() { var bid = {}; // try to fetch the bid request we sent Sovrn - var bidObj = auction.getBidderRequests().find(bidSet => bidSet.bidderCode === 'sovrn').bids - .find(bid => bid.bidId === id); + var bidObj = findBidRequest({ bidId: id }); if (bidObj) { placementCode = bidObj.placementCode; diff --git a/src/adapters/springserve.js b/src/adapters/springserve.js index 3efb19f8f93..ca1124bb90d 100644 --- a/src/adapters/springserve.js +++ b/src/adapters/springserve.js @@ -57,50 +57,42 @@ SpringServeAdapter = function SpringServeAdapter() { var bids = params.bids || []; for (var i = 0; i < bids.length; i++) { var bid = bids[i]; - //bidmanager.pbCallbackMap[bid.params.impId] = params; + pbjs.handleSpringServeCB = _createCallback(bid); adloader.loadScript(buildSpringServeCall(bid)); } } - pbjs.handleSpringServeCB = function (responseObj) { - if (responseObj && responseObj.seatbid && responseObj.seatbid.length > 0 && - responseObj.seatbid[0].bid[0] !== undefined) { - - var responseBid = responseObj.seatbid[0].bid[0]; - var requestBids = pbjs.auctionManager.findBidderRequestByBidParamImpId(+responseBid.impid); - - //var requestBids = auction.getBidderRequests() - // .find(bidSet => bidSet.bidderCode === 'springserve').bids - // .filter(bid => bid.params && bid.params.impId === +responseBid.impid); - var bid = bidfactory.createBid(1); - var placementCode; - - //assign properties from the original request to the bid object - for (var i = 0; i < requestBids.length; i++) { - var bidRequest = requestBids[i]; - if (bidRequest.bidder === 'springserve') { - placementCode = bidRequest.placementCode; - var size = bidRequest.sizes[0]; - bid.width = size[0]; - bid.height = size[1]; + function _createCallback(bidRequest) { + return function _handleSpringServeCB(responseObj) { + if (responseObj && responseObj.seatbid && responseObj.seatbid.length > 0 && + responseObj.seatbid[0].bid[0] !== undefined) { + + var responseBid = responseObj.seatbid[0].bid[0]; + var bid = bidfactory.createBid(1, bidRequest.bidId); + var placementCode; + + //assign properties from the original request to the bid object + placementCode = bidRequest.placementCode; + var size = bidRequest.sizes[0]; + bid.width = size[0]; + bid.height = size[1]; + + bid.bidderCode = bidRequest.bidder; + + if (responseBid.hasOwnProperty('price') && responseBid.hasOwnProperty('adm')) { + //assign properties from the response to the bid object + bid.cpm = responseBid.price; + bid.ad = responseBid.adm; + } else { + //make object for invalid bid response + bid = bidfactory.createBid(2, bidRequest.bidId); + bid.bidderCode = 'springserve'; } - } - - bid.bidderCode = requestBids[0].bidder; - if (responseBid.hasOwnProperty('price') && responseBid.hasOwnProperty('adm')) { - //assign properties from the response to the bid object - bid.cpm = responseBid.price; - bid.ad = responseBid.adm; - } else { - //make object for invalid bid response - bid = bidfactory.createBid(2); - bid.bidderCode = 'springserve'; + bidmanager.addBidResponse(placementCode, bid); } - - bidmanager.addBidResponse(placementCode, bid); - } - }; + }; + } // Export the callBids function, so that prebid.js can execute this function // when the page asks to send out bid requests. diff --git a/src/adapters/triplelift.js b/src/adapters/triplelift.js index 8883f10004e..6c8f554b047 100644 --- a/src/adapters/triplelift.js +++ b/src/adapters/triplelift.js @@ -1,3 +1,5 @@ +import { findBidderRequestByBidId } from '../utils'; + var utils = require('../utils.js'); var adloader = require('../adloader.js'); var bidmanager = require('../bidmanager.js'); @@ -7,27 +9,19 @@ var bidfactory = require('../bidfactory.js'); * Use to create a TripleLiftAdapter object */ - var TripleLiftAdapter = function TripleLiftAdapter() { function _callBids(params) { var tlReq = params.bids; var bidsCount = tlReq.length; - //set expected bids count for callback execution - //bidmanager.setExpectedBidsCount('triplelift',bidsCount); - for (var i = 0; i < bidsCount; i++) { var bidRequest = tlReq[i]; var callbackId = bidRequest.bidderRequestId; adloader.loadScript(buildTLCall(bidRequest, callbackId)); - //store a reference to the bidRequest from the callback id - //bidmanager.pbCallbackMap[callbackId] = bidRequest; } - } - function buildTLCall(bid, callbackId) { //determine tag params var inventoryCode = utils.getBidIdParamater('inventoryCode', bid.params); @@ -68,12 +62,10 @@ var TripleLiftAdapter = function TripleLiftAdapter() { } - //expose the callback to the global object: pbjs.TLCB = function(tlResponseObj) { if (tlResponseObj && tlResponseObj.callback_id) { - //var bidObj = bidmanager.pbCallbackMap[tlResponseObj.callback_id], - var bidObj = auction.getBidderRequests().find(bidSet => bidSet.bidderRequestId === tlResponseObj.callback_id).bids.reduce((a, b) => b); + var bidObj = findBidderRequestByBidId({ adId: tlResponseObj.callback_id }); var placementCode = bidObj.placementCode; // @if NODE_ENV='debug' diff --git a/src/auctionmanager.js b/src/auctionmanager.js index e2b2f7af603..1c0c3935b39 100644 --- a/src/auctionmanager.js +++ b/src/auctionmanager.js @@ -39,7 +39,6 @@ export const auctionManager = (function() { this.setTargeting = (targeting) => _targeting = targeting; this.setBidderRequests = (bidderRequests) => _bidderRequests = bidderRequests; this.setBidsReceived = (bidsReceived) =>_bidsReceived = _bidsReceived.concat(bidsReceived); - this.setBidsReceived = (auctions) =>_auctions = _auctions.concat(auctions); this.getId = () => _id; this.getAdUnits = () => _adUnits; @@ -69,11 +68,29 @@ export const auctionManager = (function() { return _findAuctionsByBidderCode(...arguments); }, - findBidderRequestByBidId({ adId }) { + findBidderRequestByBidId({ bidId }) { return _auctions.map(auction => auction.getBidderRequests() - .find(request => request.bids - .find(bid => bid.adId === adId))) - .reduce((a, b) => a || b); + .find(request => request.bids + .find(bid => bid.bidId === bidId)))[0] || { start: null }; + }, + + findBidderRequestByBidParamImpId({ impId }) { + return _auctions.map(auction => auction.getBidderRequests() + .find(request => request.bids + .find(bid => bid.params && bid.params.impId === impId))); + }, + + findAuctionByBidId(bidId) { + return _auctions.find(auction => auction.getBidderRequests() + .find(request => request.bids + .find(bid => bid.bidId === bidId))); + }, + + findBidRequest({ bidId }) { + return _auctions.map(auction => auction.getBidderRequests() + .map(request => request.bids + .find(bid => bid.bidId === bidId)))[0] + .filter(bid => bid !== undefined)[0]; } }; }()); diff --git a/src/bidfactory.js b/src/bidfactory.js index f2c76db91d6..fc0505d373d 100644 --- a/src/bidfactory.js +++ b/src/bidfactory.js @@ -14,14 +14,14 @@ var utils = require('./utils.js'); dealId, priceKeyString; */ -function Bid(statusCode, adId) { +function Bid(statusCode, bidId) { var _statusCode = statusCode || 0; this.bidderCode = ''; this.width = 0; this.height = 0; this.statusMessage = _getStatus(); - this.adId = adId || utils.getUniqueIdentifierStr(); + this.bidId = bidId || utils.getUniqueIdentifierStr(); function _getStatus() { switch (_statusCode) { diff --git a/src/bidmanager.js b/src/bidmanager.js index db659605d23..ffd99726a96 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -40,8 +40,8 @@ function getBidders(bid) { return bid.bidder; } -function bidsBackForAdUnit({ adUnitCode, auction }) { - const requested = pbjs.adUnits.find(unit => unit.code === adUnitCode).bids.length; +function bidsBackForAdUnit(adUnitCode, auction) { + const requested = auction.getAdUnits().find(unit => unit.code === adUnitCode).bids.length; const received = auction.getBidsReceived().filter(bid => bid.adUnitCode === adUnitCode).length; return requested === received; } @@ -59,14 +59,19 @@ function bidsBackAll(auction) { // exports object exports.bidsBackForAdUnit = function() { - return bidsBackForAdUnit(); + return bidsBackForAdUnit(...arguments); }; /* * This function should be called to by the bidder adapter to register a bid response */ -exports.addBidResponse = function (adUnitCode, bid, auction) { - if (bid) { +exports.addBidResponse = function (adUnitCode, bid) { + var auction; + + if (bid && bid.bidId) { + auction = pbjs.auctionManager.findAuctionByBidId(bid.bidId); + auction = auction || pbjs.auctionManager.getSingleAuction(); + Object.assign(bid, { responseTimestamp: timestamp(), requestTimestamp: findBidderRequestByBidId(bid).start, @@ -80,7 +85,7 @@ exports.addBidResponse = function (adUnitCode, bid, auction) { events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, bid); //emit the bidResponse event - events.emit(CONSTANTS.EVENTS.BID_RESPONSE, adUnitCode, bid); + events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bid); //append price strings const priceStringsObj = getPriceBucketString(bid.cpm, bid.height, bid.width); @@ -100,18 +105,18 @@ exports.addBidResponse = function (adUnitCode, bid, auction) { auction.getBidsReceived().push(bid); } - if (bidsBackForAdUnit(bid.adUnitCode)) { - triggerAdUnitCallbacks(bid.adUnitCode); + if (bidsBackForAdUnit(bid.adUnitCode, auction)) { + triggerAdUnitCallbacks(bid.adUnitCode, auction); } - if (bidsBackAll()) { - this.executeCallback(); + if (bidsBackAll(auction)) { + this.executeCallback(auction); } if (bid.timeToRespond > pbjs.bidderTimeout) { - events.emit(CONSTANTS.EVENTS.BID_TIMEOUT, this.getTimedOutBidders()); - this.executeCallback(); + events.emit(CONSTANTS.EVENTS.BID_TIMEOUT, this.getTimedOutBidders(auction)); + this.executeCallback(auction); } }; diff --git a/src/events.js b/src/events.js index 3f46245949a..9c3830246a1 100644 --- a/src/events.js +++ b/src/events.js @@ -8,7 +8,7 @@ var push = Array.prototype.push; //define entire events //var allEvents = ['bidRequested','bidResponse','bidWon','bidTimeout']; -var allEvents = Object.keys(CONSTANTS.EVENTS).map(eventName => eventName); +var allEvents = Object.keys(CONSTANTS.EVENTS).map(key => CONSTANTS.EVENTS[key]); var idPaths = CONSTANTS.EVENT_ID_PATHS; diff --git a/src/prebid.js b/src/prebid.js index 6cd751e6cb3..90897357e44 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -215,10 +215,11 @@ pbjs.getAdserverTargetingForAdUnitCodeStr = function (adunitCode) { /** * This function returns the query string targeting parameters available at this moment for a given ad unit. Note that some bidder's response may not have been received if you call this function too quickly after the requests are sent. * @param adUnitCode {string} adUnitCode to get the bid responses for + * @param auction {Object} auction from which to get targeting info * @returns {object} returnObj return bids */ pbjs.getAdserverTargetingForAdUnitCode = function (adUnitCode, auction) { - // todo validate params, type check auction + auction = auction || pbjs.auctionManager.getSingleAuction(); utils.logInfo('Invoking pbjs.getAdserverTargetingForAdUnitCode', arguments); @@ -246,9 +247,11 @@ pbjs.getAdserverTargetingForAdUnitCode = function (adUnitCode, auction) { * @alias module:pbjs.getAdserverTargeting */ -pbjs.getAdserverTargeting = function () { +pbjs.getAdserverTargeting = function (auction) { + auction = auction || pbjs.auctionManager.getSingleAuction(); + utils.logInfo('Invoking pbjs.getAdserverTargeting', arguments); - return getAllTargeting() + return getAllTargeting(auction) .map(targeting => { return { [Object.keys(targeting)[0]]: targeting[Object.keys(targeting)[0]] @@ -305,14 +308,16 @@ pbjs.getBidResponsesForAdUnitCode = function (adUnitCode, auction) { * Set query string targeting on all GPT ad units. * @alias module:pbjs.setTargetingForGPTAsync */ -pbjs.setTargetingForGPTAsync = function () { +pbjs.setTargetingForGPTAsync = function (auction) { + auction = auction || pbjs.auctionManager.getSingleAuction(); + utils.logInfo('Invoking pbjs.setTargetingForGPTAsync', arguments); if (!isGptPubadsDefined()) { utils.logError('window.googletag is not defined on the page'); return; } - setTargeting(getAllTargeting()); + setTargeting(getAllTargeting(auction)); }; /** @@ -332,6 +337,8 @@ pbjs.allBidsAvailable = function () { * @alias module:pbjs.renderAd */ pbjs.renderAd = function (doc, id, auction) { + auction = auction || pbjs.auctionManager.getSingleAuction(); + utils.logInfo('Invoking pbjs.renderAd', arguments); utils.logMessage('Calling renderAd with adId :' + id); if (doc && id) { @@ -473,6 +480,7 @@ pbjs.addAdUnits = function (adUnitArr) { * @param {String} event the name of the event * @param {Function} handler a callback to set on event * @param {String} id an identifier in the context of the event + * @param {Object} auction the auction that triggered the event * * This API call allows you to register a callback to handle a Prebid.js event. * An optional `id` parameter provides more finely-grained event callback registration. @@ -484,19 +492,21 @@ pbjs.addAdUnits = function (adUnitArr) { * * Currently `bidWon` is the only event that accepts an `id` parameter. */ -pbjs.onEvent = function (event, handler, id) { +pbjs.onEvent = function (event, handler, id, auction) { + auction = auction || pbjs.auctionManager.getSingleAuction(); + utils.logInfo('Invoking pbjs.onEvent', arguments); if (!utils.isFn(handler)) { utils.logError(`The event handler provided is not a function and was not set on event ${event}.`); return; } - if (id && !eventValidators[event].call(null, id)) { + if (id && !eventValidators[event].call(null, id, auction)) { utils.logError(`The id provided is not valid for event ${event} and no handler was set.`); return; } - events.on(event, handler, id); + events.on(event, handler, id, auction); }; /** diff --git a/src/utils.js b/src/utils.js index 19e1d07c542..32b01b4cdc1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -464,10 +464,6 @@ export function flatten(a, b) { return a.concat(b); } -export function findBidderRequestByBidId() { - return pbjs.auctionManager.findBidderRequestByBidId(...arguments); -} - export function getKeys(obj) { return Object.keys(obj); } @@ -500,6 +496,14 @@ export function getUniqueIdentifierStr() { exports.getUniqueIdentifierStr(); } +export function findBidderRequestByBidId() { + return pbjs.auctionManager.findBidderRequestByBidId(...arguments); +} + export function findAuctionByBidderCode() { return pbjs.auctionManager.findAuctionByBidderCode(...arguments); +} + +export function findBidRequest() { + return pbjs.auctionManager.findBidRequest(...arguments); } \ No newline at end of file diff --git a/test/spec/bidmanager_spec.js b/test/spec/bidmanager_spec.js index 2e26f577ece..390d3e79304 100644 --- a/test/spec/bidmanager_spec.js +++ b/test/spec/bidmanager_spec.js @@ -56,7 +56,7 @@ describe('bidmanager.js', function () { return this.height + 'x' + this.width; }; bid.bidderCode = bidderCode; - bid.adId = adId; + bid.bidId = adId; });