Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for publisher-defined outstream renderers #1357

Merged
merged 1 commit into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});