-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adkernel: added mediatypes.* attributes support (#10472)
- Loading branch information
Showing
2 changed files
with
49 additions
and
34 deletions.
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 |
---|---|---|
|
@@ -29,18 +29,19 @@ import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; | |
* | ||
* Please contact [email protected] and we'll add your adapter as an alias. | ||
*/ | ||
const VIDEO_PARAMS = ['pos', 'context', 'placement', 'api', 'mimes', 'protocols', 'playbackmethod', 'minduration', 'maxduration', | ||
const VIDEO_PARAMS = ['pos', 'context', 'placement', 'plcmt', 'api', 'mimes', 'protocols', 'playbackmethod', 'minduration', 'maxduration', | ||
'startdelay', 'linearity', 'skip', 'skipmin', 'skipafter', 'minbitrate', 'maxbitrate', 'delivery', 'playbackend', 'boxingallowed']; | ||
const VIDEO_FPD = ['battr', 'pos']; | ||
const NATIVE_FPD = ['battr', 'api']; | ||
const BANNER_PARAMS = ['pos']; | ||
const BANNER_FPD = ['btype', 'battr', 'pos', 'api']; | ||
const VERSION = '1.6'; | ||
const SYNC_IFRAME = 1; | ||
const SYNC_IMAGE = 2; | ||
const SYNC_TYPES = Object.freeze({ | ||
const SYNC_TYPES = { | ||
1: 'iframe', | ||
2: 'image' | ||
}); | ||
}; | ||
const GVLID = 14; | ||
|
||
const NATIVE_MODEL = [ | ||
|
@@ -275,33 +276,37 @@ function buildImp(bidRequest, secure) { | |
var mediaType; | ||
var sizes = []; | ||
|
||
if (deepAccess(bidRequest, 'mediaTypes.banner')) { | ||
if (bidRequest.mediaTypes?.banner) { | ||
sizes = getAdUnitSizes(bidRequest); | ||
let pbBanner = bidRequest.mediaTypes.banner; | ||
imp.banner = { | ||
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, BANNER_FPD), | ||
...getDefinedParamsOrEmpty(pbBanner, BANNER_PARAMS), | ||
format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)), | ||
topframe: 0 | ||
}; | ||
populateImpFpd(imp.banner, bidRequest, BANNER_FPD); | ||
mediaType = BANNER; | ||
} else if (deepAccess(bidRequest, 'mediaTypes.video')) { | ||
let video = deepAccess(bidRequest, 'mediaTypes.video'); | ||
imp.video = getDefinedParams(video, VIDEO_PARAMS); | ||
populateImpFpd(imp.video, bidRequest, VIDEO_FPD); | ||
if (video.playerSize) { | ||
sizes = video.playerSize[0]; | ||
} else if (bidRequest.mediaTypes?.video) { | ||
let pbVideo = bidRequest.mediaTypes.video; | ||
imp.video = { | ||
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, VIDEO_FPD), | ||
...getDefinedParamsOrEmpty(pbVideo, VIDEO_PARAMS) | ||
}; | ||
if (pbVideo.playerSize) { | ||
sizes = pbVideo.playerSize[0]; | ||
imp.video = Object.assign(imp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {}); | ||
} else if (video.w && video.h) { | ||
imp.video.w = video.w; | ||
imp.video.h = video.h; | ||
} else if (pbVideo.w && pbVideo.h) { | ||
imp.video.w = pbVideo.w; | ||
imp.video.h = pbVideo.h; | ||
} | ||
mediaType = VIDEO; | ||
} else if (deepAccess(bidRequest, 'mediaTypes.native')) { | ||
} else if (bidRequest.mediaTypes?.native) { | ||
let nativeRequest = buildNativeRequest(bidRequest.mediaTypes.native); | ||
imp.native = { | ||
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, NATIVE_FPD), | ||
ver: '1.1', | ||
request: JSON.stringify(nativeRequest) | ||
}; | ||
populateImpFpd(imp.native, bidRequest, NATIVE_FPD); | ||
mediaType = NATIVE; | ||
} else { | ||
throw new Error('Unsupported bid received'); | ||
|
@@ -316,6 +321,13 @@ function buildImp(bidRequest, secure) { | |
return imp; | ||
} | ||
|
||
function getDefinedParamsOrEmpty(object, params) { | ||
if (object === undefined) { | ||
return {}; | ||
} | ||
return getDefinedParams(object, params); | ||
} | ||
|
||
/** | ||
* Builds native request from native adunit | ||
*/ | ||
|
@@ -345,19 +357,6 @@ function buildNativeRequest(nativeReq) { | |
return request; | ||
} | ||
|
||
/** | ||
* Populate impression-level FPD from bid request | ||
* @param target {Object} | ||
* @param bidRequest {BidRequest} | ||
* @param props {String[]} | ||
*/ | ||
function populateImpFpd(target, bidRequest, props) { | ||
if (bidRequest.ortb2Imp === undefined) { | ||
return; | ||
} | ||
Object.assign(target, getDefinedParams(bidRequest.ortb2Imp, props)); | ||
} | ||
|
||
/** | ||
* Builds image asset request | ||
*/ | ||
|
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