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 13, 2017
1 parent 81f3877 commit 61c617a
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 @@ -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(),
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 @@ -134,19 +135,28 @@ 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
});

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

0 comments on commit 61c617a

Please sign in to comment.