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

Adding Medianet outstream renderer support #5854

Merged
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
45 changes: 43 additions & 2 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { Renderer } from '../src/Renderer.js';

const BIDDER_CODE = 'medianet';
const BID_URL = 'https://prebid.media.net/rtb/prebid';
const PLAYER_URL = 'https://prebid.media.net/video/bundle.js';
const SLOT_VISIBILITY = {
NOT_DETERMINED: 0,
ABOVE_THE_FOLD: 1,
Expand All @@ -16,10 +18,14 @@ const EVENTS = {
BID_WON_EVENT_NAME: 'client_bid_won'
};
const EVENT_PIXEL_URL = 'qsearch-a.akamaihd.net/log';

const OUTSTREAM = 'outstream';
let refererInfo = getRefererInfo();

let mnData = {};

window.mnet = window.mnet || {};
window.mnet.queue = window.mnet.queue || [];

mnData.urlData = {
domain: utils.parseUrl(refererInfo.referer).hostname,
page: refererInfo.referer,
Expand Down Expand Up @@ -314,6 +320,40 @@ function clearMnData() {
mnData = {};
}

function addRenderer(bid) {
const videoContext = utils.deepAccess(bid, 'context') || '';
const vastTimeout = utils.deepAccess(bid, 'vto');
/* Adding renderer only when the context is Outstream
and the provider has responded with a renderer.
*/
if (videoContext == OUTSTREAM && vastTimeout) {
bid.renderer = newVideoRenderer(bid);
}
}

function newVideoRenderer(bid) {
const renderer = Renderer.install({
url: PLAYER_URL,
});
renderer.setRender(function (bid) {
window.mnet.queue.push(function () {
const obj = {
width: bid.width,
height: bid.height,
vastTimeout: bid.vto,
maxAllowedVastTagRedirects: bid.mavtr,
allowVpaid: bid.avp,
autoPlay: bid.ap,
preload: bid.pl,
mute: bid.mt
}
const adUnitCode = bid.dfp_id;
const divId = utils.getGptSlotInfoForAdUnitCode(adUnitCode).divId || adUnitCode;
window.mnet.mediaNetoutstreamPlayer(bid, divId, obj);
});
});
return renderer;
}
export const spec = {

code: BIDDER_CODE,
Expand Down Expand Up @@ -380,9 +420,10 @@ export const spec = {
}
validBids = bids.filter(bid => isValidBid(bid));

validBids.forEach(addRenderer);

return validBids;
},

getUserSyncs: function(syncOptions, serverResponses) {
let cookieSyncUrls = fetchCookieSyncUrls(serverResponses);

Expand Down
41 changes: 41 additions & 0 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,42 @@ let VALID_BID_REQUEST = [{
}
}
},
SERVER_VIDEO_OUTSTREAM_RESPONSE_VALID_BID = {
body: {
'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a',
'bidList': [{
'no_bid': false,
'requestId': '27210feac00e96',
'cpm': 12.00,
'width': 640,
'height': 480,
'ttl': 180,
'creativeId': '370637746',
'netRevenue': true,
'vastXml': '',
'currency': 'USD',
'dfp_id': 'video1',
'mediaType': 'video',
'vto': 5000,
'mavtr': 10,
'avp': true,
'ap': true,
'pl': true,
'mt': true,
'jslt': 3000,
'context': 'outstream'
}],
'ext': {
'csUrl': [{
'type': 'image',
'url': 'http://cs.media.net/cksync.php'
}, {
'type': 'iframe',
'url': 'http://contextual.media.net/checksync.php?&vsSync=1'
}]
}
}
},
SERVER_VALID_BIDS = [{
'no_bid': false,
'requestId': '27210feac00e96',
Expand Down Expand Up @@ -1379,4 +1415,9 @@ describe('Media.net bid adapter', function () {
expect(response).to.deep.equal(undefined);
});
});

it('context should be outstream', function () {
let bids = spec.interpretResponse(SERVER_VIDEO_OUTSTREAM_RESPONSE_VALID_BID, []);
expect(bids[0].context).to.equal('outstream');
});
});