Skip to content

Commit

Permalink
Triplelift: Add Instream support (#5472)
Browse files Browse the repository at this point in the history
* initial commit, instream poc done

* push in poc changes

* push in poc changes

* restore instream.html

* push in poc changes

* restore instream.html

* restore instream.html v2

* adding instream unit tests v1

* catch up to bidfloor changes

* unit tests finalized!

* update adapter md

* add support for mediaTypes.video

Co-authored-by: Sy Dao <[email protected]>
  • Loading branch information
sdao-tl and iam-sydao authored Aug 12, 2020
1 parent b591906 commit 4d2b401
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 110 deletions.
50 changes: 37 additions & 13 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BANNER } from '../src/mediaTypes.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
Expand All @@ -11,9 +11,13 @@ let consentString = null;
export const tripleliftAdapterSpec = {

code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: function(bid) {
return (typeof bid.params.inventoryCode !== 'undefined');
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function (bid) {
if (bid.mediaTypes.video) {
let video = _getORTBVideo(bid);
if (!video.w || !video.h) return false;
}
return typeof bid.params.inventoryCode !== 'undefined';
},

buildRequests: function(bidRequests, bidderRequest) {
Expand Down Expand Up @@ -107,15 +111,18 @@ function _getSyncType(syncOptions) {
function _buildPostBody(bidRequests) {
let data = {};
let { schain } = bidRequests[0];
data.imp = bidRequests.map(function(bid, index) {
return {
data.imp = bidRequests.map(function(bidRequest, index) {
let imp = {
id: index,
tagid: bid.params.inventoryCode,
floor: _getFloor(bid),
banner: {
format: _sizes(bid.sizes)
}
tagid: bidRequest.params.inventoryCode,
floor: _getFloor(bidRequest)
};
if (bidRequest.mediaTypes.video) {
imp.video = _getORTBVideo(bidRequest);
} else if (bidRequest.mediaTypes.banner) {
imp.banner = { format: _sizes(bidRequest.sizes) };
};
return imp;
});

let eids = [
Expand All @@ -138,6 +145,17 @@ function _buildPostBody(bidRequests) {
return data;
}

function _getORTBVideo(bidRequest) {
// give precedent to mediaTypes.video
let video = { ...bidRequest.params.video, ...bidRequest.mediaTypes.video };
if (!video.w) video.w = video.playerSize[0][0];
if (!video.h) video.h = video.playerSize[0][1];
if (video.context === 'instream') video.placement = 1;
// clean up oRTB object
delete video.playerSize;
return video;
}

function _getFloor (bid) {
let floor = null;
if (typeof bid.getFloor === 'function') {
Expand Down Expand Up @@ -207,10 +225,11 @@ function _buildResponseObject(bidderRequest, bid) {
let height = bid.height || 1;
let dealId = bid.deal_id || '';
let creativeId = bid.crid || '';
let breq = bidderRequest.bids[bid.imp_id];

if (bid.cpm != 0 && bid.ad) {
bidResponse = {
requestId: bidderRequest.bids[bid.imp_id].bidId,
requestId: breq.bidId,
cpm: bid.cpm,
width: width,
height: height,
Expand All @@ -220,7 +239,12 @@ function _buildResponseObject(bidderRequest, bid) {
dealId: dealId,
currency: 'USD',
ttl: 300,
tl_source: bid.tl_source,
tl_source: bid.tl_source
};

if (breq.mediaTypes.video) {
bidResponse.vastXml = bid.ad;
bidResponse.mediaType = 'video';
};
};
return bidResponse;
Expand Down
20 changes: 20 additions & 0 deletions modules/tripleliftBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,25 @@ var adUnits = [{
floor: 0
}
}]
}, {
code: 'instream-div-1',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream',
}
},
bids: [
{
bidder: 'triplelift',
params: {
inventoryCode: 'instream_test',
video: {
mimes: ['video/mp4'],
w: 640,
h: 480,
},
}
}]
}];
```
Loading

0 comments on commit 4d2b401

Please sign in to comment.