Skip to content

Commit

Permalink
Triplelift Bid Adapter: outstream support (prebid#8709)
Browse files Browse the repository at this point in the history
* alt outstream support

* removes consoleLog

* rename video ttl

* multi-imp

* simplify video if statement in buildPostBody

* distinguish banner from video bid; temp solution for testing

* adds tests for mediatype

* remove console log

* individual instream/outstream tests

* simplify some functions

* nitpick

* adds media_type check

* adds placement options to outstream

* checks instream placement values

* TL-19850 Finished log error logic around floors functionality

* deprecates getlegacyFpd

* remove console log

* TL-19850 Changed functionlity of tests

* restore logErrorSpy aftereach

* removing pub name from test

Co-authored-by: Dan Goldin <[email protected]>
Co-authored-by: Patrick Loughrey <[email protected]>
Co-authored-by: Patrick Loughrey <[email protected]>
  • Loading branch information
4 people authored Jul 28, 2022
1 parent ef86ab1 commit 82d74d2
Show file tree
Hide file tree
Showing 2 changed files with 423 additions and 29 deletions.
64 changes: 45 additions & 19 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const GVLID = 28;
const BIDDER_CODE = 'triplelift';
const STR_ENDPOINT = 'https://tlx.3lift.com/header/auction?';
const BANNER_TIME_TO_LIVE = 300;
const INSTREAM_TIME_TO_LIVE = 3600;
const VIDEO_TIME_TO_LIVE = 3600;
let gdprApplies = true;
let consentString = null;
export const storage = getStorageManager({gvlid: GVLID, bidderCode: BIDDER_CODE});
Expand Down Expand Up @@ -120,12 +120,15 @@ function _buildPostBody(bidRequests, bidderRequest) {
tagid: bidRequest.params.inventoryCode,
floor: _getFloor(bidRequest)
};
// remove the else to support multi-imp
if (_isInstreamBidRequest(bidRequest)) {
// Check for video bidrequest
if (_isVideoBidRequest(bidRequest)) {
imp.video = _getORTBVideo(bidRequest);
} else if (bidRequest.mediaTypes.banner) {
}
// append banner if applicable and request is not for instream
if (bidRequest.mediaTypes.banner && !_isInstream(bidRequest)) {
imp.banner = { format: _sizes(bidRequest.sizes) };
};
}

if (!isEmpty(bidRequest.ortb2Imp)) {
imp.fpd = _getAdUnitFpd(bidRequest.ortb2Imp);
}
Expand Down Expand Up @@ -153,22 +156,41 @@ function _buildPostBody(bidRequests, bidderRequest) {
return data;
}

function _isInstreamBidRequest(bidRequest) {
if (!bidRequest.mediaTypes.video) return false;
if (!bidRequest.mediaTypes.video.context) return false;
if (bidRequest.mediaTypes.video.context.toLowerCase() === 'instream') {
return true;
} else {
return false;
}
function _isVideoBidRequest(bidRequest) {
return _isValidVideoObject(bidRequest) && (_isInstream(bidRequest) || _isOutstream(bidRequest));
}

function _isOutstream(bidRequest) {
return _isValidVideoObject(bidRequest) && bidRequest.mediaTypes.video.context.toLowerCase() === 'outstream';
}

function _isInstream(bidRequest) {
return _isValidVideoObject(bidRequest) && bidRequest.mediaTypes.video.context.toLowerCase() === 'instream';
}

function _isValidVideoObject(bidRequest) {
return bidRequest.mediaTypes.video && bidRequest.mediaTypes.video.context;
}

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];
try {
if (!video.w) video.w = video.playerSize[0][0];
if (!video.h) video.h = video.playerSize[0][1];
} catch (err) {
logWarn('Video size not defined', err);
}
if (video.context === 'instream') video.placement = 1;
if (video.context === 'outstream') {
if (!video.placement) {
video.placement = 3
} else if ([3, 4, 5].indexOf(video.placement) === -1) {
logMessage(`video.placement value of ${video.placement} is invalid for outstream context. Setting placement to 3`)
video.placement = 3
}
}

// clean up oRTB object
delete video.playerSize;
return video;
Expand All @@ -180,7 +202,7 @@ function _getFloor (bid) {
try {
const floorInfo = bid.getFloor({
currency: 'USD',
mediaType: _isInstreamBidRequest(bid) ? 'video' : 'banner',
mediaType: _isVideoBidRequest(bid) ? 'video' : 'banner',
size: '*'
});
if (typeof floorInfo === 'object' &&
Expand Down Expand Up @@ -366,10 +388,10 @@ function _buildResponseObject(bidderRequest, bid) {
meta: {}
};

if (_isInstreamBidRequest(breq)) {
if (_isVideoBidRequest(breq) && bid.media_type === 'video') {
bidResponse.vastXml = bid.ad;
bidResponse.mediaType = 'video';
bidResponse.ttl = INSTREAM_TIME_TO_LIVE;
bidResponse.ttl = VIDEO_TIME_TO_LIVE;
};

if (bid.advertiser_name) {
Expand All @@ -381,7 +403,11 @@ function _buildResponseObject(bidderRequest, bid) {
}

if (bid.tl_source && bid.tl_source == 'hdx') {
bidResponse.meta.mediaType = 'banner';
if (_isVideoBidRequest(breq) && bid.media_type === 'video') {
bidResponse.meta.mediaType = 'video'
} else {
bidResponse.meta.mediaType = 'banner'
}
}

if (bid.tl_source && bid.tl_source == 'tlx') {
Expand Down
Loading

0 comments on commit 82d74d2

Please sign in to comment.