Skip to content

Commit

Permalink
Adkernel: added mediatypes.* attributes support (#10472)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckbo3hrk committed Sep 14, 2023
1 parent 6438f27 commit 61d4f5c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
57 changes: 28 additions & 29 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
*
* Please contact [email protected] and we'll add your adapter as an alias.
*/
const VIDEO_PARAMS = ['pos', 'context', 'placement', 'api', 'mimes', 'protocols', 'playbackmethod', 'minduration', 'maxduration',
const VIDEO_PARAMS = ['pos', 'context', 'placement', 'plcmt', 'api', 'mimes', 'protocols', 'playbackmethod', 'minduration', 'maxduration',
'startdelay', 'linearity', 'skip', 'skipmin', 'skipafter', 'minbitrate', 'maxbitrate', 'delivery', 'playbackend', 'boxingallowed'];
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 SYNC_IFRAME = 1;
const SYNC_IMAGE = 2;
const SYNC_TYPES = Object.freeze({
const SYNC_TYPES = {
1: 'iframe',
2: 'image'
});
};
const GVLID = 14;

const NATIVE_MODEL = [
Expand Down Expand Up @@ -275,33 +276,37 @@ function buildImp(bidRequest, secure) {
var mediaType;
var sizes = [];

if (deepAccess(bidRequest, 'mediaTypes.banner')) {
if (bidRequest.mediaTypes?.banner) {
sizes = getAdUnitSizes(bidRequest);
let pbBanner = bidRequest.mediaTypes.banner;
imp.banner = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, BANNER_FPD),
...getDefinedParamsOrEmpty(pbBanner, BANNER_PARAMS),
format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)),
topframe: 0
};
populateImpFpd(imp.banner, bidRequest, BANNER_FPD);
mediaType = BANNER;
} else if (deepAccess(bidRequest, 'mediaTypes.video')) {
let video = deepAccess(bidRequest, 'mediaTypes.video');
imp.video = getDefinedParams(video, VIDEO_PARAMS);
populateImpFpd(imp.video, bidRequest, VIDEO_FPD);
if (video.playerSize) {
sizes = video.playerSize[0];
} else if (bidRequest.mediaTypes?.video) {
let pbVideo = bidRequest.mediaTypes.video;
imp.video = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, VIDEO_FPD),
...getDefinedParamsOrEmpty(pbVideo, VIDEO_PARAMS)
};
if (pbVideo.playerSize) {
sizes = pbVideo.playerSize[0];
imp.video = Object.assign(imp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {});
} else if (video.w && video.h) {
imp.video.w = video.w;
imp.video.h = video.h;
} else if (pbVideo.w && pbVideo.h) {
imp.video.w = pbVideo.w;
imp.video.h = pbVideo.h;
}
mediaType = VIDEO;
} else if (deepAccess(bidRequest, 'mediaTypes.native')) {
} else if (bidRequest.mediaTypes?.native) {
let nativeRequest = buildNativeRequest(bidRequest.mediaTypes.native);
imp.native = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, NATIVE_FPD),
ver: '1.1',
request: JSON.stringify(nativeRequest)
};
populateImpFpd(imp.native, bidRequest, NATIVE_FPD);
mediaType = NATIVE;
} else {
throw new Error('Unsupported bid received');
Expand All @@ -316,6 +321,13 @@ function buildImp(bidRequest, secure) {
return imp;
}

function getDefinedParamsOrEmpty(object, params) {
if (object === undefined) {
return {};
}
return getDefinedParams(object, params);
}

/**
* Builds native request from native adunit
*/
Expand Down Expand Up @@ -345,19 +357,6 @@ function buildNativeRequest(nativeReq) {
return request;
}

/**
* Populate impression-level FPD from bid request
* @param target {Object}
* @param bidRequest {BidRequest}
* @param props {String[]}
*/
function populateImpFpd(target, bidRequest, props) {
if (bidRequest.ortb2Imp === undefined) {
return;
}
Object.assign(target, getDefinedParams(bidRequest.ortb2Imp, props));
}

/**
* Builds image asset request
*/
Expand Down
26 changes: 21 additions & 5 deletions test/spec/modules/adkernelBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ describe('Adkernel adapter', function () {
auctionId: 'auc-001',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 200]]
sizes: [[300, 250], [300, 200]],
pos: 1
}
},
ortb2Imp: {
battr: [6, 7, 9]
battr: [6, 7, 9],
pos: 2
}
}, bid2_zone2 = {
bidder: 'adkernel',
Expand Down Expand Up @@ -103,7 +105,11 @@ describe('Adkernel adapter', function () {
video: {
context: 'instream',
playerSize: [[640, 480]],
api: [1, 2]
api: [1, 2],
placement: 1,
plcmt: 1,
skip: 1,
pos: 1
}
},
adUnitCode: 'ad-unit-1'
Expand Down Expand Up @@ -346,6 +352,11 @@ describe('Adkernel adapter', function () {
expect(bidRequest.imp[0].banner.battr).to.be.eql([6, 7, 9]);
});

it('should respect mediatypes attributes over FPD', function() {
expect(bidRequest.imp[0].banner).to.have.property('pos');
expect(bidRequest.imp[0].banner.pos).to.be.eql(1);
});

it('shouldn\'t contain gdpr nor ccpa information for default request', function () {
let [_, bidRequests] = buildRequest([bid1_zone1]);
expect(bidRequests[0]).to.not.have.property('regs');
Expand Down Expand Up @@ -438,8 +449,13 @@ describe('Adkernel adapter', function () {
});

it('should have openrtb video impression parameters', function() {
expect(bidRequests[0].imp[0].video).to.have.property('api');
expect(bidRequests[0].imp[0].video.api).to.be.eql([1, 2]);
let video = bidRequests[0].imp[0].video;
expect(video).to.have.property('api');
expect(video.api).to.be.eql([1, 2]);
expect(video.placement).to.be.eql(1);
expect(video.plcmt).to.be.eql(1);
expect(video.skip).to.be.eql(1);
expect(video.pos).to.be.eql(1);
});
});

Expand Down

0 comments on commit 61d4f5c

Please sign in to comment.