Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adkernel Bid Adapter: switch to ortb native implementation #11291

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 14 additions & 99 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
_each,
cleanObj,
contains,
createTrackPixelHtml,
deepAccess,
Expand All @@ -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';

/**
Expand All @@ -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 = {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
74 changes: 54 additions & 20 deletions test/spec/modules/adkernelBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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']
});
});
});
});