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

Vdo.ai Bid Adapter : update to prebid version 9 #12284

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
176 changes: 151 additions & 25 deletions modules/vdoaiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js';
import { deepClone, logError, deepAccess } from '../src/utils.js';
import { config } from '../src/config.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand All @@ -9,7 +11,85 @@ import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js';
*/

const BIDDER_CODE = 'vdoai';
const ENDPOINT_URL = 'https://prebid.vdo.ai/auction';
const ENDPOINT_URL = 'https://prebid-v2.vdo.ai/auction';

function getFrameNesting() {
let topmostFrame = window;
let parent = window.parent;
try {
while (topmostFrame !== topmostFrame.parent) {
parent = topmostFrame.parent;
// eslint-disable-next-line no-unused-expressions
parent.location.href;
topmostFrame = topmostFrame.parent;
}
} catch (e) { }
return topmostFrame;
}

/**
* Returns information about the page needed by the server in an object to be converted in JSON
* @returns {{location: *, referrer: (*|string), stack: (*|Array.<String>), numIframes: (*|Number), wWidth: (*|Number), wHeight: (*|Number), sWidth, sHeight, date: string, timeOffset: number}}
*/
function getPageInfo(bidderRequest) {
const topmostFrame = getFrameNesting();
return {
referrer: deepAccess(bidderRequest, 'refererInfo.ref', null),
stack: deepAccess(bidderRequest, 'refererInfo.stack', []),
numIframes: deepAccess(bidderRequest, 'refererInfo.numIframes', 0),
wWidth: topmostFrame.innerWidth,
location: deepAccess(bidderRequest, 'refererInfo.page', null),
wHeight: topmostFrame.innerHeight,
aWidth: topmostFrame.screen.availWidth,
aHeight: topmostFrame.screen.availHeight,
oWidth: topmostFrame.outerWidth,
oHeight: topmostFrame.outerHeight,
sWidth: topmostFrame.screen.width,
sHeight: topmostFrame.screen.height,
sLeft: 'screenLeft' in topmostFrame ? topmostFrame.screenLeft : topmostFrame.screenX,
sTop: 'screenTop' in topmostFrame ? topmostFrame.screenTop : topmostFrame.screenY,
xOffset: topmostFrame.pageXOffset,
docHeight: topmostFrame.document.body ? topmostFrame.document.body.scrollHeight : null,
hLength: history.length,
yOffset: topmostFrame.pageYOffset,
version: {
prebid_version: '$prebid.version$',
adapter_version: '1.0.0',
vendor: '$$PREBID_GLOBAL$$',
}
};
}

export function isSchainValid(schain) {
let isValid = false;
const requiredFields = ['asi', 'sid', 'hp'];
if (!schain || !schain.nodes) return isValid;
isValid = schain.nodes.reduce((status, node) => {
if (!status) return status;
return requiredFields.every(field => node.hasOwnProperty(field));
}, true);
if (!isValid) {
logError('VDO.AI: required schain params missing');
}
return isValid;
}

function parseVideoSize(bid) {
const playerSize = bid.mediaTypes.video.playerSize;
if (typeof playerSize !== 'undefined' && Array.isArray(playerSize) && playerSize.length > 0) {
return getSizes(playerSize)
}
return [];
}

function getSizes(sizes) {
const ret = [];
for (let i = 0; i < sizes.length; i++) {
const size = sizes[i];
ret.push({ width: size[0], height: size[1] })
}
return ret;
}

export const spec = {
code: BIDDER_CODE,
Expand All @@ -21,7 +101,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.placementId);
return !!(bid.params.placementId) && typeof bid.params.placementId === 'string';
},

/**
Expand All @@ -31,23 +111,80 @@ export const spec = {
* @param validBidRequests
* @param bidderRequest
*/

buildRequests: function (validBidRequests, bidderRequest) {
if (validBidRequests.length === 0) {
return [];
}

return validBidRequests.map(bidRequest => {
const sizes = getAdUnitSizes(bidRequest);
const payload = {
let payload = {
placementId: bidRequest.params.placementId,
sizes: sizes,
bidId: bidRequest.bidId,
// TODO: is 'page' the right value here?
referer: bidderRequest.refererInfo.page,
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
id: bidRequest.auctionId,
mediaType: bidRequest.mediaTypes.video ? 'video' : 'banner'
mediaType: bidRequest.mediaTypes.video ? 'video' : 'banner',
domain: bidderRequest.ortb2.site.domain,
publisherDomain: bidderRequest.ortb2.site.publisher.domain,
adUnitCode: bidRequest.adUnitCode,
bidder: bidRequest.bidder,
tmax: bidderRequest.timeout
};

payload.bidderRequestId = bidRequest.bidderRequestId;
payload.auctionId = deepAccess(bidRequest, 'ortb2.source.tid');
payload.transactionId = deepAccess(bidRequest, 'ortb2Imp.ext.tid');
payload.gpid = deepAccess(bidRequest, 'ortb2Imp.ext.gpid') || deepAccess(bidRequest, 'ortb2Imp.ext.data.pbadslot');
payload.ortb2Imp = deepAccess(bidRequest, 'ortb2Imp');

if (payload.mediaType === 'video') {
payload.context = bidRequest.mediaTypes.video.context;
payload.playerSize = parseVideoSize(bidRequest);
payload.mediaTypeInfo = deepClone(bidRequest.mediaTypes.video);
}

if (typeof bidRequest.getFloor === 'function') {
let floor = bidRequest.getFloor({
currency: 'USD',
mediaType: '*',
size: '*'
});
if (floor && floor.floor && floor.currency === 'USD') {
payload.bidFloor = floor.floor;
}
} else if (bidRequest.params.bidFloor) {
payload.bidFloor = bidRequest.params.bidFloor;
}

payload.pageInfo = getPageInfo(bidderRequest);

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdprConsent = {
consentRequired: bidderRequest.gdprConsent.gdprApplies,
consentString: bidderRequest.gdprConsent.consentString,
addtlConsent: bidderRequest.gdprConsent.addtlConsent
};
}
if (bidderRequest && bidderRequest.gppConsent) {
payload.gppConsent = {
applicableSections: bidderRequest.gppConsent.applicableSections,
consentString: bidderRequest.gppConsent.gppString,
}
}
if (bidderRequest && bidderRequest.ortb2) {
payload.ortb2 = bidderRequest.ortb2;
}
if (bidderRequest && bidderRequest.uspConsent) {
payload.usPrivacy = bidderRequest.uspConsent;
}
if (validBidRequests && validBidRequests.length !== 0 && validBidRequests[0].schain && isSchainValid(validBidRequests[0].schain)) {
payload.schain = validBidRequests[0].schain;
}
if (validBidRequests && validBidRequests.length !== 0 && validBidRequests[0].userIdAsEids) {
payload.userId = validBidRequests[0].userIdAsEids;
}
if (config.getConfig('coppa') === true) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please access coppa from bidderRequest.ortb2.regs.coppa instead of config

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ChrisHuie , thanks for the review. we have made the necessary changes. Is there anything else I can assist with?

payload.coppa = true;
}
return {
method: 'POST',
url: ENDPOINT_URL,
Expand All @@ -67,35 +204,24 @@ export const spec = {
const bidResponses = [];
const response = serverResponse.body;
const creativeId = response.adid || 0;
// const width = response.w || 0;
const width = response.width;
// const height = response.h || 0;
const height = response.height;
const width = response.w;
const height = response.h;
const cpm = response.price || 0;

response.rWidth = width;
response.rHeight = height;

const adCreative = response.vdoCreative;

if (width !== 0 && height !== 0 && cpm !== 0 && creativeId !== 0) {
// const dealId = response.dealid || '';
const currency = response.cur || 'USD';
const netRevenue = true;
// const referrer = bidRequest.data.referer;
const bidResponse = {
requestId: response.bidId,
cpm: cpm,
width: width,
height: height,
creativeId: creativeId,
// dealId: dealId,
currency: currency,
netRevenue: netRevenue,
ttl: 60,
// referrer: referrer,
// ad: response.adm
// ad: adCreative,
mediaType: response.mediaType
};

Expand All @@ -104,9 +230,9 @@ export const spec = {
} else {
bidResponse.ad = adCreative;
}
if (response.adDomain) {
if (response.adomain) {
bidResponse.meta = {
advertiserDomains: response.adDomain
advertiserDomains: response.adomain
};
}
bidResponses.push(bidResponse);
Expand All @@ -130,7 +256,7 @@ export const spec = {
return [];
},

onTImeout: function(data) {},
onTimeout: function(data) {},
onBidWon: function(bid) {},
onSetTargeting: function(bid) {}
};
Expand Down
Loading