From 186ba06cfd795434302c8cdbfd78bc2c67f9f000 Mon Sep 17 00:00:00 2001 From: Filip Stamenkovic Date: Mon, 10 Jan 2022 12:27:11 +0100 Subject: [PATCH] changes to support ortb for native media type --- modules/prebidServerBidAdapter/index.js | 56 ++++++++++++++----------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index efe2576efd52..5e9ac8b14e76 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -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]; @@ -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'); }