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 : update mediatypes.* attributes support #10472

Merged
merged 1 commit into from
Sep 14, 2023
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
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 @@ -276,33 +277,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 @@ -317,6 +322,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 @@ -346,19 +358,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