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

Prebid Core: Define "VIDEO" compile time feature flag #9543

Merged
merged 13 commits into from
Mar 30, 2023
3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[
"NATIVE"
"NATIVE",
"VIDEO"
]
2 changes: 1 addition & 1 deletion modules/sizeMappingV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function checkAdUnitSetupHook(adUnits) {
}
}

if (mediaTypes.video) {
if (FEATURES.VIDEO && mediaTypes.video) {
if (mediaTypes.video.playerSize) {
// Ad unit is using 'mediaTypes.video.playerSize' instead of the new property 'sizeConfig'. Apply the old checks!
validatedVideo = validatedBanner ? adUnitSetupChecks.validateVideoMediaType(validatedBanner) : adUnitSetupChecks.validateVideoMediaType(adUnit);
Expand Down
4 changes: 2 additions & 2 deletions src/adapterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request

function getSupportedMediaTypes(bidderCode) {
let supportedMediaTypes = [];
if (includes(adapterManager.videoAdapters, bidderCode)) supportedMediaTypes.push('video');
if (FEATURES.VIDEO && includes(adapterManager.videoAdapters, bidderCode)) supportedMediaTypes.push('video');
if (FEATURES.NATIVE && includes(nativeAdapters, bidderCode)) supportedMediaTypes.push('native');
return supportedMediaTypes;
}
Expand All @@ -455,7 +455,7 @@ adapterManager.registerBidAdapter = function (bidAdapter, bidderCode, {supported
if (typeof bidAdapter.callBids === 'function') {
_bidderRegistry[bidderCode] = bidAdapter;

if (includes(supportedMediaTypes, 'video')) {
if (FEATURES.VIDEO && includes(supportedMediaTypes, 'video')) {
adapterManager.videoAdapters.push(bidderCode);
}
if (FEATURES.NATIVE && includes(supportedMediaTypes, 'native')) {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export function isValid(adUnitCode, bid, {index = auctionManager.index} = {}) {
logError(errorMessage('Native bid missing some required properties.'));
return false;
}
if (bid.mediaType === 'video' && !isValidVideoBid(bid, {index})) {
if (FEATURES.VIDEO && bid.mediaType === 'video' && !isValidVideoBid(bid, {index})) {
logError(errorMessage(`Video bid does not have required vastUrl or renderer property`));
return false;
}
Expand Down
54 changes: 29 additions & 25 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export function auctionCallbacks(auctionDone, auctionInstance, {index = auctionM
handleBidResponse(adUnitCode, bid, (done) => {
let bidResponse = getPreparedBidForAuction(bid);

if (bidResponse.mediaType === VIDEO) {
if (FEATURES.VIDEO && bidResponse.mediaType === VIDEO) {
tryAddVideoBid(auctionInstance, bidResponse, done);
} else {
if (FEATURES.NATIVE && bidResponse.native != null && typeof bidResponse.native === 'object') {
Expand Down Expand Up @@ -574,28 +574,30 @@ export function addBidToAuction(auctionInstance, bidResponse) {

// Video bids may fail if the cache is down, or there's trouble on the network.
function tryAddVideoBid(auctionInstance, bidResponse, afterBidAdded, {index = auctionManager.index} = {}) {
let addBid = true;

const videoMediaType = deepAccess(
index.getMediaTypes({
requestId: bidResponse.originalRequestId || bidResponse.requestId,
transactionId: bidResponse.transactionId
}), 'video');
const context = videoMediaType && deepAccess(videoMediaType, 'context');
const useCacheKey = videoMediaType && deepAccess(videoMediaType, 'useCacheKey');

if (config.getConfig('cache.url') && (useCacheKey || context !== OUTSTREAM)) {
if (!bidResponse.videoCacheKey || config.getConfig('cache.ignoreBidderCacheKey')) {
addBid = false;
callPrebidCache(auctionInstance, bidResponse, afterBidAdded, videoMediaType);
} else if (!bidResponse.vastUrl) {
logError('videoCacheKey specified but not required vastUrl for video bid');
addBid = false;
if (FEATURES.VIDEO) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be unnecessary, if all the calls into this are skipped the function should already be removed as dead code.

let addBid = true;

const videoMediaType = deepAccess(
index.getMediaTypes({
requestId: bidResponse.originalRequestId || bidResponse.requestId,
transactionId: bidResponse.transactionId
}), 'video');
const context = videoMediaType && deepAccess(videoMediaType, 'context');
const useCacheKey = videoMediaType && deepAccess(videoMediaType, 'useCacheKey');

if (config.getConfig('cache.url') && (useCacheKey || context !== OUTSTREAM)) {
if (!bidResponse.videoCacheKey || config.getConfig('cache.ignoreBidderCacheKey')) {
addBid = false;
callPrebidCache(auctionInstance, bidResponse, afterBidAdded, videoMediaType);
} else if (!bidResponse.vastUrl) {
logError('videoCacheKey specified but not required vastUrl for video bid');
addBid = false;
}
}
if (addBid) {
addBidToAuction(auctionInstance, bidResponse);
afterBidAdded();
}
}
if (addBid) {
addBidToAuction(auctionInstance, bidResponse);
afterBidAdded();
}
}

Expand All @@ -610,7 +612,7 @@ const addLegacyFieldsIfNeeded = (bidResponse) => {
}
}

const storeInCache = (batch) => {
const _storeInCache = (batch) => {
store(batch.map(entry => entry.bidResponse), function (error, cacheIds) {
cacheIds.forEach((cacheId, i) => {
const { auctionInstance, bidResponse, afterBidAdded } = batch[i];
Expand All @@ -637,6 +639,8 @@ const storeInCache = (batch) => {
});
};

const storeInCache = FEATURES.VIDEO ? _storeInCache : () => {};

let batchSize, batchTimeout;
config.getConfig('cache', (cacheConfig) => {
batchSize = typeof cacheConfig.cache.batchSize === 'number' && cacheConfig.cache.batchSize > 0
Expand Down Expand Up @@ -772,7 +776,7 @@ function setupBidTargeting(bidObject) {
*/
export function getMediaTypeGranularity(mediaType, mediaTypes, mediaTypePriceGranularity) {
if (mediaType && mediaTypePriceGranularity) {
if (mediaType === VIDEO) {
if (FEATURES.VIDEO && mediaType === VIDEO) {
const context = deepAccess(mediaTypes, `${VIDEO}.context`, 'instream');
if (mediaTypePriceGranularity[`${VIDEO}-${context}`]) {
return mediaTypePriceGranularity[`${VIDEO}-${context}`];
Expand Down Expand Up @@ -881,7 +885,7 @@ export function getStandardBidderSettings(mediaType, bidderCode) {
standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = defaultAdserverTargeting();
}

if (mediaType === 'video') {
if (FEATURES.VIDEO && mediaType === 'video') {
const adserverTargeting = standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING].slice();
standardSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = adserverTargeting;

Expand Down
37 changes: 21 additions & 16 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,17 @@ function validateAdUnit(adUnit) {
export const adUnitSetupChecks = {
validateAdUnit,
validateBannerMediaType,
validateVideoMediaType,
validateSizes
};

if (FEATURES.NATIVE) {
Object.assign(adUnitSetupChecks, {validateNativeMediaType});
}

if (FEATURES.VIDEO) {
Object.assign(adUnitSetupChecks, { validateVideoMediaType });
}

export const checkAdUnitSetup = hook('sync', function (adUnits) {
const validatedAdUnits = [];

Expand All @@ -248,7 +251,7 @@ export const checkAdUnitSetup = hook('sync', function (adUnits) {
if (mediaTypes.banner.hasOwnProperty('pos')) validatedBanner = validateAdUnitPos(validatedBanner, 'banner');
}

if (mediaTypes.video) {
if (FEATURES.VIDEO && mediaTypes.video) {
validatedVideo = validatedBanner ? validateVideoMediaType(validatedBanner) : validateVideoMediaType(adUnit);
if (mediaTypes.video.hasOwnProperty('pos')) validatedVideo = validateAdUnitPos(validatedVideo, 'video');
}
Expand Down Expand Up @@ -995,21 +998,23 @@ $$PREBID_GLOBAL$$.getHighestCpmBids = function (adUnitCode) {
* @alias module:pbjs.markWinningBidAsUsed
*/
$$PREBID_GLOBAL$$.markWinningBidAsUsed = function (markBidRequest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may be just a stylistic difference, but I think it'd be better to not have this method rather than have it silently do nothing.

let bids = [];

if (markBidRequest.adUnitCode && markBidRequest.adId) {
bids = auctionManager.getBidsReceived()
.filter(bid => bid.adId === markBidRequest.adId && bid.adUnitCode === markBidRequest.adUnitCode);
} else if (markBidRequest.adUnitCode) {
bids = targeting.getWinningBids(markBidRequest.adUnitCode);
} else if (markBidRequest.adId) {
bids = auctionManager.getBidsReceived().filter(bid => bid.adId === markBidRequest.adId);
} else {
logWarn('Improper use of markWinningBidAsUsed. It needs an adUnitCode or an adId to function.');
}
if (FEATURES.VIDEO) {
let bids = [];

if (markBidRequest.adUnitCode && markBidRequest.adId) {
bids = auctionManager.getBidsReceived()
.filter(bid => bid.adId === markBidRequest.adId && bid.adUnitCode === markBidRequest.adUnitCode);
} else if (markBidRequest.adUnitCode) {
bids = targeting.getWinningBids(markBidRequest.adUnitCode);
} else if (markBidRequest.adId) {
bids = auctionManager.getBidsReceived().filter(bid => bid.adId === markBidRequest.adId);
} else {
logWarn('Improper use of markWinningBidAsUsed. It needs an adUnitCode or an adId to function.');
}

if (bids.length > 0) {
bids[0].status = CONSTANTS.BID_STATUS.RENDERED;
if (bids.length > 0) {
bids[0].status = CONSTANTS.BID_STATUS.RENDERED;
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ export function isValidMediaTypes(mediaTypes) {
return false;
}

if (mediaTypes.video && mediaTypes.video.context) {
if (FEATURES.VIDEO && mediaTypes.video && mediaTypes.video.context) {
return includes(SUPPORTED_STREAM_TYPES, mediaTypes.video.context);
}

Expand Down
Loading