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

Mediasquare Bid Adapter: add video renderer + change with floors #9079

Merged
merged 1 commit into from
Oct 14, 2022
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: 42 additions & 3 deletions modules/mediasquareBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import {Renderer} from '../src/Renderer.js';

const BIDDER_CODE = 'mediasquare';
const BIDDER_URL_PROD = 'https://pbs-front.mediasquare.fr/'
const BIDDER_URL_TEST = 'https://bidder-test.mediasquare.fr/'
const BIDDER_ENDPOINT_AUCTION = 'msq_prebid';
const BIDDER_ENDPOINT_WINNING = 'winning';

const OUTSTREAM_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';

export const spec = {
code: BIDDER_CODE,
gvlid: 791,
Expand Down Expand Up @@ -40,11 +43,15 @@ export const spec = {
const test = config.getConfig('debug') ? 1 : 0;
let adunitValue = null;
Object.keys(validBidRequests).forEach(key => {
floor = {};
adunitValue = validBidRequests[key];
if (typeof adunitValue.getFloor === 'function') {
floor = adunitValue.getFloor({currency: 'EUR', mediaType: '*', size: '*'});
} else {
floor = {};
if (Array.isArray(adunitValue.sizes)) {
adunitValue.sizes.forEach(value => {
let tmpFloor = adunitValue.getFloor({currency: 'USD', mediaType: '*', size: value});
if (tmpFloor != {}) { floor[value.join('x')] = tmpFloor; }
});
}
}
codes.push({
owner: adunitValue.params.owner,
Expand Down Expand Up @@ -132,6 +139,7 @@ export const spec = {
if ('url' in value['video']) { bidResponse['vastUrl'] = value['video']['url'] }
if ('xml' in value['video']) { bidResponse['vastXml'] = value['video']['xml'] }
bidResponse['mediaType'] = 'video';
bidResponse['renderer'] = createRenderer(value, OUTSTREAM_RENDERER_URL);
}
if (value.hasOwnProperty('deal_id')) { bidResponse['dealId'] = value['deal_id']; }
bidResponses.push(bidResponse);
Expand Down Expand Up @@ -182,4 +190,35 @@ export const spec = {
}

}

function outstreamRender(bid) {
bid.renderer.push(() => {
window.ANOutstreamVideo.renderAd({
sizes: [bid.width, bid.height],
targetId: bid.adUnitCode,
adResponse: bid.adResponse,
rendererOptions: {
showBigPlayButton: false,
showProgressBar: 'bar',
showVolume: false,
allowFullscreen: true,
skippable: false,
content: bid.vastXml
}
});
});
}

function createRenderer(bid, url) {
const renderer = Renderer.install({
id: bid.bidId,
url: url,
loaded: false,
adUnitCode: bid.adUnitCode,
targetId: bid.adUnitCode
});
renderer.setRender(outstreamRender);
return renderer;
}

registerBidder(spec);
6 changes: 4 additions & 2 deletions test/spec/modules/mediasquareBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ describe('MediaSquare bid adapter tests', function () {
owner: 'test',
code: 'publishername_atf_desktop_rg_pave'
},
getFloor: function (a) { return { currency: 'EUR', floor: 1.0 }; },
sizes: [[300, 250]],
getFloor: function (a) { return { currency: 'USD', floor: 1.0 }; },
}];
var BID_RESPONSE = {'body': {
'responses': [{
Expand Down Expand Up @@ -142,7 +143,7 @@ describe('MediaSquare bid adapter tests', function () {
const requestfloor = spec.buildRequests(FLOORS_PARAMS, DEFAULT_OPTIONS);
const responsefloor = JSON.parse(requestfloor.data);
expect(responsefloor.codes[0]).to.have.property('floor').exist;
expect(responsefloor.codes[0].floor).to.have.property('floor').and.to.equal(1.0);
expect(responsefloor.codes[0].floor).to.have.property('300x250').and.to.have.property('floor').and.to.equal(1);
});

it('Verify parse response', function () {
Expand Down Expand Up @@ -239,6 +240,7 @@ describe('MediaSquare bid adapter tests', function () {
const bid = response[0];
expect(bid).to.have.property('vastXml');
expect(bid).to.have.property('vastUrl');
expect(bid).to.have.property('renderer');
delete BID_RESPONSE.body.responses[0].video;
});
});