Skip to content

Commit

Permalink
AppNexus Bid Adapter - add support for video plcmt field (#11244)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker authored Apr 2, 2024
1 parent 3a808fe commit cddb934
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
48 changes: 40 additions & 8 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const URL = 'https://ib.adnxs.com/ut/v3/prebid';
const URL_SIMPLE = 'https://ib.adnxs-simple.com/ut/v3/prebid';
const VIDEO_TARGETING = ['id', 'minduration', 'maxduration',
'skippable', 'playback_method', 'frameworks', 'context', 'skipoffset'];
const VIDEO_RTB_TARGETING = ['minduration', 'maxduration', 'skip', 'skipafter', 'playbackmethod', 'api', 'startdelay'];
const VIDEO_RTB_TARGETING = ['minduration', 'maxduration', 'skip', 'skipafter', 'playbackmethod', 'api', 'startdelay', 'placement', 'plcmt'];
const USER_PARAMS = ['age', 'externalUid', 'external_uid', 'segments', 'gender', 'dnt', 'language'];
const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately
const DEBUG_PARAMS = ['enabled', 'dongle', 'member_id', 'debug_timeout'];
Expand All @@ -72,7 +72,12 @@ const VIDEO_MAPPING = {
'mid_roll': 2,
'post_roll': 3,
'outstream': 4,
'in-banner': 5
'in-banner': 5,
'in-feed': 6,
'interstitial': 7,
'accompanying_content_pre_roll': 8,
'accompanying_content_mid_roll': 9,
'accompanying_content_post_roll': 10
}
};
const NATIVE_MAPPING = {
Expand Down Expand Up @@ -916,15 +921,15 @@ function bidToTag(bid) {
tag['video_frameworks'] = apiTmp;
}
break;

case 'startdelay':
case 'plcmt':
case 'placement':
const contextKey = 'context';
if (typeof tag.video[contextKey] !== 'number') {
if (typeof tag.video.context !== 'number') {
const plcmt = videoMediaType['plcmt'];
const placement = videoMediaType['placement'];
const startdelay = videoMediaType['startdelay'];
const context = getContextFromPlacement(placement) || getContextFromStartDelay(startdelay);
tag.video[contextKey] = VIDEO_MAPPING[contextKey][context];
const contextVal = getContextFromPlcmt(plcmt, startdelay) || getContextFromPlacement(placement) || getContextFromStartDelay(startdelay);
tag.video.context = VIDEO_MAPPING.context[contextVal];
}
break;
}
Expand Down Expand Up @@ -983,8 +988,12 @@ function getContextFromPlacement(ortbPlacement) {

if (ortbPlacement === 2) {
return 'in-banner';
} else if (ortbPlacement > 2) {
} else if (ortbPlacement === 3) {
return 'outstream';
} else if (ortbPlacement === 4) {
return 'in-feed';
} else if (ortbPlacement === 5) {
return 'intersitial';

This comment has been minimized.

Copy link
@michelnguyenfr

michelnguyenfr Jun 13, 2024

should this be 'interstitial' (typo)?

}
}

Expand All @@ -1002,6 +1011,29 @@ function getContextFromStartDelay(ortbStartDelay) {
}
}

function getContextFromPlcmt(ortbPlcmt, ortbStartDelay) {
if (!ortbPlcmt) {
return;
}

if (ortbPlcmt === 2) {
if (!ortbStartDelay) {
return;
}
if (ortbStartDelay === 0) {
return 'accompanying_content_pre_roll';
} else if (ortbStartDelay === -1) {
return 'accompanying_content_mid_roll';
} else if (ortbStartDelay === -2) {
return 'accompanying_content_post_roll';
}
} else if (ortbPlcmt === 3) {
return 'interstitial';
} else if (ortbPlcmt === 4) {
return 'outstream';
}
}

function hasUserInfo(bid) {
return !!bid.params.user;
}
Expand Down
57 changes: 56 additions & 1 deletion test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe('AppNexusAdapter', function () {
expect(payload.tags[0].hb_source).to.deep.equal(1);
});

it('should include ORTB video values when video params were not set', function () {
it('should include ORTB video values when matching video params were not all set', function () {
let bidRequest = deepClone(bidRequests[0]);
bidRequest.params = {
placementId: '1234235',
Expand Down Expand Up @@ -377,6 +377,61 @@ describe('AppNexusAdapter', function () {
expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4])
});

it('should include ORTB video values when video params is empty - case 1', function () {
let bidRequest = deepClone(bidRequests[0]);
bidRequest.mediaTypes = {
video: {
playerSize: [640, 480],
context: 'outstream',
placement: 3,
mimes: ['video/mp4'],
skip: 0,
minduration: 5,
api: [1, 5, 6],
playbackmethod: [2, 4]
}
};

const request = spec.buildRequests([bidRequest]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].video).to.deep.equal({
minduration: 5,
playback_method: 2,
skippable: false,
context: 4
});
expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4])
});

it('should include ORTB video values when video params is empty - case 2', function () {
let bidRequest = deepClone(bidRequests[0]);
bidRequest.mediaTypes = {
video: {
playerSize: [640, 480],
context: 'outstream',
plcmt: 2,
startdelay: -1,
mimes: ['video/mp4'],
skip: 1,
minduration: 5,
api: [1, 5, 6],
playbackmethod: [2, 4]
}
};

const request = spec.buildRequests([bidRequest]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].video).to.deep.equal({
minduration: 5,
playback_method: 2,
skippable: true,
context: 9
});
expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4])
});

it('should add video property when adUnit includes a renderer', function () {
const videoData = {
mediaTypes: {
Expand Down

0 comments on commit cddb934

Please sign in to comment.