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 outstream feature #7325

Merged
merged 10 commits into from
Aug 24, 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
63 changes: 54 additions & 9 deletions modules/tappxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';

const BIDDER_CODE = 'tappx';
const TTL = 360;
const CUR = 'USD';
const TAPPX_BIDDER_VERSION = '0.1.10714';
const TAPPX_BIDDER_VERSION = '0.1.0818';
const TYPE_CNN = 'prebidjs';
const LOG_PREFIX = '[TAPPX]: ';
const VIDEO_SUPPORT = ['instream'];
const VIDEO_SUPPORT = ['instream', 'outstream'];

const DATA_TYPES = {
'NUMBER': 'number',
Expand Down Expand Up @@ -161,9 +162,9 @@ function validMediaType(bid) {
const video = utils.deepAccess(bid, 'mediaTypes.video');

// Video validations
if (typeof video != 'undefined') {
if (typeof video !== 'undefined') {
if (VIDEO_SUPPORT.indexOf(video.context) === -1) {
utils.logWarn(LOG_PREFIX, 'Please review the mandatory Tappx parameters for Video. Only "instream" is suported.');
utils.logWarn(LOG_PREFIX, 'Please review the mandatory Tappx parameters for Video. Video context not supported.');
return false;
}
if (typeof video.mimes == 'undefined') {
Expand Down Expand Up @@ -193,19 +194,30 @@ function interpretBid(serverBid, request) {
netRevenue: true,
}

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

if (typeof request.bids.mediaTypes != 'undefined' && typeof request.bids.mediaTypes.video != 'undefined') {
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;
bidReturned.width = serverBid.w;
bidReturned.height = serverBid.h;

if (request.bids.mediaTypes.video.context === 'outstream') {
const url = (serverBid.ext.purl) ? serverBid.ext.purl : false;
if (typeof url === 'undefined') {
utils.logWarn(LOG_PREFIX, 'Error getting player outstream from tappx');
return false;
}
bidReturned.renderer = createRenderer(bidReturned, request, url);
}
} else {
bidReturned.ad = serverBid.adm;
bidReturned.mediaType = BANNER;
}

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

Expand Down Expand Up @@ -290,7 +302,7 @@ function buildOneRequest(validBidRequests, bidderRequest) {
imp.banner = banner;
}

if (videoMediaType) {
if (typeof videoMediaType !== 'undefined') {
let video = {};

let videoParams = utils.deepAccess(validBidRequests, 'params.video');
Expand Down Expand Up @@ -410,6 +422,10 @@ function buildOneRequest(validBidRequests, bidderRequest) {
payloadExt.bidder.mktag = MKTAG;
payloadExt.bidder.bcid = utils.deepAccess(validBidRequests, 'params.bcid');
payloadExt.bidder.bcrid = utils.deepAccess(validBidRequests, 'params.bcrid');
payloadExt.bidder.ext = (typeof BIDEXTRA == 'object') ? BIDEXTRA : {};
if (typeof videoMediaType !== 'undefined') {
payloadExt.bidder.ext.pbvidtype = videoMediaType.context;
}
// < Payload Ext

// > Payload
Expand All @@ -426,7 +442,7 @@ function buildOneRequest(validBidRequests, bidderRequest) {
payload.regs = regs;
// < Payload

let pbjsv = ($$PREBID_GLOBAL$$.version != null) ? encodeURIComponent($$PREBID_GLOBAL$$.version) : -1;
let pbjsv = ($$PREBID_GLOBAL$$.version !== null) ? encodeURIComponent($$PREBID_GLOBAL$$.version) : -1;

return {
method: 'POST',
Expand Down Expand Up @@ -469,6 +485,35 @@ export function _getHostInfo(validBidRequests) {
return domainInfo;
}

function outstreamRender(bid, request) {
bid.renderer.push(() => {
window.tappxOutstream.renderAd({
sizes: [bid.width, bid.height],
targetId: bid.adUnitCode,
adResponse: bid.adResponse,
rendererOptions: {
content: bid.vastXml
}
});
});
}

function createRenderer(bid, request, url) {
const rendererInst = Renderer.install({
id: request.id,
url: url,
loaded: false
});

try {
rendererInst.setRender(outstreamRender);
} catch (err) {
utils.logWarn(LOG_PREFIX, 'Prebid Error calling setRender on renderer');
}

return rendererInst;
}

export function _checkParamDataType(key, value, datatype) {
var errMsg = 'Ignoring param key: ' + key + ', expects ' + datatype + ', found ' + typeof value;
var functionToExecute;
Expand Down
4 changes: 2 additions & 2 deletions modules/tappxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Maintainer: [email protected]

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

Expand Down Expand Up @@ -55,7 +55,7 @@ Ads sizes available: [300,250], [320,50], [320,480], [480,320], [728,90], [768,1
},
mediaTypes: {
video: {
context: "instream",
context: %CONTEXT%, // Could be "instream" or "outstream"
mimes : [ "video/mp4", "application/javascript" ],
playerSize: [320, 250]
}
Expand Down
Loading