Skip to content

Commit

Permalink
Core: include dynamic renderer in native messages (prebid#11343)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored and mefjush committed May 21, 2024
1 parent 83b5861 commit d774959
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 169 deletions.
19 changes: 17 additions & 2 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {includes} from './polyfill.js';
import {auctionManager} from './auctionManager.js';
import {NATIVE_ASSET_TYPES, NATIVE_IMAGE_TYPES, PREBID_NATIVE_DATA_KEYS_TO_ORTB, NATIVE_KEYS_THAT_ARE_NOT_ASSETS, NATIVE_KEYS} from './constants.js';
import {NATIVE} from './mediaTypes.js';
import {getRenderingData} from './adRendering.js';
import {getCreativeRendererSource} from './creativeRenderers.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -434,11 +436,24 @@ export function getNativeRenderingData(bid, adUnit, keys) {
}

function assetsMessage(data, adObject, keys, {index = auctionManager.index} = {}) {
return {
const msg = {
message: 'assetResponse',
adId: data.adId,
...getNativeRenderingData(adObject, index.getAdUnit(adObject), keys)
};
let renderData = getRenderingData(adObject).native;
if (renderData) {
// if we have native rendering data (set up by the nativeRendering module)
// include it in full ("all assets") together with the renderer.
// this is to allow PUC to use dynamic renderers without requiring changes in creative setup
msg.native = Object.assign({}, renderData);
msg.renderer = getCreativeRendererSource(adObject);
if (keys != null) {
renderData.assets = renderData.assets.filter(({key}) => keys.includes(key))
}
} else {
renderData = getNativeRenderingData(adObject, index.getAdUnit(adObject), keys);
}
return Object.assign(msg, renderData);
}

const NATIVE_KEYS_INVERTED = Object.fromEntries(Object.entries(NATIVE_KEYS).map(([k, v]) => [v, k]));
Expand Down
Loading

0 comments on commit d774959

Please sign in to comment.