Skip to content

Commit 1032bd2

Browse files
committed
Update conversant adapter support for video playerSize
1 parent bbc6316 commit 1032bd2

File tree

3 files changed

+129
-42
lines changed

3 files changed

+129
-42
lines changed

modules/conversantBidAdapter.js

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BANNER, VIDEO } from 'src/mediaTypes';
44

55
const BIDDER_CODE = 'conversant';
66
const URL = '//web.hb.ad.cpe.dotomi.com/s2s/header/24';
7-
const VERSION = '2.2.3';
7+
const VERSION = '2.2.4';
88

99
export const spec = {
1010
code: BIDDER_CODE,
@@ -62,8 +62,6 @@ export const spec = {
6262
siteId = utils.getBidIdParameter('site_id', bid.params);
6363
requestId = bid.auctionId;
6464

65-
let format = convertSizes(bid.sizes);
66-
6765
const imp = {
6866
id: bid.bidId,
6967
secure: secure,
@@ -72,29 +70,31 @@ export const spec = {
7270
displaymanagerver: VERSION
7371
};
7472

75-
copyOptProperty(bid.params, 'tag_id', imp, 'tagid');
73+
copyOptProperty(bid.params.tag_id, imp, 'tagid');
7674

7775
if (isVideoRequest(bid)) {
78-
if (bid.mediaTypes.video.playerSize) {
79-
format = convertSizes(bid.mediaTypes.video.playerSize);
80-
}
76+
const videoData = utils.deepAccess(bid, 'mediaTypes.video') || {};
77+
const format = convertSizes(videoData.playerSize || bid.sizes);
78+
const video = {};
8179

82-
const video = {
83-
w: format[0].w,
84-
h: format[0].h
85-
};
80+
if (format && format[0]) {
81+
copyOptProperty(format[0].w, video, 'w');
82+
copyOptProperty(format[0].h, video, 'h');
83+
}
8684

87-
copyOptProperty(bid.params, 'position', video, 'pos');
88-
copyOptProperty(bid.params, 'mimes', video);
89-
copyOptProperty(bid.params, 'maxduration', video);
90-
copyOptProperty(bid.params, 'protocols', video);
91-
copyOptProperty(bid.params, 'api', video);
85+
copyOptProperty(bid.params.position, video, 'pos');
86+
copyOptProperty(bid.params.mimes || videoData.mimes, video, 'mimes');
87+
copyOptProperty(bid.params.maxduration, video, 'maxduration');
88+
copyOptProperty(bid.params.protocols || videoData.protocols, video, 'protocols');
89+
copyOptProperty(bid.params.api || videoData.api, video, 'api');
9290

9391
imp.video = video;
9492
} else {
93+
const bannerData = utils.deepAccess(bid, 'mediaTypes.banner') || {};
94+
const format = convertSizes(bannerData.sizes || bid.sizes);
9595
const banner = {format: format};
9696

97-
copyOptProperty(bid.params, 'position', banner, 'pos');
97+
copyOptProperty(bid.params.position, banner, 'pos');
9898

9999
imp.banner = banner;
100100
}
@@ -253,11 +253,12 @@ function getDevice() {
253253
*/
254254
function convertSizes(bidSizes) {
255255
let format;
256-
257-
if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') {
258-
format = [{w: bidSizes[0], h: bidSizes[1]}];
259-
} else {
260-
format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; });
256+
if (Array.isArray(bidSizes)) {
257+
if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') {
258+
format = [{w: bidSizes[0], h: bidSizes[1]}];
259+
} else {
260+
format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; });
261+
}
261262
}
262263

263264
return format;
@@ -276,16 +277,13 @@ function isVideoRequest(bid) {
276277
/**
277278
* Copy property if exists from src to dst
278279
*
279-
* @param {object} src
280-
* @param {string} srcName
281-
* @param {object} dst
282-
* @param {string} [dstName] - Optional. If not specified then srcName is used.
280+
* @param {object} src - source object
281+
* @param {object} dst - destination object
282+
* @param {string} dstName - destination property name
283283
*/
284-
function copyOptProperty(src, srcName, dst, dstName) {
285-
dstName = dstName || srcName;
286-
const obj = utils.getBidIdParameter(srcName, src);
287-
if (obj !== '') {
288-
dst[dstName] = obj;
284+
function copyOptProperty(src, dst, dstName) {
285+
if (src) {
286+
dst[dstName] = src;
289287
}
290288
}
291289

modules/conversantBidAdapter.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var adUnits = [
2222
}]
2323
},{
2424
code: 'video-test-div',
25-
sizes: [640, 480],
2625
mediaTypes: {
2726
video: {
2827
context: 'instream',
@@ -32,7 +31,7 @@ var adUnits = [
3231
bids: [{
3332
bidder: "conversant",
3433
params: {
35-
site_id: '88563',
34+
site_id: '108060',
3635
api: [2],
3736
protocols: [1, 2],
3837
mimes: ['video/mp4']

test/spec/modules/conversantBidAdapter_spec.js

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('Conversant adapter tests', function() {
88
const siteId = '108060';
99

1010
const bidRequests = [
11+
// banner with single size
1112
{
1213
bidder: 'conversant',
1314
params: {
@@ -23,19 +24,27 @@ describe('Conversant adapter tests', function() {
2324
bidId: 'bid000',
2425
bidderRequestId: '117d765b87bed38',
2526
auctionId: 'req000'
26-
}, {
27+
},
28+
// banner with sizes in mediaTypes.banner.sizes
29+
{
2730
bidder: 'conversant',
2831
params: {
2932
site_id: siteId,
3033
secure: false
3134
},
35+
mediaTypes: {
36+
banner: {
37+
sizes: [[728, 90], [468, 60]]
38+
}
39+
},
3240
placementCode: 'pcode001',
3341
transactionId: 'tx001',
34-
sizes: [[468, 60]],
3542
bidId: 'bid001',
3643
bidderRequestId: '117d765b87bed38',
3744
auctionId: 'req000'
38-
}, {
45+
},
46+
// banner with tag id and position
47+
{
3948
bidder: 'conversant',
4049
params: {
4150
site_id: siteId,
@@ -49,7 +58,9 @@ describe('Conversant adapter tests', function() {
4958
bidId: 'bid002',
5059
bidderRequestId: '117d765b87bed38',
5160
auctionId: 'req000'
52-
}, {
61+
},
62+
// video with single size
63+
{
5364
bidder: 'conversant',
5465
params: {
5566
site_id: siteId,
@@ -70,6 +81,47 @@ describe('Conversant adapter tests', function() {
7081
bidId: 'bid003',
7182
bidderRequestId: '117d765b87bed38',
7283
auctionId: 'req000'
84+
},
85+
// video with playerSize
86+
{
87+
bidder: 'conversant',
88+
params: {
89+
site_id: siteId,
90+
maxduration: 30,
91+
api: [2, 3]
92+
},
93+
mediaTypes: {
94+
video: {
95+
context: 'instream',
96+
playerSize: [1024, 768],
97+
api: [1, 2],
98+
protocols: [1, 2, 3],
99+
mimes: ['video/mp4', 'video/x-flv']
100+
}
101+
},
102+
placementCode: 'pcode004',
103+
transactionId: 'tx004',
104+
bidId: 'bid004',
105+
bidderRequestId: '117d765b87bed38',
106+
auctionId: 'req000'
107+
},
108+
// video without sizes
109+
{
110+
bidder: 'conversant',
111+
params: {
112+
site_id: siteId
113+
},
114+
mediaTypes: {
115+
video: {
116+
context: 'instream',
117+
mimes: ['video/mp4', 'video/x-flv']
118+
}
119+
},
120+
placementCode: 'pcode005',
121+
transactionId: 'tx005',
122+
bidId: 'bid005',
123+
bidderRequestId: '117d765b87bed38',
124+
auctionId: 'req000'
73125
}];
74126

75127
const bidResponses = {
@@ -129,6 +181,8 @@ describe('Conversant adapter tests', function() {
129181
expect(spec.isBidRequestValid(bidRequests[1])).to.be.true;
130182
expect(spec.isBidRequestValid(bidRequests[2])).to.be.true;
131183
expect(spec.isBidRequestValid(bidRequests[3])).to.be.true;
184+
expect(spec.isBidRequestValid(bidRequests[4])).to.be.true;
185+
expect(spec.isBidRequestValid(bidRequests[5])).to.be.true;
132186

133187
const simpleVideo = JSON.parse(JSON.stringify(bidRequests[3]));
134188
simpleVideo.params.site_id = 123;
@@ -151,7 +205,7 @@ describe('Conversant adapter tests', function() {
151205
expect(payload).to.have.property('id', 'req000');
152206
expect(payload).to.have.property('at', 1);
153207
expect(payload).to.have.property('imp');
154-
expect(payload.imp).to.be.an('array').with.lengthOf(4);
208+
expect(payload.imp).to.be.an('array').with.lengthOf(6);
155209

156210
expect(payload.imp[0]).to.have.property('id', 'bid000');
157211
expect(payload.imp[0]).to.have.property('secure', 0);
@@ -169,18 +223,18 @@ describe('Conversant adapter tests', function() {
169223
expect(payload.imp[1]).to.have.property('secure', 0);
170224
expect(payload.imp[1]).to.have.property('bidfloor', 0);
171225
expect(payload.imp[1]).to.have.property('displaymanager', 'Prebid.js');
172-
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
226+
expect(payload.imp[1]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
173227
expect(payload.imp[1]).to.not.have.property('tagid');
174228
expect(payload.imp[1]).to.have.property('banner');
175229
expect(payload.imp[1].banner).to.not.have.property('pos');
176230
expect(payload.imp[1].banner).to.have.property('format');
177-
expect(payload.imp[1].banner.format).to.deep.equal([{w: 468, h: 60}]);
231+
expect(payload.imp[1].banner.format).to.deep.equal([{w: 728, h: 90}, {w: 468, h: 60}]);
178232

179233
expect(payload.imp[2]).to.have.property('id', 'bid002');
180234
expect(payload.imp[2]).to.have.property('secure', 0);
181235
expect(payload.imp[2]).to.have.property('bidfloor', 0);
182236
expect(payload.imp[2]).to.have.property('displaymanager', 'Prebid.js');
183-
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
237+
expect(payload.imp[2]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
184238
expect(payload.imp[2]).to.have.property('banner');
185239
expect(payload.imp[2].banner).to.have.property('pos', 2);
186240
expect(payload.imp[2].banner).to.have.property('format');
@@ -190,7 +244,7 @@ describe('Conversant adapter tests', function() {
190244
expect(payload.imp[3]).to.have.property('secure', 0);
191245
expect(payload.imp[3]).to.have.property('bidfloor', 0);
192246
expect(payload.imp[3]).to.have.property('displaymanager', 'Prebid.js');
193-
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
247+
expect(payload.imp[3]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
194248
expect(payload.imp[3]).to.not.have.property('tagid');
195249
expect(payload.imp[3]).to.have.property('video');
196250
expect(payload.imp[3].video).to.not.have.property('pos');
@@ -205,6 +259,42 @@ describe('Conversant adapter tests', function() {
205259
expect(payload.imp[3].video).to.have.property('maxduration', 30);
206260
expect(payload.imp[3]).to.not.have.property('banner');
207261

262+
expect(payload.imp[4]).to.have.property('id', 'bid004');
263+
expect(payload.imp[4]).to.have.property('secure', 0);
264+
expect(payload.imp[4]).to.have.property('bidfloor', 0);
265+
expect(payload.imp[4]).to.have.property('displaymanager', 'Prebid.js');
266+
expect(payload.imp[4]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
267+
expect(payload.imp[4]).to.not.have.property('tagid');
268+
expect(payload.imp[4]).to.have.property('video');
269+
expect(payload.imp[4].video).to.not.have.property('pos');
270+
expect(payload.imp[4].video).to.have.property('w', 1024);
271+
expect(payload.imp[4].video).to.have.property('h', 768);
272+
expect(payload.imp[4].video).to.have.property('mimes');
273+
expect(payload.imp[4].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']);
274+
expect(payload.imp[4].video).to.have.property('protocols');
275+
expect(payload.imp[4].video.protocols).to.deep.equal([1, 2, 3]);
276+
expect(payload.imp[4].video).to.have.property('api');
277+
expect(payload.imp[4].video.api).to.deep.equal([2, 3]);
278+
expect(payload.imp[4].video).to.have.property('maxduration', 30);
279+
expect(payload.imp[4]).to.not.have.property('banner');
280+
281+
expect(payload.imp[5]).to.have.property('id', 'bid005');
282+
expect(payload.imp[5]).to.have.property('secure', 0);
283+
expect(payload.imp[5]).to.have.property('bidfloor', 0);
284+
expect(payload.imp[5]).to.have.property('displaymanager', 'Prebid.js');
285+
expect(payload.imp[5]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
286+
expect(payload.imp[5]).to.not.have.property('tagid');
287+
expect(payload.imp[5]).to.have.property('video');
288+
expect(payload.imp[5].video).to.not.have.property('pos');
289+
expect(payload.imp[5].video).to.not.have.property('w');
290+
expect(payload.imp[5].video).to.not.have.property('h');
291+
expect(payload.imp[5].video).to.have.property('mimes');
292+
expect(payload.imp[5].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']);
293+
expect(payload.imp[5].video).to.not.have.property('protocols');
294+
expect(payload.imp[5].video).to.not.have.property('api');
295+
expect(payload.imp[5].video).to.not.have.property('maxduration');
296+
expect(payload.imp[5]).to.not.have.property('banner');
297+
208298
expect(payload).to.have.property('site');
209299
expect(payload.site).to.have.property('id', siteId);
210300
expect(payload.site).to.have.property('mobile').that.is.oneOf([0, 1]);

0 commit comments

Comments
 (0)