Skip to content

Commit

Permalink
Michao Bid Adapter: Support for native format
Browse files Browse the repository at this point in the history
  • Loading branch information
hogekai committed Dec 2, 2024
1 parent 522b79d commit d8313fc
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 15 deletions.
28 changes: 16 additions & 12 deletions modules/michaoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';
import {
deepSetValue,
Expand All @@ -13,7 +13,7 @@ import {

const ENV = {
BIDDER_CODE: 'michao',
SUPPORTED_MEDIA_TYPES: [BANNER, VIDEO],
SUPPORTED_MEDIA_TYPES: [BANNER, VIDEO, NATIVE],
ENDPOINT: 'https://rtb.michao-ssp.com/openrtb/prebid',
NET_REVENUE: true,
DEFAULT_CURRENCY: 'USD',
Expand Down Expand Up @@ -42,19 +42,19 @@ export const spec = {
const bidRequests = [];

validBidRequests.forEach((validBidRequest) => {
if (
hasVideoMediaType(validBidRequest) &&
hasBannerMediaType(validBidRequest)
) {
if (hasVideoMediaType(validBidRequest)) {
bidRequests.push(buildRequest(validBidRequest, bidderRequest, 'video'));
}

if (hasBannerMediaType(validBidRequest)) {
bidRequests.push(
buildRequest(validBidRequest, bidderRequest, 'banner')
);
bidRequests.push(buildRequest(validBidRequest, bidderRequest, 'video'));
} else if (hasVideoMediaType(validBidRequest)) {
bidRequests.push(buildRequest(validBidRequest, bidderRequest, 'video'));
} else if (hasBannerMediaType(validBidRequest)) {
}

if (hasNativeMediaType(validBidRequest)) {
bidRequests.push(
buildRequest(validBidRequest, bidderRequest, 'banner')
buildRequest(validBidRequest, bidderRequest, 'native')
);
}
});
Expand Down Expand Up @@ -184,7 +184,7 @@ const converter = ortbConverter({
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
deepSetValue(imp, 'ext.placement', bidRequest.params.placement.toString());
deepSetValue(imp, 'rwdd', bidRequest.params?.reward ? 1 : false);
deepSetValue(imp, 'rwdd', bidRequest.params?.reward ? 1 : 0);

return imp;
},
Expand Down Expand Up @@ -223,6 +223,10 @@ function hasVideoMediaType(bid) {
return hasMediaType(bid, 'video');
}

function hasNativeMediaType(bid) {
return hasMediaType(bid, 'native');
}

function hasMediaType(bid, mediaType) {
return bid.mediaTypes.hasOwnProperty(mediaType);
}
Expand Down
86 changes: 83 additions & 3 deletions test/spec/modules/michaoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,58 @@ describe('the michao bidder adapter', () => {
});
});

it('Native bid requests are converted to video server request objects', () => {
const nativeBidRequest = {
adUnitCode: 'test-div',
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidId: '22c4871113f461',
bidder: 'michao',
bidderRequestId: '15246a574e859f',
bidRequestsCount: 1,
bidderRequestsCount: 1,
bidderWinsCount: 0,
mediaTypes: {
native: {
ortb: {
assets: [
{
id: 2,
required: 1,
title: {
len: 80
}
}
]
}
}
},
params: {
site: 123,
placement: 456,
},
};
const bidderRequest = {
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
auctionStart: 1579746300522,
bidderCode: 'michao',
bidderRequestId: '15246a574e859f',
bids: [nativeBidRequest],
};

const result = buildRequest(nativeBidRequest, bidderRequest, 'native');

expect(result).to.nested.include({
url: 'https://rtb.michao-ssp.com/openrtb/prebid',
'options.contentType': 'application/json',
'options.withCredentials': true,
method: 'POST',
'data.cur[0]': 'USD',
'data.imp[0].ext.placement': '456',
'data.site.id': '123',
'data.test': 0,
});
});

it('Converted to server request object for testing in debug mode', () => {
const bidRequest = {
adUnitCode: 'test-div',
Expand Down Expand Up @@ -467,8 +519,36 @@ describe('the michao bidder adapter', () => {
bidder: 'michao',
bidderRequestId: 'bidder-request-2',
mediaTypes: {
banner: {
sizes: [[300, 250]],
video: {
context: 'outstream',
playerSize: [640, 480],
mimes: ['video/mp4'],
},
},
params: {
site: 12,
placement: 12,
},
},
{
adUnitCode: 'test-div',
auctionId: 'auction-2',
bidId: 'bid-2',
bidder: 'michao',
bidderRequestId: 'bidder-request-2',
mediaTypes: {
native: {
ortb: {
assets: [
{
id: 2,
required: 1,
title: {
len: 80
}
}
]
}
},
},
params: {
Expand All @@ -486,7 +566,7 @@ describe('the michao bidder adapter', () => {

const result = spec.buildRequests(validBidRequests, bidderRequest);

expect(result.length).to.equal(2);
expect(result.length).to.equal(3);
});

it('`interpretResponse`', () => {
Expand Down

0 comments on commit d8313fc

Please sign in to comment.