Skip to content

Commit

Permalink
Media type renderers (#5760)
Browse files Browse the repository at this point in the history
* allow publisher to define a renderer specific to the mediaType

* validate outstream bid with a renderer defined on the video mediaType

* get the mediaTypes from the bidReqest

* tests for publisher-defined, media-specific renderers

* use single quote

* undo inadvertent package-lock.json changes

Co-authored-by: Michael Sperone <msperone@usnews.com>
  • Loading branch information
MikeSperone and msperone authored Oct 29, 2020
1 parent d966829 commit 78a2d28
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
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

0 comments on commit 78a2d28

Please sign in to comment.