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: fix site param and add extra video params #7451

Merged
merged 10 commits into from
Sep 29, 2021
34 changes: 16 additions & 18 deletions modules/tappxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Renderer } from '../src/Renderer.js';
const BIDDER_CODE = 'tappx';
const TTL = 360;
const CUR = 'USD';
const TAPPX_BIDDER_VERSION = '0.1.0818';
const TAPPX_BIDDER_VERSION = '0.1.0921';
const TYPE_CNN = 'prebidjs';
const LOG_PREFIX = '[TAPPX]: ';
const VIDEO_SUPPORT = ['instream', 'outstream'];
Expand Down Expand Up @@ -195,6 +195,9 @@ function interpretBid(serverBid, request) {
}

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

if (typeof request.bids.mediaTypes !== 'undefined' && typeof request.bids.mediaTypes.video !== 'undefined') {
bidReturned.vastXml = serverBid.adm;
Expand Down Expand Up @@ -324,6 +327,12 @@ function buildOneRequest(validBidRequests, bidderRequest) {

video.mimes = videoMediaType.mimes;

let videoExt = {};
if ((typeof videoMediaType.rewarded !== 'undefined') && videoMediaType.rewarded == 1) {
videoExt.rewarded = videoMediaType.rewarded;
}
video.ext = videoExt;

imp.video = video;
}

Expand Down Expand Up @@ -492,7 +501,8 @@ function outstreamRender(bid, request) {
targetId: bid.adUnitCode,
adResponse: bid.adResponse,
rendererOptions: {
content: bid.vastXml
content: bid.vastXml,
skip: (typeof bid.params[0].video.skip != 'undefined' && bid.params[0].video.skip > 0) ? bid.params[0].video.skip : 0
}
});
});
Expand Down Expand Up @@ -539,30 +549,18 @@ export function _checkParamDataType(key, value, datatype) {
}

export function _extractPageUrl(validBidRequests, bidderRequest) {
let domainUrl = deepAccess(validBidRequests, 'params.domainUrl');
let referrer = deepAccess(bidderRequest, 'refererInfo.referer');
let page = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || deepAccess(window, 'location.href');
let paramUrl = deepAccess(validBidRequests, 'params.domainUrl') || config.getConfig('pageUrl');

if (typeof domainUrl == 'undefined' || domainUrl == null) {
domainUrl = config.getConfig('pageUrl') || deepAccess(bidderRequest, 'refererInfo.canonicalUrl');
}

if (typeof domainUrl == 'undefined' || domainUrl == null) {
try {
domainUrl = window.top.document.head.querySelector('link[rel="canonical"][href]').getAttribute('href');
} catch (error) {
domainUrl = undefined;
}
}
let domainUrl = referrer || page || paramUrl;

try {
domainUrl = domainUrl.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img)[0].replace(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?/img, '');
} catch (error) {
domainUrl = undefined;
}

if (typeof domainUrl == 'undefined' || domainUrl == null) {
domainUrl = window.location.hostname;
}

return domainUrl;
}

Expand Down
42 changes: 39 additions & 3 deletions test/spec/modules/tappxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from 'chai';
import { spec } from 'modules/tappxBidAdapter.js';
import { _checkParamDataType, _getHostInfo } from '../../../modules/tappxBidAdapter.js';
import { _checkParamDataType, _getHostInfo, _extractPageUrl } from '../../../modules/tappxBidAdapter.js';

const c_BIDREQUEST = {
data: {
Expand Down Expand Up @@ -70,7 +70,10 @@ const c_SERVERRESPONSE_B = {
adm: "<!-- Tappx Test AD :: 320x480 --><a href='http://www.tappx.com' target=\"_blank\">\t<img src='https://testing.ssp.tappx.com/zcdn/creatives/interstitial320x480.gif'></a>",
w: 320,
h: 480,
lurl: 'http://testing.ssp.tappx.com/rtb/RTBv2Loss?id=3811165568213389257&ep=ZZ1234PBJS&au=test&bu=localhost&sz=320x480&pu=0.005&pt=0.01&cid=&crid=&adv=&aid=${AUCTION_ID}&bidid=${AUCTION_BID_ID}&impid=${AUCTION_IMP_ID}&sid=${AUCTION_SEAT_ID}&adid=${AUCTION_AD_ID}&ap=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}&mbr=${AUCTION_MBR}&l=${AUCTION_LOSS}',
lurl: 'https:\/\/ssp.api.tappx.com\/burlURL',
burl: 'https:\/\/ssp.api.tappx.com\/burlURL',
nurl: 'https:\/\/ssp.api.tappx.com\/nurllURL',
dealId: 'b21d0704-9688-4e46-81d9-41de1050fef7',
cid: '01744fbb521e9fb10ffea926190effea',
crid: 'a13cf884e66e7c660afec059c89d98b6',
adomain: [
Expand Down Expand Up @@ -98,7 +101,10 @@ const c_SERVERRESPONSE_V = {
impid: 1,
price: 0.05,
adm: "<?xml version='1.0'?><VAST version='2.0'><Ad id='4381'><InLine><AdSystem>Tappx<\/AdSystem><AdTitle>Tappx<\/AdTitle><Description \/><Impression><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/impression?tag=VZ12TESTCTV]]><\/Impression><Error><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/error?tag=VZ12TESTCTV]]><\/Error><Creatives><Creative AdID='4381'><Linear><Duration>00:00:22<\/Duration><TrackingEvents><Tracking event='start'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/start?tag=VZ12TESTCTV]]><\/Tracking><Tracking event='pause'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/pause?tag=VZ12TESTCTV]]><\/Tracking><Tracking event='complete'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/complete?tag=VZ12TESTCTV]]><\/Tracking><Tracking event='mute'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/mute?tag=VZ12TESTCTV]]><\/Tracking><Tracking event='firstQuartile'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/firstquartile?tag=VZ12TESTCTV]]><\/Tracking><Tracking event='midpoint'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/midpoint?tag=VZ12TESTCTV]]><\/Tracking><Tracking event='thirdQuartile'><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/thirdquartile?tag=VZ12TESTCTV]]><\/Tracking><\/TrackingEvents><VideoClicks><ClickThrough id='ang'><![CDATA[https:\/\/play.google.com\/store\/apps\/details?id=com.tappx.flipnsave.battery&hl=en]]><\/ClickThrough><ClickTracking><![CDATA[https:\/\/ssp.api.tappx.com\/vasttag\/tracker\/click?tag=VZ12TESTCTV]]><\/ClickTracking><\/VideoClicks><MediaFiles><MediaFile delivery='progressive' type='video\/mp4' bitrate='763' width='640' height='480' scalable='true' maintainAspectRatio='true'><![CDATA[https:\/\/ssp.api.tappx.com\/zcdn\/videos\/flipnsave_01_low.mp4]]><\/MediaFile><\/MediaFiles><\/Linear><\/Creative><\/Creatives><\/InLine><\/Ad><\/VAST>",
'lurl': 'https:\/\/ssp.api.tappx.com\/rtb\/RTBv2Loss?id=5001829913749291152&ep=VZ12TESTCTV&au=test&bu=localhost&sz=6x6&pu=0.005&pt=0.01&cid=&crid=&adv=&aid=${AUCTION_ID}&bidid=${AUCTION_BID_ID}&impid=${AUCTION_IMP_ID}&sid=${AUCTION_SEAT_ID}&adid=${AUCTION_AD_ID}&ap=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}&mbr=${AUCTION_MBR}&l=${AUCTION_LOSS}',
lurl: 'https:\/\/ssp.api.tappx.com\/lurlURL',
burl: 'https:\/\/ssp.api.tappx.com\/burlURL',
nurl: 'https:\/\/ssp.api.tappx.com\/nurllURL',
dealId: 'b21d0704-9688-4e46-81d9-41de1050fef7',
cid: '01744fbb521e9fb10ffea926190effea',
crid: 'a13cf884e66e7c660afec059c89d98b6',
adomain: [
Expand Down Expand Up @@ -257,6 +263,27 @@ describe('Tappx bid adapter', function () {
expect(data.imp[0].video).to.not.equal(null);
});

it('should properly create video rewarded request', function () {
delete validBidRequests_Voutstream[0].mediaTypes.banner
validBidRequests_Voutstream[0].mediaTypes.video = {};
validBidRequests_Voutstream[0].mediaTypes.video.rewarded = 1;
validBidRequests_Voutstream[0].mediaTypes.video.playerSize = [640, 480];
validBidRequests_Voutstream[0].mediaTypes.video.context = 'outstream';
validBidRequests_Voutstream[0].mediaTypes.video.mimes = [ 'video/mp4', 'application/javascript' ];

bidderRequest_VOutstream.bids.mediaTypes.context = 'outstream';

const request = spec.buildRequests(validBidRequests_Voutstream, bidderRequest_VOutstream);
expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/);
expect(request[0].method).to.equal('POST');

const data = JSON.parse(request[0].data);
expect(data.site).to.not.equal(null);
expect(data.imp).to.have.lengthOf(1);
expect(data.imp[0].bidfloor, data).to.not.be.null;
expect(data.imp[0].video).to.not.equal(null);
});

it('should set user eids array', function () {
const request = spec.buildRequests(validBidRequests, bidderRequest);

Expand Down Expand Up @@ -443,4 +470,13 @@ describe('Tappx bid adapter', function () {
expect(_checkParamDataType('Wrong array', false, 'array')).to.be.undefined;
});
})

describe('_extractPageUrl tests', function() {
let validBidRequests = c_VALIDBIDREQUESTS;
let bidderRequest = c_BIDDERREQUEST_B;
it('should return the Domain of the site', function () {
validBidRequests[0].params.domainUrl = 'testUrl.com';
assert.isString(_extractPageUrl(validBidRequests, bidderRequest));
});
})
});