From a783e90c15f0a443c69fc6bfba0471f3debb17e8 Mon Sep 17 00:00:00 2001 From: Denis Logachov Date: Tue, 9 Apr 2024 12:49:39 +0300 Subject: [PATCH] Adkernel Bid Adapter: remove legacy native impl --- modules/adkernelBidAdapter.js | 113 +++---------------- test/spec/modules/adkernelBidAdapter_spec.js | 74 ++++++++---- 2 files changed, 68 insertions(+), 119 deletions(-) diff --git a/modules/adkernelBidAdapter.js b/modules/adkernelBidAdapter.js index 491808f2602..ae02a8967b1 100644 --- a/modules/adkernelBidAdapter.js +++ b/modules/adkernelBidAdapter.js @@ -1,6 +1,5 @@ import { _each, - cleanObj, contains, createTrackPixelHtml, deepAccess, @@ -20,7 +19,6 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {find} from '../src/polyfill.js'; import {config} from '../src/config.js'; -import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js'; /** @@ -39,7 +37,7 @@ 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 VERSION = '1.7'; const SYNC_IFRAME = 1; const SYNC_IMAGE = 2; const SYNC_TYPES = { @@ -48,29 +46,6 @@ const SYNC_TYPES = { }; const GVLID = 14; -const NATIVE_MODEL = [ - {name: 'title', assetType: 'title'}, - {name: 'icon', assetType: 'img', type: 1}, - {name: 'image', assetType: 'img', type: 3}, - {name: 'body', assetType: 'data', type: 2}, - {name: 'body2', assetType: 'data', type: 10}, - {name: 'sponsoredBy', assetType: 'data', type: 1}, - {name: 'phone', assetType: 'data', type: 8}, - {name: 'address', assetType: 'data', type: 9}, - {name: 'price', assetType: 'data', type: 6}, - {name: 'salePrice', assetType: 'data', type: 7}, - {name: 'cta', assetType: 'data', type: 12}, - {name: 'rating', assetType: 'data', type: 3}, - {name: 'downloads', assetType: 'data', type: 5}, - {name: 'likes', assetType: 'data', type: 4}, - {name: 'displayUrl', assetType: 'data', type: 11} -]; - -const NATIVE_INDEX = NATIVE_MODEL.reduce((acc, val, idx) => { - acc[val.name] = {id: idx, ...val}; - return acc; -}, {}); - const MULTI_FORMAT_SUFFIX = '__mf'; const MULTI_FORMAT_SUFFIX_BANNER = 'b' + MULTI_FORMAT_SUFFIX; const MULTI_FORMAT_SUFFIX_VIDEO = 'v' + MULTI_FORMAT_SUFFIX; @@ -139,9 +114,6 @@ export const spec = { * @returns {ServerRequest[]} */ buildRequests: function (bidRequests, bidderRequest) { - // convert Native ORTB definition to old-style prebid native definition - bidRequests = convertOrtbRequestToProprietaryNative(bidRequests); - let impGroups = groupImpressionsByHostZone(bidRequests, bidderRequest.refererInfo); let requests = []; let schain = bidRequests[0].schain; @@ -199,7 +171,9 @@ export const spec = { prBid.height = imp.video.h; } else if ('native' in imp) { prBid.mediaType = NATIVE; - prBid.native = buildNativeAd(JSON.parse(rtbBid.adm)); + prBid.native = { + ortb: buildNativeAd(rtbBid.adm) + }; } if (isStr(rtbBid.dealid)) { prBid.dealId = rtbBid.dealid; @@ -345,11 +319,9 @@ function buildImps(bidRequest, secure) { } else { typedImp = imp; } - let nativeRequest = buildNativeRequest(mediaTypes.native); typedImp.native = { ...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, NATIVE_FPD), - ver: '1.1', - request: JSON.stringify(nativeRequest) + request: JSON.stringify(bidRequest.nativeOrtbRequest) }; initImpBidfloor(typedImp, bidRequest, sizes, isMultiformat ? '*' : NATIVE); result.push(typedImp); @@ -371,51 +343,6 @@ function getDefinedParamsOrEmpty(object, params) { return getDefinedParams(object, params); } -/** - * Builds native request from native adunit - */ -function buildNativeRequest(nativeReq) { - let request = {ver: '1.1', assets: []}; - for (let k of Object.keys(nativeReq)) { - let v = nativeReq[k]; - let desc = NATIVE_INDEX[k]; - if (desc === undefined) { - continue; - } - let assetRoot = { - id: desc.id, - required: ~~v.required, - }; - if (desc.assetType === 'img') { - assetRoot[desc.assetType] = buildImageAsset(desc, v); - } else if (desc.assetType === 'data') { - assetRoot.data = cleanObj({type: desc.type, len: v.len}); - } else if (desc.assetType === 'title') { - assetRoot.title = {len: v.len || 90}; - } else { - return; - } - request.assets.push(assetRoot); - } - return request; -} - -/** - * Builds image asset request - */ -function buildImageAsset(desc, val) { - let img = { - type: desc.type - }; - if (val.sizes) { - [img.w, img.h] = val.sizes; - } else if (val.aspect_ratios) { - img.wmin = val.aspect_ratios[0].min_width; - img.hmin = val.aspect_ratios[0].min_height; - } - return cleanObj(img); -} - /** * Checks if configuration allows specified sync method * @param syncRule {Object} @@ -540,12 +467,11 @@ function makeRegulations(bidderRequest) { * @returns */ function makeBaseRequest(bidderRequest, imps, fpd) { - let {timeout} = bidderRequest; let request = { 'id': bidderRequest.bidderRequestId, 'imp': imps, 'at': 1, - 'tmax': parseInt(timeout) + 'tmax': parseInt(bidderRequest.timeout) }; if (!isEmpty(fpd.bcat)) { request.bcat = fpd.bcat; @@ -665,26 +591,15 @@ function validateNativeImageSize(img) { } /** - * Creates native ad for native 1.1 response + * Creates native ad for native 1.2 response */ -function buildNativeAd(nativeResp) { - const {assets, link, imptrackers, jstracker, privacy} = nativeResp.native; - let nativeAd = { - clickUrl: link.url, - impressionTrackers: imptrackers, - javascriptTrackers: jstracker ? [jstracker] : undefined, - privacyLink: privacy, - }; - _each(assets, asset => { - let assetName = NATIVE_MODEL[asset.id].name; - let assetType = NATIVE_MODEL[asset.id].assetType; - nativeAd[assetName] = asset[assetType].text || asset[assetType].value || cleanObj({ - url: asset[assetType].url, - width: asset[assetType].w, - height: asset[assetType].h - }); - }); - return cleanObj(nativeAd); +function buildNativeAd(adm) { + let resp = JSON.parse(adm); + // temporary workaround for top-level native object wrapper + if ('native' in resp) { + resp = resp.native; + } + return resp; } function stripMultiformatSuffix(impid) { diff --git a/test/spec/modules/adkernelBidAdapter_spec.js b/test/spec/modules/adkernelBidAdapter_spec.js index ade34478c20..cdfc9795b85 100644 --- a/test/spec/modules/adkernelBidAdapter_spec.js +++ b/test/spec/modules/adkernelBidAdapter_spec.js @@ -125,7 +125,8 @@ describe('Adkernel adapter', function () { bidId: 'Bid_01', bidderRequestId: 'req-001', auctionId: 'auc-001' - }, bid_native = { + }, + bid_native = { bidder: 'adkernel', params: {zoneId: 1, host: 'rtb.adkernel.com'}, mediaTypes: { @@ -171,6 +172,33 @@ describe('Adkernel adapter', function () { } } }, + nativeOrtbRequest: { + ver: '1.2', + assets: [ + { + id: 0, required: 1, title: {len: 80} + }, { + id: 1, required: 1, data: {type: 2}}, + { + id: 2, required: 1, data: {type: 10} + }, { + id: 3, required: 1, img: {type: 1, wmin: 50, hmin: 50} + }, { + id: 4, required: 1, img: {type: 3, w: 300, h: 200} + }, { + id: 5, required: 0, data: {type: 3} + }, { + id: 6, required: 0, data: {type: 6} + }, { + id: 7, required: 0, data: {type: 12} + }, { + id: 8, required: 0, data: {type: 1} + }, { + id: 9, required: 0, data: {type: 11} + } + ], + privacy: 1 + }, adUnitCode: 'ad-unit-1', transactionId: 'f82c64b8-c602-42a4-9791-4a268f6559ed', bidId: 'Bid_01', @@ -679,18 +707,18 @@ describe('Adkernel adapter', function () { expect(bidRequests[0].imp[0]).to.have.property('native'); expect(bidRequests[0].imp[0].native).to.have.property('request'); let request = JSON.parse(bidRequests[0].imp[0].native.request); - expect(request).to.have.property('ver', '1.1'); + expect(request).to.have.property('ver', '1.2'); expect(request.assets).to.have.length(10); expect(request.assets[0]).to.be.eql({id: 0, required: 1, title: {len: 80}}); - expect(request.assets[1]).to.be.eql({id: 3, required: 1, data: {type: 2}}); - expect(request.assets[2]).to.be.eql({id: 4, required: 1, data: {type: 10}}); - expect(request.assets[3]).to.be.eql({id: 1, required: 1, img: {wmin: 50, hmin: 50, type: 1}}); - expect(request.assets[4]).to.be.eql({id: 2, required: 1, img: {w: 300, h: 200, type: 3}}); - expect(request.assets[5]).to.be.eql({id: 11, required: 0, data: {type: 3}}); - expect(request.assets[6]).to.be.eql({id: 8, required: 0, data: {type: 6}}); - expect(request.assets[7]).to.be.eql({id: 10, required: 0, data: {type: 12}}); - expect(request.assets[8]).to.be.eql({id: 5, required: 0, data: {type: 1}}); - expect(request.assets[9]).to.be.eql({id: 14, required: 0, data: {type: 11}}); + expect(request.assets[1]).to.be.eql({id: 1, required: 1, data: {type: 2}}); + expect(request.assets[2]).to.be.eql({id: 2, required: 1, data: {type: 10}}); + expect(request.assets[3]).to.be.eql({id: 3, required: 1, img: {wmin: 50, hmin: 50, type: 1}}); + expect(request.assets[4]).to.be.eql({id: 4, required: 1, img: {w: 300, h: 200, type: 3}}); + expect(request.assets[5]).to.be.eql({id: 5, required: 0, data: {type: 3}}); + expect(request.assets[6]).to.be.eql({id: 6, required: 0, data: {type: 6}}); + expect(request.assets[7]).to.be.eql({id: 7, required: 0, data: {type: 12}}); + expect(request.assets[8]).to.be.eql({id: 8, required: 0, data: {type: 1}}); + expect(request.assets[9]).to.be.eql({id: 9, required: 0, data: {type: 11}}); }); it('native response processing', () => { @@ -707,15 +735,21 @@ describe('Adkernel adapter', function () { expect(resp.meta.secondaryCatIds).to.be.eql(['IAB1-4', 'IAB8-16', 'IAB25-5']); expect(resp).to.have.property('mediaType', NATIVE); expect(resp).to.have.property('native'); - expect(resp.native).to.have.property('clickUrl', 'http://rtb.com/click?i=pTuOlf5KHUo_0'); - expect(resp.native.impressionTrackers).to.be.eql(['http://rtb.com/win?i=pTuOlf5KHUo_0&f=imp']); - expect(resp.native).to.have.property('title', 'Title'); - expect(resp.native).to.have.property('body', 'Description'); - expect(resp.native).to.have.property('body2', 'Additional description'); - expect(resp.native.icon).to.be.eql({url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0&imgt=icon', width: 50, height: 50}); - expect(resp.native.image).to.be.eql({url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0', width: 300, height: 200}); - expect(resp.native).to.have.property('sponsoredBy', 'Sponsor.com'); - expect(resp.native).to.have.property('displayUrl', 'displayurl.com'); + expect(resp.native).to.have.property('ortb'); + + expect(resp.native.ortb).to.be.eql({ + assets: [ + {id: 0, title: {text: 'Title'}}, + {id: 3, data: {value: 'Description'}}, + {id: 4, data: {value: 'Additional description'}}, + {id: 1, img: {url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0&imgt=icon', w: 50, h: 50}}, + {id: 2, img: {url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0', w: 300, h: 200}}, + {id: 5, data: {value: 'Sponsor.com'}}, + {id: 14, data: {value: 'displayurl.com'}} + ], + link: {url: 'http://rtb.com/click?i=pTuOlf5KHUo_0'}, + imptrackers: ['http://rtb.com/win?i=pTuOlf5KHUo_0&f=imp'] + }); }); }); });