Skip to content

Commit

Permalink
Undertone 24910 video in prebid (#5485)
Browse files Browse the repository at this point in the history
* support video ads

* support video ads

* fix indentation

Co-authored-by: omerko <omer.koren@perion.com>
Co-authored-by: Omer Koren <omerko@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 23, 2020
1 parent 34ea366 commit 4bd0d32
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
25 changes: 22 additions & 3 deletions modules/undertoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* Adapter to send bids to Undertone
*/

import { parseUrl } from '../src/utils.js';
import { deepAccess, parseUrl } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';

const BIDDER_CODE = 'undertone';
const URL = 'https://hb.undertone.com/hb';
Expand Down Expand Up @@ -73,6 +74,7 @@ function getBannerCoords(id) {

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bid) {
if (bid && bid.params && bid.params.publisherId) {
bid.params.publisherId = parseInt(bid.params.publisherId);
Expand Down Expand Up @@ -120,8 +122,20 @@ export const spec = {
sizes: bidReq.sizes,
params: bidReq.params
};
const videoMediaType = deepAccess(bidReq, 'mediaTypes.video');
if (videoMediaType) {
bid.video = {
playerSize: deepAccess(bidReq, 'mediaTypes.video.playerSize') || null,
streamType: deepAccess(bidReq, 'mediaTypes.video.context') || null,
playbackMethod: deepAccess(bidReq, 'params.video.playbackMethod') || null,
maxDuration: deepAccess(bidReq, 'params.video.maxDuration') || null,
skippable: deepAccess(bidReq, 'params.video.skippable') || null
};
bid.mediaType = 'video';
}
payload['x-ut-hb-params'].push(bid);
});

return {
method: 'POST',
url: reqUrl,
Expand All @@ -144,9 +158,14 @@ export const spec = {
creativeId: bidRes.adId,
currency: bidRes.currency,
netRevenue: bidRes.netRevenue,
ttl: bidRes.ttl || 360,
ad: bidRes.ad
ttl: bidRes.ttl || 360
};
if (bidRes.mediaType && bidRes.mediaType === 'video') {
bid.vastXml = bidRes.ad;
bid.mediaType = bidRes.mediaType;
} else {
bid.ad = bidRes.ad
}
bids.push(bid);
}
});
Expand Down
76 changes: 75 additions & 1 deletion test/spec/modules/undertoneBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,49 @@ const invalidBidReq = {
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746'
};

const bidReq = [{
const videoBidReq = [{
adUnitCode: 'div-gpt-ad-1460505748561-0',
bidder: BIDDER_CODE,
params: {
placementId: '10433394',
publisherId: 12345,
video: {
id: 123,
skippable: true,
playbackMethod: 2,
maxDuration: 30
}
},
mediaTypes: {video: {
context: 'outstream',
playerSize: [640, 480]
}},
sizes: [[300, 250], [300, 600]],
bidId: '263be71e91dd9d',
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746'
},
{
adUnitCode: 'div-gpt-ad-1460505748561-1',
bidder: BIDDER_CODE,
params: {
placementId: '10433395',
publisherId: 12345
},
mediaTypes: {video: {
context: 'outstream',
playerSize: [640, 480]
}},
sizes: [[300, 250], [300, 600]],
bidId: '263be71e91dd9d',
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746'
}];
const bidReq = [{
adUnitCode: 'div-gpt-ad-1460505748561-0',
bidder: BIDDER_CODE,
params: {
placementId: '10433394',
publisherId: 12345,
},
sizes: [[300, 250], [300, 600]],
bidId: '263be71e91dd9d',
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746'
Expand Down Expand Up @@ -147,6 +183,20 @@ const bidResArray = [
ttl: 360
}
];
const bidVideoResponse = [
{
ad: '<xml />',
bidRequestId: '263be71e91dd9d',
cpm: 100,
adId: '123abc',
currency: 'USD',
mediaType: 'video',
netRevenue: true,
width: 300,
height: 250,
ttl: 360
}
];

let element;
let sandbox;
Expand Down Expand Up @@ -241,6 +291,23 @@ describe('Undertone Adapter', () => {
expect(bid2.publisherId).to.equal(12345);
expect(bid2.params).to.be.an('object');
});
it('should send video fields correctly', function () {
const request = spec.buildRequests(videoBidReq, bidderReq);
const bidVideo = JSON.parse(request.data)['x-ut-hb-params'][0];
const bidVideo2 = JSON.parse(request.data)['x-ut-hb-params'][1];

expect(bidVideo.mediaType).to.equal('video');
expect(bidVideo.video).to.be.an('object');
expect(bidVideo.video.playerSize).to.be.an('array');
expect(bidVideo.video.streamType).to.equal('outstream');
expect(bidVideo.video.playbackMethod).to.equal(2);
expect(bidVideo.video.maxDuration).to.equal(30);
expect(bidVideo.video.skippable).to.equal(true);

expect(bidVideo2.video.skippable).to.equal(null);
expect(bidVideo2.video.maxDuration).to.equal(null);
expect(bidVideo2.video.playbackMethod).to.equal(null);
});
it('should send all userIds data to server', function () {
const request = spec.buildRequests(bidReqUserIds, bidderReq);
const bidCommons = JSON.parse(request.data)['commons'];
Expand Down Expand Up @@ -303,6 +370,13 @@ describe('Undertone Adapter', () => {
it('should only use valid bid responses', () => {
expect(spec.interpretResponse({ body: bidResArray }).length).to.equal(1);
});

it('should detect video response', () => {
const videoResult = spec.interpretResponse({body: bidVideoResponse});
const vbid = videoResult[0];

expect(vbid.mediaType).to.equal('video');
});
});

describe('getUserSyncs', () => {
Expand Down

0 comments on commit 4bd0d32

Please sign in to comment.