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

Media type renderers #5760

Merged
merged 12 commits into from
Oct 29, 2020
45 changes: 18 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,26 @@ function getPreparedBidForAuction({adUnitCode, bid, bidderRequest, auctionId}) {
const bidReq = bidderRequest.bids && find(bidderRequest.bids, bid => bid.adUnitCode == adUnitCode);
const adUnitRenderer = bidReq && bidReq.renderer;

if (adUnitRenderer && adUnitRenderer.url && !(adUnitRenderer.backupOnly && isBoolean(adUnitRenderer.backupOnly) && bid.renderer)) {
bidObject.renderer = Renderer.install({ url: adUnitRenderer.url });
bidObject.renderer.setRender(adUnitRenderer.render);
// a publisher can also define a renderer for a mediaType
const bidObjectMediaType = bidObject.mediaType;
const bidMediaType = bidReq &&
bidReq.mediaTypes &&
bidReq.mediaTypes[bidObjectMediaType];

var mediaTypeRenderer = bidMediaType && bidMediaType.renderer;

var renderer = null;

// the renderer for the mediaType takes precendence
if (mediaTypeRenderer && mediaTypeRenderer.url && mediaTypeRenderer.render) {
renderer = mediaTypeRenderer;
} else if (adUnitRenderer && adUnitRenderer.url && !(adUnitRenderer.backupOnly && isBoolean(adUnitRenderer.backupOnly) && bid.renderer)) {
renderer = adUnitRenderer;
}

if (renderer) {
bidObject.renderer = Renderer.install({ url: renderer.url });
bidObject.renderer.setRender(renderer.render);
}

// Use the config value 'mediaTypeGranularity' if it has been defined for mediaType, else use 'customPriceBucket'
Expand Down
2 changes: 1 addition & 1 deletion src/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const checkVideoBidSetup = hook('sync', function(bid, bidRequest, videoMe

// outstream bids require a renderer on the bid or pub-defined on adunit
if (context === OUTSTREAM) {
return !!(bid.renderer || bidRequest.renderer);
return !!(bid.renderer || bidRequest.renderer || videoMediaType.renderer);
}

return true;
Expand Down
30 changes: 30 additions & 0 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,36 @@ describe('auctionmanager.js', function () {
assert.equal(addedBid.renderer.url, 'renderer.js');
});

it('installs publisher-defined renderers for a media type', function () {
const renderer = {
url: 'videoRenderer.js',
render: (bid) => bid
};
let myBid = mockBid();
let bidRequest = mockBidRequest(myBid);

bidRequest.bids[0] = {
...bidRequest.bids[0],
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
},
video: {
context: 'outstream',
renderer
}
}
};
makeRequestsStub.returns([bidRequest]);

myBid.mediaType = 'video';
spec.interpretResponse.returns(myBid);
auction.callBids();

const addedBid = auction.getBidsReceived().pop();
assert.equal(addedBid.renderer.url, renderer.url);
});

it('bid for a regular unit and a video unit', function() {
let renderer = {
url: 'renderer.js',
Expand Down
23 changes: 23 additions & 0 deletions test/spec/video_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ describe('video.js', function () {
expect(valid).to.equal(true);
});

it('validates valid outstream bids with a publisher defined renderer', function () {
const bid = {
requestId: '123abc',
};
const bidRequests = [{
bids: [{
bidId: '123abc',
bidder: 'appnexus',
mediaTypes: {
video: {
context: 'outstream',
renderer: {
url: 'render.url',
render: () => true,
}
}
}
}]
}];
const valid = isValidVideoBid(bid, bidRequests);
expect(valid).to.equal(true);
});

it('catches invalid outstream bids', function () {
const bid = {
requestId: '123abc'
Expand Down