Skip to content

Commit

Permalink
RichAudience Bid Adapter: add render video in banner (#6392)
Browse files Browse the repository at this point in the history
  • Loading branch information
richaudience authored Mar 19, 2021
1 parent 3eb1216 commit 24c4fb8
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 42 deletions.
62 changes: 36 additions & 26 deletions modules/richaudienceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ export const spec = {
supportedMediaTypes: [BANNER, VIDEO],

/***
* Determines whether or not the given bid request is valid
*
* @param {bidRequest} bid The bid params to validate.
* @returns {boolean} True if this is a valid bid, and false otherwise
*/
* Determines whether or not the given bid request is valid
*
* @param {bidRequest} bid The bid params to validate.
* @returns {boolean} True if this is a valid bid, and false otherwise
*/
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.pid && bid.params.supplyType);
},
/***
* Build a server request from the list of valid BidRequests
* @param {validBidRequests} is an array of the valid bids
* @param {bidderRequest} bidder request object
* @returns {ServerRequest} Info describing the request to the server
*/
* Build a server request from the list of valid BidRequests
* @param {validBidRequests} is an array of the valid bids
* @param {bidderRequest} bidder request object
* @returns {ServerRequest} Info describing the request to the server
*/
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bid => {
var payload = {
Expand Down Expand Up @@ -77,11 +77,11 @@ export const spec = {
});
},
/***
* Read the response from the server and build a list of bids
* @param {serverResponse} Response from the server.
* @param {bidRequest} Bid request object
* @returns {bidResponses} Array of bids which were nested inside the server
*/
* Read the response from the server and build a list of bids
* @param {serverResponse} Response from the server.
* @param {bidRequest} Bid request object
* @returns {bidResponses} Array of bids which were nested inside the server
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
// try catch
Expand All @@ -103,10 +103,16 @@ export const spec = {
if (response.media_type === 'video') {
bidResponse.vastXml = response.vastXML;
try {
if (JSON.parse(bidRequest.data).videoData.format == 'outstream') {
bidResponse.renderer = Renderer.install({
url: 'https://cdn3.richaudience.com/prebidVideo/player.js'
});
if (bidResponse.vastXml != null) {
if (JSON.parse(bidRequest.data).videoData.format == 'outstream' || JSON.parse(bidRequest.data).videoData.format == 'banner') {
bidResponse.renderer = Renderer.install({
id: bidRequest.bidId,
adunitcode: bidRequest.tagId,
loaded: false,
config: response.media_type,
url: 'https://cdn3.richaudience.com/prebidVideo/player.js'
});
}
bidResponse.renderer.setRender(renderer);
}
} catch (e) {
Expand All @@ -121,13 +127,13 @@ export const spec = {
return bidResponses
},
/***
* User Syncs
*
* @param {syncOptions} Publisher prebid configuration
* @param {serverResponses} Response from the server
* @param {gdprConsent} GPDR consent object
* @returns {Array}
*/
* User Syncs
*
* @param {syncOptions} Publisher prebid configuration
* @param {serverResponses} Response from the server
* @param {gdprConsent} GPDR consent object
* @returns {Array}
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent) {
const syncs = [];

Expand Down Expand Up @@ -197,6 +203,10 @@ function raiGetVideoInfo(bid) {
playerSize: bid.mediaTypes.video.playerSize,
mimes: bid.mediaTypes.video.mimes
};
} else {
videoData = {
format: 'banner'
}
}
return videoData;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/richaudienceBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Please reach out to your account manager for more information.
"pid":"ADb1f40rmo",
"supplyType":"site",
"bidfloor":0.40,
"keywords": "bici=scott;coche=audi;coche=mercedes;"
"keywords": "key1=value1;key2=value2;key3=value3;"
}
}]
}
Expand Down
99 changes: 84 additions & 15 deletions test/spec/modules/richaudienceBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Richaudience adapter tests', function () {
bidfloor: 0.5,
pid: 'ADb1f40rmi',
supplyType: 'site',
keywords: 'coche=mercedes;coche=audi'
keywords: 'key1=value1;key2=value2'
},
auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563',
bidRequestsCount: 1,
Expand Down Expand Up @@ -75,26 +75,19 @@ describe('Richaudience adapter tests', function () {
user: {}
}];

var DEFAULT_PARAMS_VIDEO_OUT_PARAMS = [{
var DEFAULT_PARAMS_BANNER_OUTSTREAM = [{
adUnitCode: 'test-div',
bidId: '2c7c8e9c900244',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [640, 480],
mimes: ['video/mp4']
banner: {
sizes: [[300, 250], [600, 300]]
}
},
bidder: 'richaudience',
params: {
bidfloor: 0.5,
pid: 'ADb1f40rmi',
supplyType: 'site',
player: {
init: 'close',
end: 'close',
skin: 'dark'
}
supplyType: 'site'
},
auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563',
bidRequestsCount: 1,
Expand Down Expand Up @@ -242,7 +235,7 @@ describe('Richaudience adapter tests', function () {
expect(requestContent).to.have.property('numIframes').and.to.equal(0);
expect(typeof requestContent.scr_rsl === 'string')
expect(typeof requestContent.cpuc === 'number')
expect(requestContent).to.have.property('kws').and.to.equal('coche=mercedes;coche=audi');
expect(requestContent).to.have.property('kws').and.to.equal('key1=value1;key2=value2');
})

it('Verify build request to prebid video inestream', function() {
Expand All @@ -262,8 +255,6 @@ describe('Richaudience adapter tests', function () {

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() {
Expand All @@ -281,6 +272,7 @@ describe('Richaudience adapter tests', function () {
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('outstream');
})

Expand Down Expand Up @@ -623,9 +615,19 @@ describe('Richaudience adapter tests', function () {
});

const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]);
expect(bids).to.have.lengthOf(1);
const bid = bids[0];
expect(bid.cpm).to.equal(1.50);
expect(bid.mediaType).to.equal('video');
expect(bid.vastXml).to.equal('<VAST></VAST>');
expect(bid.cpm).to.equal(1.50);
expect(bid.width).to.equal(1);
expect(bid.height).to.equal(1);
expect(bid.creativeId).to.equal('189198063');
expect(bid.netRevenue).to.equal(true);
expect(bid.currency).to.equal('USD');
expect(bid.ttl).to.equal(300);
expect(bid.dealId).to.equal('dealId');
});

it('no banner media response outstream', function () {
Expand All @@ -640,6 +642,35 @@ describe('Richaudience adapter tests', function () {
}
});

const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]);
expect(bids).to.have.lengthOf(1);
const bid = bids[0];
expect(bid.cpm).to.equal(1.50);
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');
expect(bid.cpm).to.equal(1.50);
expect(bid.width).to.equal(1);
expect(bid.height).to.equal(1);
expect(bid.creativeId).to.equal('189198063');
expect(bid.netRevenue).to.equal(true);
expect(bid.currency).to.equal('USD');
expect(bid.ttl).to.equal(300);
expect(bid.dealId).to.equal('dealId');
});

it('banner media and response VAST', function () {
const request = spec.buildRequests(DEFAULT_PARAMS_BANNER_OUTSTREAM, {
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');
Expand All @@ -656,6 +687,16 @@ describe('Richaudience adapter tests', function () {
expect(spec.aliases[0]).to.equal('ra');
});

it('Verifies bidder gvlid', function () {
expect(spec.gvlid).to.equal(108);
});

it('Verifies bidder supportedMediaTypes', function () {
expect(spec.supportedMediaTypes).to.have.lengthOf(2);
expect(spec.supportedMediaTypes[0]).to.equal('banner');
expect(spec.supportedMediaTypes[1]).to.equal('video');
});

it('Verifies if bid request is valid', function () {
expect(spec.isBidRequestValid(DEFAULT_PARAMS_NEW_SIZES[0])).to.equal(true);
expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL[0])).to.equal(true);
Expand Down Expand Up @@ -717,6 +758,34 @@ describe('Richaudience adapter tests', function () {
bidfloor: 0.50,
}
})).to.equal(true);
expect(spec.isBidRequestValid({
params: {
pid: ['1gCB5ZC4XL', '1a40xk8qSV'],
bidfloor: 0.50,
}
})).to.equal(false);
expect(spec.isBidRequestValid({
params: {
pid: ['1gCB5ZC4XL', '1a40xk8qSV'],
supplyType: 'site',
bidfloor: 0.50,
}
})).to.equal(true);
expect(spec.isBidRequestValid({
params: {
supplyType: 'site',
bidfloor: 0.50,
ifa: 'AAAAAAAAA-BBBB-CCCC-1111-222222220000',
}
})).to.equal(false);
expect(spec.isBidRequestValid({
params: {
pid: ['1gCB5ZC4XL', '1a40xk8qSV'],
supplyType: 'site',
bidfloor: 0.50,
ifa: 'AAAAAAAAA-BBBB-CCCC-1111-222222220000',
}
})).to.equal(true);
});

it('Verifies user syncs iframe', function () {
Expand Down

0 comments on commit 24c4fb8

Please sign in to comment.