Skip to content

Commit

Permalink
changes to support ortb for native media type
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipStamenkovic committed Jan 12, 2022
1 parent 9db1ee9 commit f4ed600
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ const OPEN_RTB_PROTOCOL = {
impIds.add(impressionId);

const nativeParams = processNativeAdUnitParams(deepAccess(adUnit, 'mediaTypes.native'));
let nativeAssets;
if (nativeParams) {
let nativeAssets = nativeAssetCache[impressionId] = deepAccess(nativeParams, 'ortb.assets');
if (nativeParams && !nativeAssets) {
try {
nativeAssets = nativeAssetCache[impressionId] = Object.keys(nativeParams).reduce((assets, type) => {
let params = nativeParams[type];
Expand Down Expand Up @@ -965,30 +965,36 @@ const OPEN_RTB_PROTOCOL = {
}

if (isPlainObject(adm) && Array.isArray(adm.assets)) {
let origAssets = nativeAssetCache[bid.impid];
bidObject.native = cleanObj(adm.assets.reduce((native, asset) => {
let origAsset = origAssets[asset.id];
if (isPlainObject(asset.img)) {
native[origAsset.img.type ? nativeImgIdMap[origAsset.img.type] : 'image'] = pick(
asset.img,
['url', 'w as width', 'h as height']
);
} else if (isPlainObject(asset.title)) {
native['title'] = asset.title.text
} else if (isPlainObject(asset.data)) {
nativeDataNames.forEach(dataType => {
if (nativeDataIdMap[dataType] === origAsset.data.type) {
native[dataType] = asset.data.value;
}
});
if (deepAccess(bidRequest, 'mediaTypes.native.ortb')) {
bidObject.native = {
ortb: adm,
}
return native;
}, cleanObj({
clickUrl: adm.link,
clickTrackers: deepAccess(adm, 'link.clicktrackers'),
impressionTrackers: trackers[nativeEventTrackerMethodMap.img],
javascriptTrackers: trackers[nativeEventTrackerMethodMap.js]
})));
} else {
let origAssets = nativeAssetCache[bid.impid];
bidObject.native = cleanObj(adm.assets.reduce((native, asset) => {
let origAsset = origAssets[asset.id];
if (isPlainObject(asset.img)) {
native[origAsset.img.type ? nativeImgIdMap[origAsset.img.type] : 'image'] = pick(
asset.img,
['url', 'w as width', 'h as height']
);
} else if (isPlainObject(asset.title)) {
native['title'] = asset.title.text
} else if (isPlainObject(asset.data)) {
nativeDataNames.forEach(dataType => {
if (nativeDataIdMap[dataType] === origAsset.data.type) {
native[dataType] = asset.data.value;
}
});
}
return native;
}, cleanObj({
clickUrl: adm.link,
clickTrackers: deepAccess(adm, 'link.clicktrackers'),
impressionTrackers: trackers[nativeEventTrackerMethodMap.img],
javascriptTrackers: trackers[nativeEventTrackerMethodMap.js]
})));
}
} else {
logError('prebid server native response contained no assets');
}
Expand Down

0 comments on commit f4ed600

Please sign in to comment.