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

Adot Bid Adapter: add advertiser domains support; add support for openrtb video parameters on the ad unit #6876

Merged
merged 1 commit into from
Jun 2, 2021
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
54 changes: 44 additions & 10 deletions modules/adotBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function isBanner(mediaTypes) {
}

function isVideo(mediaTypes) {
return isPlainObject(mediaTypes) && isPlainObject(mediaTypes.video);
return isPlainObject(mediaTypes) && 'video' in mediaTypes;
}

function validateBanner(banner) {
Expand Down Expand Up @@ -104,13 +104,16 @@ function validateMediaSizes(mediaSize) {
function validateParameters(parameters, adUnit) {
if (isVideo(adUnit.mediaTypes)) {
if (!isPlainObject(parameters)) return false;
if (!isPlainObject(adUnit.mediaTypes.video)) return false;
if (!validateVideoParameters(parameters.video, adUnit)) return false;
}

return true;
}

function validateVideoParameters(video, adUnit) {
function validateVideoParameters(videoParams, adUnit) {
const video = adUnit.mediaTypes.video;

if (!video) return false;

if (!isArray(video.mimes)) return false;
Expand All @@ -124,9 +127,9 @@ function validateVideoParameters(video, adUnit) {
if (video.protocols.length === 0) return false;
if (!video.protocols.every(isNumber)) return false;

if (isInstream(adUnit.mediaTypes.video)) {
if (!video.instreamContext) return false;
if (SUPPORTED_INSTREAM_CONTEXTS.indexOf(video.instreamContext) === -1) return false;
if (isInstream(video)) {
if (!videoParams.instreamContext) return false;
if (SUPPORTED_INSTREAM_CONTEXTS.indexOf(videoParams.instreamContext) === -1) return false;
}

return true;
Expand Down Expand Up @@ -203,7 +206,7 @@ function generateImpressionsFromAdUnit(acc, adUnit) {

if (mediaType === 'banner') return acc.concat(generateBannerFromAdUnit(impId, data, params));
if (mediaType === 'video') return acc.concat({id: impId, video: generateVideoFromAdUnit(data, params), pmp, ext});
if (mediaType === 'native') return acc.concat({id: impId, native: generateNativeFromAdUnit(data, params), pmp, ext});
if (mediaType === 'native') return acc.concat({id: impId, native: generateNativeFromAdUnit(data), pmp, ext});
}, []);

return acc.concat(imps);
Expand All @@ -226,25 +229,52 @@ function generateBannerFromAdUnit(impId, data, params) {

function generateVideoFromAdUnit(data, params) {
const {playerSize} = data;
const video = data

const hasPlayerSize = isArray(playerSize) && playerSize.length > 0;
const {position, video = {}} = params;
const {minDuration, maxDuration, protocols} = video;

const size = {width: hasPlayerSize ? playerSize[0][0] : null, height: hasPlayerSize ? playerSize[0][1] : null};
const duration = {min: isNumber(minDuration) ? minDuration : null, max: isNumber(maxDuration) ? maxDuration : null};
const startdelay = computeStartDelay(data, params);

return {
mimes: SUPPORTED_VIDEO_MIMES,
skip: video.skippable || 0,
w: size.width,
h: size.height,
startdelay: computeStartDelay(data, params),
startdelay: startdelay,
linearity: video.linearity || null,
minduration: duration.min,
maxduration: duration.max,
protocols,
pos: position || 0
api: getApi(protocols),
format: hasPlayerSize ? playerSize.map(s => {
return {w: s[0], h: s[1]};
}) : null,
pos: video.position || 0
};
}

function getApi(protocols) {
let defaultValue = [2];
let listProtocols = [
{key: 'VPAID_1_0', value: 1},
{key: 'VPAID_2_0', value: 2},
{key: 'MRAID_1', value: 3},
{key: 'ORMMA', value: 4},
{key: 'MRAID_2', value: 5},
{key: 'MRAID_3', value: 6},
];
if (protocols) {
return listProtocols.filter(p => {
return protocols.indexOf(p.key) !== -1;
}).map(p => p.value)
} else {
return defaultValue;
}
}

function isInstream(video) {
return isPlainObject(video) && (video.context === 'instream');
}
Expand All @@ -263,7 +293,7 @@ function computeStartDelay(data, params) {
return null;
}

function generateNativeFromAdUnit(data, params) {
function generateNativeFromAdUnit(data) {
const {type} = data;
const presetFormatter = type && NATIVE_PRESET_FORMATTERS[data.type];
const nativeFields = presetFormatter ? presetFormatter(data) : data;
Expand Down Expand Up @@ -500,6 +530,10 @@ function generateAdFromBid(bid, bidResponse, serverRequest) {
mediaType: bid.ext.adot.media_type,
};

if (bid.adomain) {
base.meta = { advertiserDomains: bid.adomain };
}

if (isBidANative(bid)) return {...base, native: formatNativeData(bid)};

const size = getSizeFromBid(bid, impressionData);
Expand Down
44 changes: 21 additions & 23 deletions modules/adotBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,22 @@ const adUnit = {
context: 'outstream',
// Video dimensions supported by the video ad unit.
// Each ad unit size is formatted as follows: [width, height].
playerSize: [[300, 250]]
playerSize: [[300, 250]],
// Content MIME types supported by the ad unit.
mimes: ['video/mp4'],
// Minimum accepted video ad duration (in seconds).
minDuration: 5,
// Maximum accepted video ad duration (in seconds).
maxDuration: 35,
// Video protocols supported by the ad unit (see the OpenRTB 2.5 specifications,
// section 5.8).
protocols: [2, 3]
}
},
bids: [{
bidder: 'adot',
params: {
video: {
// Content MIME types supported by the ad unit.
mimes: ['video/mp4'],
// Minimum accepted video ad duration (in seconds).
minDuration: 5,
// Maximum accepted video ad duration (in seconds).
maxDuration: 35,
// Video protocols supported by the ad unit (see the OpenRTB 2.5 specifications,
// section 5.8).
protocols: [2, 3]
}
video: {}
}
}]
}
Expand All @@ -82,23 +81,22 @@ const adUnit = {
context: 'instream',
// Video dimensions supported by the video ad unit.
// Each ad unit size is formatted as follows: [width, height].
playerSize: [[300, 250]]
playerSize: [[300, 250]],
// Content MIME types supported by the ad unit.
mimes: ['video/mp4'],
// Minimum accepted video ad duration (in seconds).
minDuration: 5,
// Maximum accepted video ad duration (in seconds).
maxDuration: 35,
// Video protocols supported by the ad unit (see the OpenRTB 2.5 specifications,
// section 5.8).
protocols: [2, 3]
}
},
bids: [{
bidder: 'adot',
params: {
video: {
// Content MIME types supported by the ad unit.
mimes: ['video/mp4'],
// Minimum accepted video ad duration (in seconds).
minDuration: 5,
// Maximum accepted video ad duration (in seconds).
maxDuration: 35,
// Video protocols supported by the ad unit (see the OpenRTB 2.5 specifications,
// section 5.8).
protocols: [2, 3],
// Instream video context. Must be either 'pre-roll', 'mid-roll' or 'post-roll'.
instreamContext: 'pre-roll'
}
}
Expand Down
Loading