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

YIELDONE adapter - support Video #3227

Merged
merged 22 commits into from
Nov 1, 2018
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: 27 additions & 9 deletions modules/yieldoneBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as utils from 'src/utils';
import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';

const BIDDER_CODE = 'yieldone';
const ENDPOINT_URL = '//y.one.impact-ad.jp/h_bid';
Expand All @@ -9,29 +10,38 @@ const USER_SYNC_URL = '//y.one.impact-ad.jp/push_sync';
export const spec = {
code: BIDDER_CODE,
aliases: ['y1'],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bid) {
return !!(bid.params.placementId);
},
buildRequests: function(validBidRequests) {
return validBidRequests.map(bidRequest => {
const params = bidRequest.params;
const sizes = utils.parseSizesInput(bidRequest.sizes)[0];
const width = sizes.split('x')[0];
const height = sizes.split('x')[1];
const placementId = params.placementId;
const cb = Math.floor(Math.random() * 99999999999);
const referrer = encodeURIComponent(utils.getTopWindowUrl());
const bidId = bidRequest.bidId;
const payload = {
v: 'hb1',
p: placementId,
w: width,
h: height,
cb: cb,
r: referrer,
uid: bidId,
t: 'i'
};

const videoMediaType = utils.deepAccess(bidRequest, 'mediaTypes.video');
if (bidRequest.mediaType === VIDEO || videoMediaType) {
const sizes = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize') || bidRequest.sizes;
const size = utils.parseSizesInput(sizes)[0];
payload.w = size.split('x')[0];
payload.h = size.split('x')[1];
} else if ((utils.isEmpty(bidRequest.mediaType) && utils.isEmpty(bidRequest.mediaTypes)) ||
(bidRequest.mediaType === BANNER || (bidRequest.mediaTypes && bidRequest.mediaTypes[BANNER]))) {
const sizes = utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes;
payload.sz = utils.parseSizesInput(sizes).join(',');
}

return {
method: 'GET',
url: ENDPOINT_URL,
Expand All @@ -47,12 +57,12 @@ export const spec = {
const height = response.height || 0;
const cpm = response.cpm * 1000 || 0;
if (width !== 0 && height !== 0 && cpm !== 0 && crid !== 0) {
const dealId = response.dealid || '';
const dealId = response.dealId || '';
const currency = response.currency || 'JPY';
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
const referrer = utils.getTopWindowUrl();
const bidResponse = {
requestId: bidRequest.data.uid,
requestId: response.uid,
cpm: cpm,
width: response.width,
height: response.height,
Expand All @@ -61,9 +71,17 @@ export const spec = {
currency: currency,
netRevenue: netRevenue,
ttl: config.getConfig('_bidderTimeout'),
referrer: referrer,
ad: response.adTag
referrer: referrer
};

if (response.adTag) {
bidResponse.mediaType = BANNER;
bidResponse.ad = response.adTag;
} else if (response.adm) {
bidResponse.mediaType = VIDEO;
bidResponse.vastXml = response.adm;
}

bidResponses.push(bidResponse);
}
return bidResponses;
Expand Down
50 changes: 38 additions & 12 deletions modules/yieldoneBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,46 @@ Maintainer: y1dev@platform-one.co.jp

Connect to YIELDONE for bids.

THE YIELDONE adapter requires setup and approval from the YIELDONE team. Please reach out to your account team or y1s@platform-one.co.jp for more information.
THE YIELDONE adapter requires setup and approval from the YIELDONE team.
Please reach out to your account team or y1s@platform-one.co.jp for more information.

Note: THE YIELDONE adapter do not support "multi-format" scenario... if both
banner and video are specified as mediatypes, YIELDONE will treat it as a video unit.

# Test Parameters
```
var adUnits = [{
code: 'banner-ad-div',
sizes: [[300, 250]],
bids: [{
bidder: 'yieldone',
params: {
placementId: '44082'
}
}]
}];
```javascript
var adUnits = [
// Banner adUnit
{
code: 'banner-div',
mediaTypes: {
banner: {
sizes: [[300, 250], [336, 280]]
}
},
bids: [{
bidder: 'yieldone',
params: {
placementId: '36891'
}
}]
},
// Video adUnit
{
code: 'video-div',
mediaTypes: {
video: {
playerSize: [[640, 480]],
context: 'outstream'
},
},
bids: [{
bidder: 'yieldone',
params: {
placementId: '41993'
}
}]
}
```

### Configuration
Expand Down
117 changes: 89 additions & 28 deletions test/spec/modules/yieldoneBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spec } from 'modules/yieldoneBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

const ENDPOINT = '//y.one.impact-ad.jp/h_bid';
const USER_SYNC_URL = '//y.one.impact-ad.jp/push_sync';

describe('yieldoneBidAdapter', function() {
const adapter = newBidder(spec);
Expand All @@ -11,12 +12,10 @@ describe('yieldoneBidAdapter', function() {
let bid = {
'bidder': 'yieldone',
'params': {
placementId: '44082'
placementId: '36891'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'sizes': [[300, 250], [336, 280]],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
Expand All @@ -43,25 +42,21 @@ describe('yieldoneBidAdapter', function() {
{
'bidder': 'yieldone',
'params': {
placementId: '44082'
placementId: '36891'
},
'adUnitCode': 'adunit-code1',
'sizes': [
[300, 250]
],
'sizes': [[300, 250], [336, 280]],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
},
{
'bidder': 'yieldone',
'params': {
placementId: '44337'
placementId: '47919'
},
'adUnitCode': 'adunit-code2',
'sizes': [
[300, 250]
],
'sizes': [[300, 250]],
'bidId': '382091349b149f"',
'bidderRequestId': '"1f9c98192de251"',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
Expand All @@ -79,18 +74,31 @@ describe('yieldoneBidAdapter', function() {
expect(request[0].url).to.equal(ENDPOINT);
expect(request[1].url).to.equal(ENDPOINT);
});

it('parameter sz has more than one size on banner requests', function () {
expect(request[0].data.sz).to.equal('300x250,336x280');
expect(request[1].data.sz).to.equal('300x250');
});

it('width and height should be set as separate parameters on outstream requests', function () {
const bidRequest = Object.assign({}, bidRequests[0]);
bidRequest.mediaTypes = {};
bidRequest.mediaTypes.video = {context: 'outstream'};
const request = spec.buildRequests([bidRequest]);
expect(request[0].data.w).to.equal('300');
expect(request[0].data.h).to.equal('250');
});
});

describe('interpretResponse', function () {
let bidRequest = [
let bidRequestBanner = [
{
'method': 'GET',
'url': '//y.one.impact-ad.jp/h_bid',
'data': {
'v': 'hb1',
'p': '44082',
'w': '300',
'h': '250',
'p': '36891',
'sz': '300x250,336x280',
'cb': 12892917383,
'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836',
'uid': '23beaa6af6cdde',
Expand All @@ -99,34 +107,89 @@ describe('yieldoneBidAdapter', function() {
}
];

let serverResponse = {
let serverResponseBanner = {
body: {
'adTag': '<!-- adtag -->',
'uid': '23beaa6af6cdde',
'height': 250,
'width': 300,
'cpm': 0.0536616,
'crid': '2494768',
'currency': 'JPY',
'statusMessage': 'Bid available',
'uid': '23beaa6af6cdde',
'width': 300,
'height': 250
'dealId': 'P1-FIX-7800-DSP-MON'
}
};

it('should get the correct bid response', function () {
it('should get the correct bid response for banner', function () {
let expectedResponse = [{
'requestId': '23beaa6af6cdde',
'cpm': 53.6616,
'width': 300,
'height': 250,
'creativeId': '2494768',
'dealId': '',
'dealId': 'P1-FIX-7800-DSP-MON',
'currency': 'JPY',
'netRevenue': true,
'ttl': 3000,
'referrer': '',
'mediaType': 'banner',
'ad': '<!-- adtag -->'
}];
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
let result = spec.interpretResponse(serverResponseBanner, bidRequestBanner[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType);
});

let serverResponseVideo = {
body: {
'uid': '23beaa6af6cdde',
'height': 360,
'width': 640,
'cpm': 0.0536616,
'dealId': 'P1-FIX-766-DSP-MON',
'crid': '2494768',
'currency': 'JPY',
'statusMessage': 'Bid available',
'adm': '<!-- vast -->'
}
};

let bidRequestVideo = [
{
'method': 'GET',
'url': '//y.one.impact-ad.jp/h_bid',
'data': {
'v': 'hb1',
'p': '41993',
'w': '640',
'h': '360',
'cb': 12892917383,
'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836',
'uid': '23beaa6af6cdde',
't': 'i'
}
}
];

it('should get the correct bid response for video', function () {
let expectedResponse = [{
'requestId': '23beaa6af6cdde',
'cpm': 53.6616,
'width': 640,
'height': 360,
'creativeId': '2494768',
'dealId': 'P1-FIX-7800-DSP-MON',
'currency': 'JPY',
'netRevenue': true,
'ttl': 3000,
'referrer': '',
'mediaType': 'video',
'vastXml': '<!-- vast -->'
}];
let result = spec.interpretResponse(serverResponseVideo, bidRequestVideo[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType);
});

it('handles empty bid response', function () {
Expand All @@ -140,14 +203,12 @@ describe('yieldoneBidAdapter', function() {
'cpm': 0
}
};
let result = spec.interpretResponse(response, bidRequest[0]);
let result = spec.interpretResponse(response, bidRequestBanner[0]);
expect(result.length).to.equal(0);
});
});

describe('getUserSyncs', function () {
const userSyncUrl = '//y.one.impact-ad.jp/push_sync';

it('handles empty sync options', function () {
expect(spec.getUserSyncs({})).to.be.empty;
});
Expand All @@ -156,7 +217,7 @@ describe('yieldoneBidAdapter', function() {
expect(spec.getUserSyncs({
'iframeEnabled': true
})).to.deep.equal([{
type: 'iframe', url: userSyncUrl
type: 'iframe', url: USER_SYNC_URL
}]);
});
});
Expand Down