-
Notifications
You must be signed in to change notification settings - Fork 2k
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 Bid Adapter: add Flux Wrapper support. #7555
Merged
ncolletti
merged 3 commits into
prebid:master
from
DAConsortium:feature/yieldoneBidAdapter
Nov 11, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { deepAccess, isEmpty, parseSizesInput, isStr, logWarn } from '../src/utils.js'; | ||
import {deepAccess, isEmpty, isStr, logWarn, parseSizesInput} from '../src/utils.js'; | ||
import {config} from '../src/config.js'; | ||
import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
import { Renderer } from '../src/Renderer.js'; | ||
|
@@ -11,6 +11,8 @@ const VIDEO_PLAYER_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/d | |
const CMER_PLAYER_URL = 'https://an.cmertv.com/hb/renderer/cmertv-video-yone-prebid.min.js'; | ||
const VIEWABLE_PERCENTAGE_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/prebid-adformat-config.js'; | ||
|
||
const DEFAULT_VIDEO_SIZE = {w: 640, h: 360}; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['y1'], | ||
|
@@ -40,16 +42,18 @@ export const spec = { | |
t: 'i' | ||
}; | ||
|
||
const videoMediaType = deepAccess(bidRequest, 'mediaTypes.video'); | ||
if ((isEmpty(bidRequest.mediaType) && isEmpty(bidRequest.mediaTypes)) || | ||
(bidRequest.mediaType === BANNER || (bidRequest.mediaTypes && bidRequest.mediaTypes[BANNER]))) { | ||
const sizes = deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes; | ||
payload.sz = parseSizesInput(sizes).join(','); | ||
} else if (bidRequest.mediaType === VIDEO || videoMediaType) { | ||
const sizes = deepAccess(bidRequest, 'mediaTypes.video.playerSize') || bidRequest.sizes; | ||
const size = parseSizesInput(sizes)[0]; | ||
payload.w = size.split('x')[0]; | ||
payload.h = size.split('x')[1]; | ||
const mediaType = getMediaType(bidRequest); | ||
switch (mediaType) { | ||
case BANNER: | ||
payload.sz = getBannerSizes(bidRequest); | ||
break; | ||
case VIDEO: | ||
const videoSize = getVideoSize(bidRequest); | ||
payload.w = videoSize.w; | ||
payload.h = videoSize.h; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
// LiveRampID | ||
|
@@ -167,6 +171,107 @@ export const spec = { | |
}, | ||
} | ||
|
||
/** | ||
* NOTE: server side does not yet support multiple formats. | ||
* @param {Object} bidRequest - | ||
* @param {boolean} [enabledOldFormat = true] - default: `true`. | ||
* @return {string|null} - `"banner"` or `"video"` or `null`. | ||
*/ | ||
function getMediaType(bidRequest, enabledOldFormat = true) { | ||
let hasBannerType = Boolean(deepAccess(bidRequest, 'mediaTypes.banner')); | ||
let hasVideoType = Boolean(deepAccess(bidRequest, 'mediaTypes.video')); | ||
|
||
if (enabledOldFormat) { | ||
hasBannerType = hasBannerType || bidRequest.mediaType === BANNER || | ||
(isEmpty(bidRequest.mediaTypes) && isEmpty(bidRequest.mediaType)); | ||
hasVideoType = hasVideoType || bidRequest.mediaType === VIDEO; | ||
} | ||
|
||
if (hasBannerType && hasVideoType) { | ||
const playerParams = deepAccess(bidRequest, 'params.playerParams') | ||
if (playerParams) { | ||
return VIDEO; | ||
} else { | ||
return BANNER; | ||
} | ||
} else if (hasBannerType) { | ||
return BANNER; | ||
} else if (hasVideoType) { | ||
return VIDEO; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* NOTE: | ||
* If `mediaTypes.banner` exists, then `mediaTypes.banner.sizes` must also exist. | ||
* The reason for this is that Prebid.js will perform the verification and | ||
* if `mediaTypes.banner.sizes` is inappropriate, it will delete the entire `mediaTypes.banner`. | ||
* @param {Object} bidRequest - | ||
* @param {Object} bidRequest.banner - | ||
* @param {Array<string>} bidRequest.banner.sizes - | ||
* @param {boolean} [enabledOldFormat = true] - default: `true`. | ||
* @return {string} - strings like `"300x250"` or `"300x250,728x90"`. | ||
*/ | ||
function getBannerSizes(bidRequest, enabledOldFormat = true) { | ||
let sizes = deepAccess(bidRequest, 'mediaTypes.banner.sizes'); | ||
|
||
if (enabledOldFormat) { | ||
sizes = sizes || bidRequest.sizes; | ||
} | ||
|
||
const result = parseSizesInput(sizes).join(','); | ||
return result; | ||
} | ||
|
||
/** | ||
* @param {Object} bidRequest - | ||
* @param {boolean} [enabledOldFormat = true] - default: `true`. | ||
* @return {{w: number, h: number}} - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
*/ | ||
function getVideoSize(bidRequest, enabledOldFormat = true, enabledFlux = true) { | ||
/** | ||
* @param {Array<number, number> | Array<Array<number, number>>} sizes - | ||
* @return {{w: number, h: number} | null} - | ||
*/ | ||
const _getPlayerSize = (sizes) => { | ||
let result = null; | ||
|
||
const size = parseSizesInput(sizes)[0]; | ||
if (isEmpty(size)) { | ||
return result; | ||
} | ||
|
||
const splited = size.split('x'); | ||
const sizeObj = {w: parseInt(splited[0], 10), h: parseInt(splited[1], 10)}; | ||
const _isValidPlayerSize = !(isEmpty(sizeObj)) && (isFinite(sizeObj.w) && isFinite(sizeObj.h)); | ||
if (!_isValidPlayerSize) { | ||
return result; | ||
} | ||
|
||
result = sizeObj; | ||
return result; | ||
} | ||
|
||
let playerSize = _getPlayerSize(deepAccess(bidRequest, 'mediaTypes.video.playerSize')); | ||
|
||
if (enabledOldFormat) { | ||
playerSize = playerSize || _getPlayerSize(bidRequest.sizes); | ||
} | ||
|
||
if (enabledFlux) { | ||
// NOTE: `video.playerSize` in Flux is always [1,1]. | ||
if (playerSize && (playerSize.w === 1 && playerSize.h === 1)) { | ||
// NOTE: `params.playerSize` is a specific object to support `FLUX`. | ||
playerSize = _getPlayerSize(deepAccess(bidRequest, 'params.playerSize')); | ||
} | ||
} | ||
|
||
const result = playerSize || DEFAULT_VIDEO_SIZE; | ||
return result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can simply |
||
} | ||
|
||
function newRenderer(response) { | ||
const renderer = Renderer.install({ | ||
id: response.uid, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the other comments, might be cleaner to simply
return parseSizesInput(sizes).join(',');