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

tappx Bid Adapter: add video instream support and update testing #6580

Merged
merged 6 commits into from
Apr 16, 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
81 changes: 66 additions & 15 deletions modules/tappxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';

const BIDDER_CODE = 'tappx';
const TTL = 360;
const CUR = 'USD';
const TAPPX_BIDDER_VERSION = '0.1.10329';
const TAPPX_BIDDER_VERSION = '0.1.10413';
const TYPE_CNN = 'prebidjs';
const VIDEO_SUPPORT = ['instream'];

var HOST;
var hostDomain;

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],

/**
* Determines whether or not the given bid request is valid.
Expand All @@ -24,11 +26,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
if ((bid.params == null) || (bid.params.endpoint == null) || (bid.params.tappxkey == null)) {
utils.logWarn(`[TAPPX]: Please review the mandatory Tappx parameters. ${JSON.stringify(bid)}`);
return false;
}
return true;
return validBasic(bid) && validMediaType(bid)
},

/**
Expand Down Expand Up @@ -63,7 +61,7 @@ export const spec = {
const bids = [];
responseBody.seatbid.forEach(serverSeatBid => {
serverSeatBid.bid.forEach(serverBid => {
bids.push(interpretBannerBid(serverBid, originalRequest));
bids.push(interpretBid(serverBid, originalRequest));
});
});

Expand Down Expand Up @@ -106,25 +104,66 @@ export const spec = {
}
}

function validBasic(bid) {
if (
(bid.params == null) ||
(bid.params.endpoint == null) ||
(bid.params.tappxkey == null)) {
utils.logWarn(`[TAPPX]: Please review the mandatory Tappx parameters.`);
return false;
}
return true;
}

function validMediaType(bid) {
const video = utils.deepAccess(bid, 'mediaTypes.video');

// Video validations
if (typeof video != 'undefined') {
if (VIDEO_SUPPORT.indexOf(video.context) === -1) {
utils.logWarn(`[TAPPX]: Please review the mandatory Tappx parameters for Video. Only "instream" is suported.`);
return false;
}
}

return true;
}

/**
* Parse the response and generate one bid object.
*
* @param {object} serverBid Bid by OpenRTB 2.5
* @returns {object} Prebid banner bidObject
*/
function interpretBannerBid(serverBid, request) {
return {
function interpretBid(serverBid, request) {
let bidReturned = {
requestId: request.bids.bidId,
cpm: serverBid.price,
currency: serverBid.cur ? serverBid.cur : CUR,
width: serverBid.w,
height: serverBid.h,
ad: serverBid.adm,
ttl: TTL,
creativeId: serverBid.crid,
netRevenue: true,
mediaType: BANNER,
}

if (typeof serverBid.dealId != 'undefined') { bidReturned.dealId = serverBid.dealId }

if (typeof request.bids.mediaTypes != 'undefined' && typeof request.bids.mediaTypes.video != 'undefined') {
bidReturned.vastXml = serverBid.adm;
bidReturned.vastUrl = serverBid.lurl;
bidReturned.ad = serverBid.adm;
bidReturned.mediaType = VIDEO;
} else {
bidReturned.ad = serverBid.adm;
bidReturned.mediaType = BANNER;
}

if (typeof bidReturned.adomain != 'undefined' || bidReturned.adomain != null) {
bidReturned.meta = { advertiserDomains: request.bids.adomain };
}

return bidReturned;
}

/**
Expand All @@ -136,14 +175,14 @@ function interpretBannerBid(serverBid, request) {
*/
function buildOneRequest(validBidRequests, bidderRequest) {
HOST = utils.deepAccess(validBidRequests, 'params.host');
let hostInfo = getHostInfo(HOST)
// hostDomain = HOST.split('/', 1)[0];
let hostInfo = getHostInfo(HOST);
hostDomain = hostInfo.domain;

const ENDPOINT = utils.deepAccess(validBidRequests, 'params.endpoint');
const TAPPXKEY = utils.deepAccess(validBidRequests, 'params.tappxkey');
const BIDFLOOR = utils.deepAccess(validBidRequests, 'params.bidfloor');
const bannerMediaType = utils.deepAccess(validBidRequests, 'mediaTypes.banner');
const videoMediaType = utils.deepAccess(validBidRequests, 'mediaTypes.video');
const { refererInfo } = bidderRequest;

// let requests = [];
Expand Down Expand Up @@ -205,6 +244,18 @@ function buildOneRequest(validBidRequests, bidderRequest) {
imp.banner = banner;
}

if (videoMediaType) {
let video = {};
w = videoMediaType.playerSize[0][0];
h = videoMediaType.playerSize[0][1];
video.w = w;
video.h = h;

video.mimes = videoMediaType.mimes;

imp.video = video;
}

imp.id = validBidRequests.bidId;
imp.tagid = tagid;
imp.secure = 1;
Expand Down
33 changes: 33 additions & 0 deletions modules/tappxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Maintainer: [email protected]

# Description
Module that connects to :tappx demand sources.
Suppots Banner and Instream Video.
Please use ```tappx``` as the bidder code.
Ads sizes available: [320,50], [300,250], [320,480], [1024,768], [728,90]

Expand Down Expand Up @@ -35,3 +36,35 @@ Ads sizes available: [320,50], [300,250], [320,480], [1024,768], [728,90]
}
];
```


# Video Test Parameters
```
var adUnits = [
{
code: 'video-ad-div',
renderer: {
options: {
text: "Tappx instream Video"
}
},
mediaTypes: {
video: {
context: "instream",
mimes : [ "video/mp4", "application/javascript" ],
playerSize: [320, 250]
}
},
bids: [{
bidder: 'tappx',
params: {
host: "testing.ssp.tappx.com/rtb/v2/",
tappxkey: "pub-1234-desktop-1234",
endpoint: "VZ12TESTCTV",
bidfloor: 0.005,
test: true
}
}]
}
];
```
Loading