diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 579aa7d9510..004c8d6fac6 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -42,6 +42,7 @@ function getBids({bidderCode, requestId, bidderRequestId, adUnits}) { return Object.assign({}, bid, { placementCode: adUnit.code, mediaType: adUnit.mediaType, + renderer: adUnit.renderer, transactionId: adUnit.transactionId, sizes: sizes, bidId: bid.bid_id || utils.getUniqueIdentifierStr(), diff --git a/src/bidmanager.js b/src/bidmanager.js index 0c18f9fe27c..cd910c54524 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -2,6 +2,7 @@ import { uniques, flatten, adUnitsFilter, getBidderRequest } from './utils'; import {getPriceBucketString} from './cpmBucketManager'; import {NATIVE_KEYS, nativeBidIsValid} from './native'; import { store } from './videoCache'; +import { Renderer } from 'src/Renderer'; var CONSTANTS = require('./constants.json'); var AUCTION_END = CONSTANTS.EVENTS.AUCTION_END; @@ -134,12 +135,12 @@ exports.addBidResponse = function (adUnitCode, bid) { // This must be fired first, so that we calculate derived values from the updates events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, bid); - const { requestId, start } = getBidderRequest(bid.bidderCode, adUnitCode); + const bidRequest = getBidderRequest(bid.bidderCode, adUnitCode); Object.assign(bid, { - requestId: requestId, + requestId: bidRequest.requestId, responseTimestamp: timestamp(), - requestTimestamp: start, + requestTimestamp: bidRequest.start, cpm: parseFloat(bid.cpm) || 0, bidder: bid.bidderCode, adUnitCode @@ -147,6 +148,15 @@ exports.addBidResponse = function (adUnitCode, bid) { bid.timeToRespond = bid.responseTimestamp - bid.requestTimestamp; + // a publisher-defined renderer can be used to render bids + const adUnitRenderer = + bidRequest.bids && bidRequest.bids[0] && bidRequest.bids[0].renderer; + + if (adUnitRenderer) { + bid.renderer = Renderer.install({ url: adUnitRenderer.url }); + bid.renderer.setRender(adUnitRenderer.render); + } + const priceStringsObj = getPriceBucketString(bid.cpm, _customPriceBucket); bid.pbLg = priceStringsObj.low; bid.pbMg = priceStringsObj.med; diff --git a/test/spec/bidmanager_spec.js b/test/spec/bidmanager_spec.js index ae83a8d106f..d47d207c4d5 100644 --- a/test/spec/bidmanager_spec.js +++ b/test/spec/bidmanager_spec.js @@ -533,5 +533,27 @@ describe('bidmanager.js', function () { utils.getBidRequest.restore(); }); + + it('installs publisher-defined renderers on bids', () => { + sinon.stub(utils, 'getBidderRequest', () => ({ + bids: [{ + renderer: { + url: 'renderer.js', + render: (bid) => bid + } + }] + })); + + const bid = Object.assign({}, bidfactory.createBid(1), { + bidderCode: 'appnexusAst', + mediaType: 'video-outstream', + }); + + bidmanager.addBidResponse('adUnit-code', bid); + const addedBid = $$PREBID_GLOBAL$$._bidsReceived.pop(); + assert.equal(addedBid.renderer.url, 'renderer.js'); + + utils.getBidderRequest.restore(); + }); }); });