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 Render RichAudience Adapter #5357

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 39 additions & 8 deletions modules/richaudienceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import { Renderer } from '../src/Renderer.js';

const BIDDER_CODE = 'richaudience';
let REFERER = '';
Expand Down Expand Up @@ -46,7 +47,7 @@ export const spec = {
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
user: raiSetEids(bid),
demand: raiGetDemandType(bid) ? 'video' : 'display',
demand: raiGetDemandType(bid),
videoData: raiGetVideoInfo(bid)
};

Expand Down Expand Up @@ -97,6 +98,12 @@ export const spec = {

if (response.media_type === 'video') {
bidResponse.vastXml = response.vastXML;
if (JSON.parse(bidRequest.data).videoData.format == 'outstream') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON.parse here should be surrounded by a try/catch block - in case it can't parse the string.

bidResponse.renderer = Renderer.install({
url: 'https://cdn3.richaudience.com/prebidVideo/player.js'
});
bidResponse.renderer.setRender(renderer);
}
} else {
bidResponse.ad = response.adm
}
Expand Down Expand Up @@ -165,20 +172,23 @@ function raiGetSizes(bid) {
}

function raiGetDemandType(bid) {
let raiFormat = 'display';
if (bid.mediaTypes != undefined) {
if (bid.mediaTypes.video != undefined) {
return true;
raiFormat = 'video';
}
}
return false;
return raiFormat;
}

function raiGetVideoInfo(bid) {
let videoData = [];
if (raiGetDemandType(bid)) {
videoData.push({format: bid.mediaTypes.video.context});
videoData.push({playerSize: bid.mediaTypes.video.playerSize});
videoData.push({mimes: bid.mediaTypes.video.mimes});
let videoData;
if (raiGetDemandType(bid) == 'video') {
videoData = {
format: bid.mediaTypes.video.context,
playerSize: bid.mediaTypes.video.playerSize,
mimes: bid.mediaTypes.video.mimes
};
}
return videoData;
}
Expand Down Expand Up @@ -206,3 +216,24 @@ function raiSetUserId(bid, eids, source, value) {
});
}
}

function renderer(bid) {
bid.renderer.push(() => {
renderAd(bid)
});
}

function renderAd(bid) {
let raOutstreamHBPassback = `${bid.vastXml}`;
let raPlayerHB = {
config: bid.params[0].player != undefined ? {
end: bid.params[0].player.end != null ? bid.params[0].player.end : 'close',
init: bid.params[0].player.init != null ? bid.params[0].player.init : 'close',
skin: bid.params[0].player.skin != null ? bid.params[0].player.skin : 'light',
} : {end: 'close', init: 'close', skin: 'light'},
pid: bid.params[0].pid,
adUnit: bid.adUnitCode
};

window.raParams(raPlayerHB, raOutstreamHBPassback, true);
}
118 changes: 114 additions & 4 deletions test/spec/modules/richaudienceBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ describe('Richaudience adapter tests', function () {
user: {}
}];

var DEFAULT_PARAMS_VIDEO = [{
var DEFAULT_PARAMS_VIDEO_IN = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
mediaTypes: {
video: {
context: 'instream', // or 'outstream'
context: 'instream',
playerSize: [640, 480],
mimes: ['video/mp4']
}
Expand All @@ -52,6 +52,57 @@ describe('Richaudience adapter tests', function () {
user: {}
}];

var DEFAULT_PARAMS_VIDEO_OUT = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [640, 480],
mimes: ['video/mp4']
}
},
bidder: 'richaudience',
params: {
bidfloor: 0.5,
pid: 'ADb1f40rmi',
supplyType: 'site'
},
auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563',
bidRequestsCount: 1,
bidderRequestId: '1858b7382993ca',
transactionId: '29df2112-348b-4961-8863-1b33684d95e6',
user: {}
}];

var DEFAULT_PARAMS_VIDEO_OUT_PARAMS = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [640, 480],
mimes: ['video/mp4']
}
},
bidder: 'richaudience',
params: {
bidfloor: 0.5,
pid: 'ADb1f40rmi',
supplyType: 'site',
player: {
init: 'close',
end: 'close',
skin: 'dark'
}
},
auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563',
bidRequestsCount: 1,
bidderRequestId: '1858b7382993ca',
transactionId: '29df2112-348b-4961-8863-1b33684d95e6',
user: {}
}];

var DEFAULT_PARAMS_APP = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
Expand Down Expand Up @@ -191,6 +242,45 @@ describe('Richaudience adapter tests', function () {
expect(requestContent).to.have.property('numIframes').and.to.equal(0);
})

it('Verify build request to prebid video inestream', function() {
const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_IN, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
},
refererInfo: {
referer: 'https://domain.com',
numIframes: 0
}
});

expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);

expect(requestContent).to.have.property('demand').and.to.equal('video');
expect(requestContent.videoData).to.have.property('format').and.to.equal('instream');
// expect(requestContent.videoData.playerSize[0][0]).to.equal('640');
// expect(requestContent.videoData.playerSize[0][0]).to.equal('480');
})

it('Verify build request to prebid video outstream', function() {
const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_OUT, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
},
refererInfo: {
referer: 'https://domain.com',
numIframes: 0
}
});

expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);

expect(requestContent.videoData).to.have.property('format').and.to.equal('outstream');
})

describe('gdpr test', function () {
it('Verify build request with GDPR', function () {
config.setConfig({
Expand Down Expand Up @@ -502,8 +592,26 @@ describe('Richaudience adapter tests', function () {
expect(bid.dealId).to.equal('dealId');
});

it('no banner media response', function () {
const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, {
it('no banner media response inestream', function () {
const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_IN, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
},
refererInfo: {
referer: 'https://domain.com',
numIframes: 0
}
});

const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]);
const bid = bids[0];
expect(bid.mediaType).to.equal('video');
expect(bid.vastXml).to.equal('<VAST></VAST>');
});

it('no banner media response outstream', function () {
const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_OUT, {
gdprConsent: {
consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA',
gdprApplies: true
Expand All @@ -516,7 +624,9 @@ describe('Richaudience adapter tests', function () {

const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]);
const bid = bids[0];
expect(bid.mediaType).to.equal('video');
expect(bid.vastXml).to.equal('<VAST></VAST>');
expect(bid.renderer.url).to.equal('https://cdn3.richaudience.com/prebidVideo/player.js');
});

it('Verifies bidder_code', function () {
Expand Down