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

OpenX Bid Adapter: add support for mediaTypes.video and gpid #6813

Merged
merged 1 commit into from
May 22, 2021
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
56 changes: 45 additions & 11 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import includes from 'core-js-pure/features/array/includes.js'

const SUPPORTED_AD_TYPES = [BANNER, VIDEO];
const VIDEO_TARGETING = ['startdelay', 'mimes', 'minduration', 'maxduration',
'startdelay', 'skippable', 'playbackmethod', 'api', 'protocols', 'boxingallowed',
'linearity', 'delivery', 'protocol', 'placement', 'minbitrate', 'maxbitrate'];
const BIDDER_CODE = 'openx';
const BIDDER_CONFIG = 'hb_pb';
const BIDDER_VERSION = '3.0.3';
Expand Down Expand Up @@ -326,7 +330,12 @@ function buildOXBannerRequest(bids, bidderRequest) {
let auids = utils._map(bids, bid => bid.params.unit);

queryParams.aus = utils._map(bids, bid => utils.parseSizesInput(bid.mediaTypes.banner.sizes).join(',')).join('|');
queryParams.divIds = utils._map(bids, bid => encodeURIComponent(bid.adUnitCode)).join(',');
queryParams.divids = utils._map(bids, bid => encodeURIComponent(bid.adUnitCode)).join(',');
// gpid
queryParams.aucs = utils._map(bids, function (bid) {
let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot');
return encodeURIComponent(gpid || '')
}).join(',');

if (auids.some(auid => auid)) {
queryParams.auid = auids.join(',');
Expand Down Expand Up @@ -382,6 +391,7 @@ function buildOXVideoRequest(bid, bidderRequest) {
}

function generateVideoParameters(bid, bidderRequest) {
const videoMediaType = utils.deepAccess(bid, `mediaTypes.video`);
let queryParams = buildCommonQueryParamsFromBids([bid], bidderRequest);
let oxVideoConfig = utils.deepAccess(bid, 'params.video') || {};
let context = utils.deepAccess(bid, 'mediaTypes.video.context');
Expand All @@ -401,16 +411,35 @@ function generateVideoParameters(bid, bidderRequest) {
height = parseInt(playerSize[1], 10);
}

Object.keys(oxVideoConfig).forEach(function (key) {
if (key === 'openrtb') {
oxVideoConfig[key].w = width || oxVideoConfig[key].w;
oxVideoConfig[key].v = height || oxVideoConfig[key].v;
queryParams[key] = JSON.stringify(oxVideoConfig[key]);
} else if (!(key in queryParams) && key !== 'url') {
// only allow video-related attributes
queryParams[key] = oxVideoConfig[key];
}
});
let openRtbParams = {w: width, h: height};

// legacy openrtb params could be in video, openrtb, or video.openrtb
let legacyParams = bid.params.video || bid.params.openrtb || {};
if (legacyParams.openrtb) {
legacyParams = legacyParams.openrtb;
}
// support for video object or full openrtb object
if (utils.isArray(legacyParams.imp)) {
legacyParams = legacyParams.imp[0].video;
}
Object.keys(legacyParams)
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => openRtbParams[param] = legacyParams[param]);

// 5.0 openrtb video params
Object.keys(videoMediaType)
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => openRtbParams[param] = videoMediaType[param]);

let openRtbReq = {
imp: [
{
video: openRtbParams
}
]
}

queryParams['openrtb'] = JSON.stringify(openRtbReq);

queryParams.auid = bid.params.unit;
// override prebid config with openx config if available
Expand All @@ -429,6 +458,11 @@ function generateVideoParameters(bid, bidderRequest) {
queryParams.vtest = 1;
}

let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot');
if (gpid) {
queryParams.aucs = encodeURIComponent(gpid)
}

// each video bid makes a separate request
enrichQueryWithFloors(queryParams, VIDEO, [bid]);

Expand Down
4 changes: 2 additions & 2 deletions modules/openxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pbjs.setConfig({
```

# Additional Details
[Banner Ads](https://docs.openx.com/Content/developers/containers/prebid-adapter.html)
[Banner Ads](https://docs.openx.com/publishers/prebid-adapter-web/)

[Video Ads](https://docs.openx.com/Content/developers/containers/prebid-video-adapter.html)
[Video Ads](https://docs.openx.com/publishers/prebid-adapter-video/)

101 changes: 81 additions & 20 deletions test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ describe('OpenxAdapter', function () {
},
'bidId': 'test-bid-id-1',
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1'
'auctionId': 'test-auction-1',
'ortb2Imp': { ext: { data: { pbadslot: '/12345/my-gpt-tag-0' } } }
}, {
'bidder': 'openx',
'params': {
Expand All @@ -356,7 +357,8 @@ describe('OpenxAdapter', function () {
},
'bidId': 'test-bid-id-2',
'bidderRequestId': 'test-bid-request-2',
'auctionId': 'test-auction-2'
'auctionId': 'test-auction-2',
'ortb2Imp': { ext: { data: { pbadslot: '/12345/my-gpt-tag-1' } } }
}];

const bidRequestsWithPlatform = [{
Expand Down Expand Up @@ -450,7 +452,12 @@ describe('OpenxAdapter', function () {

it('should send the adunit codes', function () {
const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest);
expect(request[0].data.divIds).to.equal(`${encodeURIComponent(bidRequestsWithMediaTypes[0].adUnitCode)},${encodeURIComponent(bidRequestsWithMediaTypes[1].adUnitCode)}`);
expect(request[0].data.divids).to.equal(`${encodeURIComponent(bidRequestsWithMediaTypes[0].adUnitCode)},${encodeURIComponent(bidRequestsWithMediaTypes[1].adUnitCode)}`);
});

it('should send the gpids', function () {
const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest);
expect(request[0].data.aucs).to.equal(`${encodeURIComponent('/12345/my-gpt-tag-0')},${encodeURIComponent('/12345/my-gpt-tag-1')}`);
});

it('should send ad unit ids when any are defined', function () {
Expand Down Expand Up @@ -1238,7 +1245,8 @@ describe('OpenxAdapter', function () {
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e'
'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e',
'ortb2Imp': { ext: { data: { pbadslot: '/12345/my-gpt-tag-0' } } }
}];
const mockBidderRequest = {refererInfo: {}};

Expand All @@ -1254,6 +1262,7 @@ describe('OpenxAdapter', function () {
expect(dataParams.auid).to.equal('12345678');
expect(dataParams.vht).to.equal(480);
expect(dataParams.vwd).to.equal(640);
expect(dataParams.aucs).to.equal(encodeURIComponent('/12345/my-gpt-tag-0'));
});

it('shouldn\'t have the test parameter', function () {
Expand Down Expand Up @@ -1313,45 +1322,97 @@ describe('OpenxAdapter', function () {
expect(request[0].data.ju).to.not.equal(myUrl);
});

describe('when using the openRtb param', function () {
it('should covert the param to a JSON string', function () {
let myOpenRTBObject = {};
describe('when using the openrtb video params', function () {
it('should parse legacy params.video.openrtb', function () {
let myOpenRTBObject = {mimes: ['application/javascript']};
videoBidRequest.params.video = {
openrtb: myOpenRTBObject
};
const expected = {imp: [{video: {w: 640, h: 480, mimes: ['application/javascript']}}]}
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);

expect(request[0].data.openrtb).to.equal(JSON.stringify(myOpenRTBObject));
expect(request[0].data.openrtb).to.equal(JSON.stringify(expected));
});

it("should use the bidRequest's playerSize when it is available", function () {
const width = 200;
const height = 100;
const myOpenRTBObject = {v: height, w: width};
it('should parse legacy params.openrtb', function () {
let myOpenRTBObject = {mimes: ['application/javascript']};
videoBidRequest.params.openrtb = myOpenRTBObject;
const expected = {imp: [{video: {w: 640, h: 480, mimes: ['application/javascript']}}]}
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);

expect(request[0].data.openrtb).to.equal(JSON.stringify(expected));
});

it('should parse legacy params.video', function () {
let myOpenRTBObject = {mimes: ['application/javascript']};
videoBidRequest.params.video = myOpenRTBObject;
const expected = {imp: [{video: {w: 640, h: 480, mimes: ['application/javascript']}}]}
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);

expect(request[0].data.openrtb).to.equal(JSON.stringify(expected));
});

it('should parse legacy params.video as full openrtb', function () {
let myOpenRTBObject = {imp: [{video: {mimes: ['application/javascript']}}]};
videoBidRequest.params.video = myOpenRTBObject;
const expected = {imp: [{video: {w: 640, h: 480, mimes: ['application/javascript']}}]}
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);

expect(request[0].data.openrtb).to.equal(JSON.stringify(expected));
});

it('should parse legacy video.openrtb', function () {
let myOpenRTBObject = {mimes: ['application/javascript']};
videoBidRequest.params.video = {
openrtb: myOpenRTBObject
};
const expected = {imp: [{video: {w: 640, h: 480, mimes: ['application/javascript']}}]}
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);

expect(request[0].data.openrtb).to.equal(JSON.stringify(expected));
});

it('should omit filtered values for legacy', function () {
let myOpenRTBObject = {mimes: ['application/javascript'], dont: 'use'};
videoBidRequest.params.video = {
openrtb: myOpenRTBObject
};
const expected = {imp: [{video: {w: 640, h: 480, mimes: ['application/javascript']}}]}
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);

expect(request[0].data.openrtb).to.equal(JSON.stringify(expected));
});

it('should parse mediatypes.video', function () {
videoBidRequest.mediaTypes.video.mimes = ['application/javascript']
videoBidRequest.mediaTypes.video.minduration = 15
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);
const openRtbRequestParams = JSON.parse(request[0].data.openrtb);
expect(openRtbRequestParams.imp[0].video.mimes).to.eql(['application/javascript']);
expect(openRtbRequestParams.imp[0].video.minduration).to.equal(15);
});

expect(openRtbRequestParams.w).to.not.equal(width);
expect(openRtbRequestParams.v).to.not.equal(height);
it('should filter mediatypes.video', function () {
videoBidRequest.mediaTypes.video.mimes = ['application/javascript']
videoBidRequest.mediaTypes.video.minnothing = 15
const request = spec.buildRequests([videoBidRequest], mockBidderRequest);
const openRtbRequestParams = JSON.parse(request[0].data.openrtb);
expect(openRtbRequestParams.imp[0].video.mimes).to.eql(['application/javascript']);
expect(openRtbRequestParams.imp[0].video.minnothing).to.equal(undefined);
});

it('should use the the openRTB\'s sizing when the bidRequest\'s playerSize is not available', function () {
it("should use the bidRequest's playerSize", function () {
const width = 200;
const height = 100;
const myOpenRTBObject = {v: height, w: width};
videoBidRequest.params.video = {
openrtb: myOpenRTBObject
};
videoBidRequest.mediaTypes.video.playerSize = undefined;

const request = spec.buildRequests([videoBidRequest], mockBidderRequest);
const openRtbRequestParams = JSON.parse(request[0].data.openrtb);

expect(openRtbRequestParams.w).to.equal(width);
expect(openRtbRequestParams.v).to.equal(height);
expect(openRtbRequestParams.imp[0].video.w).to.equal(640);
expect(openRtbRequestParams.imp[0].video.h).to.equal(480);
});
});
});
Expand Down Expand Up @@ -1465,7 +1526,7 @@ describe('OpenxAdapter', function () {
const request = spec.buildRequests([multiformatBid], mockBidderRequest);
const dataParams = request[0].data;

expect(dataParams.divIds).to.have.string(multiformatBid.adUnitCode);
expect(dataParams.divids).to.have.string(multiformatBid.adUnitCode);
});
});

Expand Down