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

OMS Bid Adapter: add video support, test coverage and update documentation #12671

Merged
merged 1 commit into from
Jan 22, 2025
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
36 changes: 25 additions & 11 deletions modules/omsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
formatQS,
} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {ajax} from '../src/ajax.js';
import {percentInView} from '../libraries/percentInView/percentInView.js';
import {getUserSyncParams} from '../libraries/userSyncUtils/userSyncUtils.js';
Expand All @@ -27,7 +27,7 @@ export const spec = {
code: BIDDER_CODE,
aliases: ['brightcom', 'bcmssp'],
gvlid: 883,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid,
buildRequests,
interpretResponse,
Expand All @@ -39,7 +39,7 @@ export const spec = {
function buildRequests(bidReqs, bidderRequest) {
try {
const impressions = bidReqs.map(bid => {
let bidSizes = bid?.mediaTypes?.banner?.sizes || bid.sizes;
let bidSizes = bid?.mediaTypes?.banner?.sizes || bid?.mediaTypes?.video?.playerSize || bid.sizes;
bidSizes = ((isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes]);
bidSizes = bidSizes.filter(size => isArray(size));
const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}));
Expand All @@ -52,18 +52,25 @@ function buildRequests(bidReqs, bidderRequest) {

const imp = {
id: bid.bidId,
banner: {
format: processedSizes,
ext: {
viewability: viewabilityAmountRounded,
}
},
ext: {
...gpidData
},
tagid: String(bid.adUnitCode)
};

if (bid?.mediaTypes?.video) {
imp.video = {
...bid.mediaTypes.video,
}
} else {
imp.banner = {
format: processedSizes,
ext: {
viewability: viewabilityAmountRounded,
}
}
}

const bidFloor = _getBidFloor(bid);

if (bidFloor) {
Expand Down Expand Up @@ -158,21 +165,28 @@ function interpretResponse(serverResponse) {
try {
if (id && seatbid && seatbid.length > 0 && seatbid[0].bid && seatbid[0].bid.length > 0) {
response = seatbid[0].bid.map(bid => {
return {
const bidResponse = {
requestId: bid.impid,
cpm: parseFloat(bid.price),
width: parseInt(bid.w),
height: parseInt(bid.h),
creativeId: bid.crid || bid.id,
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: _getAdMarkup(bid),
ttl: 300,
meta: {
advertiserDomains: bid?.adomain || []
}
};

if (bid.mtype === 2) {
bidResponse.mediaType = VIDEO;
} else {
bidResponse.mediaType = BANNER;
}

return bidResponse;
});
}
} catch (e) {
Expand Down
15 changes: 15 additions & 0 deletions modules/omsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ var adUnits = [
publisherId: 2141020
}
}]
},
{
code: 'video-instream',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480]
}
},
bids: [{
bidder: 'oms',
params: {
publisherId: 2141020
}
}]
}
]
```
78 changes: 78 additions & 0 deletions test/spec/modules/omsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,45 @@ describe('omsBidAdapter', function () {
expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]);
});

it('sets the proper video object when ad unit media type is video', function () {
const bidRequests = [
{
'bidder': 'oms',
'params': {
'publisherId': 1234567
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'video': {
'context': 'instream',
'playerSize': [640, 480]
}
},
'bidId': '5fb26ac22bde4',
'bidderRequestId': '4bf93aeb730cb9',
'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e',
'schain': {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.com',
'sid': '1234',
'hp': 1,
'rid': 'bid-request-1',
'name': 'publisher',
'domain': 'publisher.com'
}
]
},
}
]
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.imp[0].video.context).to.equal('instream');
expect(payload.imp[0].video.playerSize).to.deep.equal([640, 480]);
});

it('accepts a single array as a size', function () {
bidRequests[0].mediaTypes.banner.sizes = [300, 250];
const request = spec.buildRequests(bidRequests);
Expand Down Expand Up @@ -379,6 +418,45 @@ describe('omsBidAdapter', function () {
expect(result[0]).to.deep.equal(expectedResponse[0]);
});

it('should get the correct bid response for video bids', function () {
let expectedResponse = [{
'requestId': '283a9f4cd2415d',
'cpm': 0.35743275,
'width': 300,
'height': 250,
'creativeId': '376874781',
'currency': 'USD',
'netRevenue': true,
'mediaType': 'video',
'ad': `<!-- Creative --><div style="position:absolute;left:0px;top:0px;visibility:hidden;"><img src="${encodeURI('<!-- NURL -->')}"></div>`,
'ttl': 300,
'meta': {
'advertiserDomains': ['example.com']
}
}];
const response = {
body: {
'id': '37386aade21a71',
'seatbid': [{
'bid': [{
'id': '376874781',
'impid': '283a9f4cd2415d',
'price': 0.35743275,
'nurl': '<!-- NURL -->',
'adm': '<!-- Creative -->',
'w': 300,
'h': 250,
'adomain': ['example.com'],
'mtype': 2
}]
}]
}
};

let result = spec.interpretResponse(response);
expect(result[0]).to.deep.equal(expectedResponse[0]);
});

it('crid should default to the bid id if not on the response', function () {
let expectedResponse = [{
'requestId': '283a9f4cd2415d',
Expand Down
Loading