Skip to content

Commit

Permalink
Add support for publisher-defined outstream renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlane committed Jul 11, 2017
1 parent 3b8b29d commit e615775
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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(),
Expand Down
16 changes: 13 additions & 3 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,18 +126,27 @@ exports.addBidResponse = function (adUnitCode, bid) {
// Postprocess the bids so that all the universal properties exist, no matter which bidder they came from.
// This should be called before addBidToAuction().
function prepareBidForAuction() {
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
});

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);
}

// append price strings
const priceStringsObj = getPriceBucketString(bid.cpm, _customPriceBucket);
bid.pbLg = priceStringsObj.low;
Expand Down
22 changes: 22 additions & 0 deletions test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,5 +530,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();
});
});
});

0 comments on commit e615775

Please sign in to comment.