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

[Synacormedia] adapter should use format for multi-size banner requests #5410

Merged
merged 11 commits into from
Jun 25, 2020
106 changes: 75 additions & 31 deletions modules/synacormediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,18 @@ export const spec = {
pos = 0;
}
const videoOrBannerKey = this.isVideoBid(bid) ? 'video' : 'banner';
getAdUnitSizes(bid)
.filter(size => BLOCKED_AD_SIZES.indexOf(size.join('x')) === -1)
.forEach((size, i) => {
if (!size || size.length != 2) {
return;
}
const size0 = size[0];
const size1 = size[1];
const imp = {
id: `${videoOrBannerKey.substring(0, 1)}${bid.bidId}-${size0}x${size1}`,
tagid: placementId
};
if (bidFloor !== null && !isNaN(bidFloor)) {
imp.bidfloor = bidFloor;
}
const adSizes = getAdUnitSizes(bid)
.filter(size => BLOCKED_AD_SIZES.indexOf(size.join('x')) === -1);

const videoOrBannerValue = {
w: size0,
h: size1,
pos
};
if (videoOrBannerKey === 'video') {
if (bid.mediaTypes.video) {
this.setValidVideoParams(bid.mediaTypes.video, bid.params.video);
}
if (bid.params.video) {
this.setValidVideoParams(bid.params.video, videoOrBannerValue);
}
}
imp[videoOrBannerKey] = videoOrBannerValue;
openRtbBidRequest.imp.push(imp);
});
let imps = [];
if (videoOrBannerKey === 'banner') {
imps = this.buildBannerImpressions(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey);
} else if (videoOrBannerKey === 'video') {
imps = this.buildVideoImpressions(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey);
}
if (imps.length > 0) {
imps.forEach(i => openRtbBidRequest.imp.push(i));
}
});

if (openRtbBidRequest.imp.length && seatId) {
Expand All @@ -118,6 +98,70 @@ export const spec = {
}
},

buildBannerImpressions: function(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey) {
let format = [];
let imps = [];
adSizes.forEach((size, i) => {
if (!size || size.length !== 2) {
return;
}

format.push({
w: size[0],
h: size[1],
});
});

if (format.length > 0) {
const imp = {
id: `${videoOrBannerKey.substring(0, 1)}${bid.bidId}`,
banner: {
format,
pos
},
tagid: placementId,
};
if (bidFloor !== null && !isNaN(bidFloor)) {
imp.bidfloor = bidFloor;
}
imps.push(imp);
}
return imps;
},

buildVideoImpressions: function(adSizes, bid, placementId, pos, bidFloor, videoOrBannerKey) {
let imps = [];
adSizes.forEach((size, i) => {
if (!size || size.length != 2) {
return;
}
const size0 = size[0];
const size1 = size[1];
const imp = {
id: `${videoOrBannerKey.substring(0, 1)}${bid.bidId}-${size0}x${size1}`,
tagid: placementId
};
if (bidFloor !== null && !isNaN(bidFloor)) {
imp.bidfloor = bidFloor;
}

const videoOrBannerValue = {
w: size0,
h: size1,
pos
};
if (bid.mediaTypes.video) {
this.setValidVideoParams(bid.mediaTypes.video, bid.params.video);
}
if (bid.params.video) {
this.setValidVideoParams(bid.params.video, videoOrBannerValue);
}
imp[videoOrBannerKey] = videoOrBannerValue;
imps.push(imp);
});
return imps;
},

setValidVideoParams: function (sourceObj, destObj) {
Object.keys(sourceObj)
.filter(param => includes(VIDEO_PARAMS, param) && sourceObj[param] !== null && (!isNaN(parseInt(sourceObj[param], 10)) || !(sourceObj[param].length < 1)))
Expand Down
6 changes: 4 additions & 2 deletions modules/synacormediaBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ https://track.technoratimedia.com/openrtb/tags?ID=%%PATTERN:hb_cache_id_synacorm
code: 'test-div2',
mediaTypes: {
video: {
context: 'instream',
playerSize: [[300, 250]],
context: 'instream',
playerSize: [
[300, 250]
],
}
},
bids: [{
Expand Down
112 changes: 69 additions & 43 deletions test/spec/modules/synacormediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ describe('synacormediaBidAdapter ', function () {
},
mediaTypes: {
banner: {
h: 600,
pos: 0,
w: 300,
format: [
{
w: 300,
h: 600
}
],
pos: 0
}
},
};
Expand Down Expand Up @@ -173,21 +177,19 @@ describe('synacormediaBidAdapter ', function () {

let expectedDataImp1 = {
banner: {
h: 250,
pos: 0,
w: 300,
},
id: 'b9876abcd-300x250',
tagid: '1234',
bidfloor: 0.5
};
let expectedDataImp2 = {
banner: {
h: 600,
pos: 0,
w: 300,
format: [
{
h: 250,
w: 300
},
{
h: 600,
w: 300
}
],
pos: 0
},
id: 'b9876abcd-300x600',
id: 'b9876abcd',
tagid: '1234',
bidfloor: 0.5
};
Expand All @@ -201,7 +203,7 @@ describe('synacormediaBidAdapter ', function () {
expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?');
expect(req.data).to.exist.and.to.be.an('object');
expect(req.data.id).to.equal('xyz123');
expect(req.data.imp).to.eql([expectedDataImp1, expectedDataImp2]);
expect(req.data.imp).to.eql([expectedDataImp1]);

// video test
let reqVideo = spec.buildRequests([validBidRequestVideo], bidderRequestVideo);
Expand Down Expand Up @@ -230,13 +232,17 @@ describe('synacormediaBidAdapter ', function () {
expect(req).to.have.property('url');
expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?');
expect(req.data.id).to.equal('xyz123');
expect(req.data.imp).to.eql([expectedDataImp1, expectedDataImp2, {
expect(req.data.imp).to.eql([expectedDataImp1, {
banner: {
h: 600,
pos: 0,
w: 300,
format: [
{
h: 600,
w: 300
}
],
pos: 0
},
id: 'bfoobar-300x600',
id: 'bfoobar',
tagid: '5678',
bidfloor: 0.5
}]);
Expand All @@ -260,11 +266,15 @@ describe('synacormediaBidAdapter ', function () {
expect(req.data.imp).to.eql([
{
banner: {
h: 250,
pos: 0,
w: 300,
format: [
{
h: 250,
w: 300
}
],
pos: 0
},
id: 'bfoobar-300x250',
id: 'bfoobar',
tagid: '5678',
bidfloor: 0.5
}
Expand All @@ -289,11 +299,15 @@ describe('synacormediaBidAdapter ', function () {
expect(req.data.imp).to.eql([
{
banner: {
h: 250,
pos: 0,
w: 300,
format: [
{
h: 250,
w: 300
}
],
pos: 0
},
id: 'b9876abcd-300x250',
id: 'b9876abcd',
tagid: '1234',
}
]);
Expand All @@ -316,11 +330,15 @@ describe('synacormediaBidAdapter ', function () {
expect(req.data.imp).to.eql([
{
banner: {
h: 250,
pos: 0,
w: 300,
format: [
{
h: 250,
w: 300
}
],
pos: 0
},
id: 'b9876abcd-300x250',
id: 'b9876abcd',
tagid: '1234',
}
]);
Expand All @@ -344,11 +362,15 @@ describe('synacormediaBidAdapter ', function () {
expect(req.data.imp).to.eql([
{
banner: {
h: 250,
w: 300,
pos: 1,
format: [
{
h: 250,
w: 300
}
],
pos: 1
},
id: 'b9876abcd-300x250',
id: 'b9876abcd',
tagid: '1234'
}
]);
Expand All @@ -371,11 +393,15 @@ describe('synacormediaBidAdapter ', function () {
expect(req.data.imp).to.eql([
{
banner: {
h: 250,
w: 300,
pos: 0,
format: [
{
h: 250,
w: 300
}
],
pos: 0
},
id: 'b9876abcd-300x250',
id: 'b9876abcd',
tagid: '1234'
}
]);
Expand Down