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

Viqeo Bid Adapter: updated endpoint #12338

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
147 changes: 84 additions & 63 deletions modules/viqeoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {logError, logInfo, _each, mergeDeep, isFn, isNumber, isPlainObject} from '../src/utils.js'
import {VIDEO} from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import {
logError,
logInfo,
_each,
mergeDeep,
isFn,
isNumber,
isPlainObject,
} from '../src/utils.js';
import { VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand All @@ -12,36 +20,48 @@ import {Renderer} from '../src/Renderer.js';
*/

const BIDDER_CODE = 'viqeo';
const DEFAULT_MIMES = ['application/javascript'];
const VIQEO_ENDPOINT = 'https://ads.betweendigital.com/openrtb_bid';
const DEFAULT_MIMES = [
'video/3gpp',
'video/mp4',
'video/mpeg',
'video/webm',
'application/javascript',
];
const VIQEO_ENDPOINT = 'https://ad.vqserve.com/ads/prebid';
const RENDERER_URL = 'https://cdn.viqeo.tv/js/vq_starter.js';
const DEFAULT_CURRENCY = 'USD';
const DEFAULT_SSPID = 44697;

function getBidFloor(bid) {
const {floor, currency} = bid.params;
const { floor, currency } = bid.params;
const curr = currency || DEFAULT_CURRENCY;
if (!isFn(bid.getFloor)) {
return {floor: isNumber(floor) ? floor : 0, currency: curr};
return { floor: isNumber(floor) ? floor : 0, currency: curr };
}
const floorInfo = bid.getFloor({currency: curr, mediaType: VIDEO, size: '*'});
if (isPlainObject(floorInfo) && isNumber(floorInfo.floor) && floorInfo.currency === curr) {
const floorInfo = bid.getFloor({
currency: curr,
mediaType: VIDEO,
size: '*',
});
if (
isPlainObject(floorInfo) &&
isNumber(floorInfo.floor) &&
floorInfo.currency === curr
) {
return floorInfo;
}
return {floor: floor || 0, currency: currency || DEFAULT_CURRENCY};
return { floor: floor || 0, currency: currency || DEFAULT_CURRENCY };
}

function getVideoTargetingParams({mediaTypes: {video}}) {
function getVideoTargetingParams({ mediaTypes: { video } }) {
const result = {};
Object.keys(Object(video))
.forEach(key => {
if (key === 'playerSize') {
result.w = video.playerSize[0][0];
result.h = video.playerSize[0][1];
} else if (key !== 'context') {
result[key] = video[key];
}
})
Object.keys(Object(video)).forEach((key) => {
if (key === 'playerSize') {
result.w = video.playerSize[0][0];
result.h = video.playerSize[0][1];
} else if (key !== 'context') {
result[key] = video[key];
}
});
return result;
}

Expand All @@ -55,20 +75,20 @@ export const spec = {
* @param {BidRequest} bidRequest The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: ({params}) => {
isBidRequestValid: ({ params }) => {
if (!params) {
logError('failed validation: params not declared');
return false;
}
if (!params.user && !params.user?.buyeruid) {
logError('failed validation: user.buyeruid not declared');
if (!params.tagId) {
logError('failed validation: tagId not declared');
return false;
}
if (!params.playerOptions) {
logError('failed validation: playerOptions not declared');
return false;
}
const {profileId, videoId, playerId} = params.playerOptions;
const { profileId, videoId, playerId } = params.playerOptions;
if (!profileId) {
logError('failed validation: profileId not declared');
return false;
Expand All @@ -88,46 +108,42 @@ export const spec = {
const bidRequests = [];
_each(validBidRequests, (bid, i) => {
const {
params: {test, sspId, endpointUrl},
mediaTypes: {video},
params: { test, tagId, endpointUrl, bcat, badv },
mediaTypes: { video },
} = bid;
const ortb2 = bid.ortb2 || {};
const user = bid.params.user || {};
const device = bid.params.device || {};
const site = bid.params.site || {};
const w = window;
const floorInfo = getBidFloor(bid);

const data = {
id: bid.bidId,
test,
imp: [{
id: `${i}`,
tagid: bid.adUnitCode,
video: {
...getVideoTargetingParams(bid),
mimes: video.mimes || DEFAULT_MIMES,
imp: [
{
id: `${i}`,
video: {
...getVideoTargetingParams(bid),
mimes: video.mimes || DEFAULT_MIMES,
},
tagid: `${tagId}`,
bidfloor: floorInfo.floor,
bidfloorcur: floorInfo.currency,
secure: 1,
},
bidfloor: floorInfo.floor,
bidfloorcur: floorInfo.currency,
secure: 1
}],
site: test === 1 ? {
page: 'https://viqeo.tv',
domain: 'viqeo.tv'
} : mergeDeep({
domain: w.location.hostname,
page: w.location.href
}, ortb2.site, site),
device: mergeDeep({
w: w.screen.width,
h: w.screen.height,
ua: w.navigator.userAgent,
}, ortb2.device, device),
user: mergeDeep({...user}, ortb2.user),
app: bid.params.app,
],
site: mergeDeep(
site,
ortb2.site
),
device: mergeDeep(device, ortb2.device),
user: mergeDeep(user, ortb2.user),
bcat: ortb2.bcat || bcat,
badv: ortb2.badv || badv
};
bidRequests.push({
url: endpointUrl || `${VIQEO_ENDPOINT}/?sspId=${sspId || DEFAULT_SSPID}`,
url: endpointUrl || `${VIQEO_ENDPOINT}`,
method: 'POST',
data,
bids: validBidRequests,
Expand All @@ -148,24 +164,24 @@ export const spec = {
return [];
}
try {
const {id, seatbid, cur} = serverResponse.body;
const { id, seatbid, cur } = serverResponse.body;
_each(seatbid, (sb) => {
const {bid} = sb;
const { bid } = sb;
_each(bid, (b) => {
const bidRequest = bidRequests.bids.find(({bidId}) => bidId === id);
const bidRequest = bidRequests.bids.find(({ bidId }) => bidId === id);
const renderer = Renderer.install({
url: bidRequest?.params?.renderUrl || RENDERER_URL,
});
renderer.setRender((bid) => {
renderer.setRender((bid, doc) => {
if (window.VIQEO) {
window.VIQEO.renderPrebid(bid);
window.VIQEO.renderPrebid(bid, doc);
} else {
logError('failed get window.VIQEO');
}
});
bidResponses.push({
requestId: id,
currency: cur,
currency: cur || DEFAULT_CURRENCY,
cpm: b.price,
ttl: b.exp,
netRevenue: true,
Expand All @@ -176,13 +192,18 @@ export const spec = {
vastUrl: b.nurl,
mediaType: VIDEO,
renderer,
})
})
meta: {
secondaryCatIds: b.cat,
attr: b.attr,
advertiserDomains: b.adomain,
},
});
});
});
} catch (error) {
logError(error);
}
return bidResponses;
},
}
};
registerBidder(spec);
36 changes: 16 additions & 20 deletions modules/viqeoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ Viqeo Bidder Adapter for Prebid.js. About: https://viqeo.tv/
### Bid params

{: .table .table-bordered .table-striped }
| Name | Scope | Description | Example | Type |
|-----------------------------|----------|----------------------------------------------------------------------------------------------------------------------------|--------------------------|-----------|
| `user` | required | The object containing user data (See OpenRTB spec) | `user: {}` | `object` |
| `user.buyeruid` | required | User id | `"12345"` | `string` |
| `playerOptions` | required | The object containing Viqeo player options | `playerOptions: {}` | `object` |
| `playerOptions.profileId` | required | Viqeo profile id | `1382` | `number` |
| `playerOptions.videId` | optional | Viqeo video id | `"ed584da454c7205ca7e4"` | `string` |
| `playerOptions.playerId` | optional | Viqeo player id | `1` | `number` |
| `device` | optional | The object containing device data (See OpenRTB spec) | `device: {}` | `object` |
| `site` | optional | The object containing site data (See OpenRTB spec) | `site: {}` | `object` |
| `app` | optional | The object containing app data (See OpenRTB spec) | `app: {}` | `object` |
| `floor` | optional | Bid floor price | `0.5` | `number` |
| `currency` | optional | 3-letter ISO 4217 code defining the currency of the bid. | `EUR` | `string` |
| `test` | optional | Flag which will induce a sample bid response when true; only set to true for testing purposes (1 = true, 0 = false) | `1` | `integer` |
| `sspId` | optional | For debug, request id | `1` | `number` |
| `renderUrl` | optional | For debug, script player url | `"https://viqeo.tv"` | `string` |
| `endpointUrl` | optional | For debug, api endpoint | `"https://viqeo.tv"` | `string` |
| Name | Scope | Description | Example | Type |
|-----------------------------|----------|---------------------------------------------------------------------------------------------------------------------|--------------------------|-----------|
| `tagid` | required | The unique identifier of the ad placement. Could be obtained from the Viqeo UI or from your account manager. | `2` | `string` |
| `playerOptions` | required | The object containing Viqeo player options | `playerOptions: {}` | `object` |
| `playerOptions.profileId` | required | Viqeo profile id | `1382` | `number` |
| `playerOptions.videId` | optional | Viqeo video id | `"ed584da454c7205ca7e4"` | `string` |
| `playerOptions.playerId` | optional | Viqeo player id | `1` | `number` |
| `user` | optional | The object containing user data (See OpenRTB spec) | `user: {}` | `object` |
| `device` | optional | The object containing device data (See OpenRTB spec) | `device: {}` | `object` |
| `site` | optional | The object containing site data (See OpenRTB spec) | `site: {}` | `object` |
| `floor` | optional | Bid floor price | `0.5` | `number` |
| `currency` | optional | 3-letter ISO 4217 code defining the currency of the bid. | `EUR` | `string` |
| `test` | optional | Flag which will induce a sample bid response when true; only set to true for testing purposes (1 = true, 0 = false) | `1` | `integer` |
| `renderUrl` | optional | For debug, script player url | `"https://viqeo.tv"` | `string` |
| `endpointUrl` | optional | For debug, api endpoint | `"https://viqeo.tv"` | `string` |

# Test Parameters
```
Expand All @@ -42,9 +40,7 @@ Viqeo Bidder Adapter for Prebid.js. About: https://viqeo.tv/
bids: [{
bidder: 'viqeo',
params: {
user: {
buyeruid: '1',
},
tagId: '2',
playerOptions: {
videoId: 'ed584da454c7205ca7e4',
profileId: 1382,
Expand Down
13 changes: 4 additions & 9 deletions test/spec/modules/viqeoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ describe('viqeoBidAdapter', function () {
expect(spec.isBidRequestValid({
bidder: 'viqeo',
params: {
user: {
buyeruid: '1',
},
tagId: '2',
playerOptions: {
videoId: 'ed584da454c7205ca7e4',
profileId: 1382,
Expand All @@ -27,9 +25,7 @@ describe('viqeoBidAdapter', function () {
bidId: 'id1',
bidder: 'viqeo',
params: {
user: {
buyeruid: '1',
},
tagId: '2',
currency: 'EUR',
floor: 0.5,
playerOptions: {
Expand All @@ -48,7 +44,7 @@ describe('viqeoBidAdapter', function () {
expect(requestData.imp[0].bidfloor).to.equal(0.5);
expect(requestData.imp[0].video.w).to.equal(240);
expect(requestData.imp[0].video.h).to.equal(400);
expect(requestData.user.buyeruid).to.equal('1');
expect(requestData.imp[0].tagid).to.equal('2');
});
it('build request check url', function () {
const bidRequestData = [{
Expand All @@ -58,14 +54,13 @@ describe('viqeoBidAdapter', function () {
videoId: 'ed584da454c7205ca7e4',
profileId: 1382,
},
sspId: 42,
},
mediaTypes: {
video: { playerSize: [[240, 400]] }
},
}];
const request = spec.buildRequests(bidRequestData);
expect(request[0].url).to.equal('https://ads.betweendigital.com/openrtb_bid/?sspId=42')
expect(request[0].url).to.equal('https://ad.vqserve.com/ads/prebid')
});
it('response_params common case', function () {
const bidRequestData = {
Expand Down