Skip to content

Commit

Permalink
tappx Bid Adapter: add internal Tappx params and refactor pageUrl (#7181
Browse files Browse the repository at this point in the history
)

* tappxBidAdapter :: update adapter version

* tappxBidAdapter :: update and add tappx internal params

* tappxBidAdapter :: add mktag to overview

* tappxBidAdapter :: update way getting pageUrl

* tapppxBidAdapter :: update pageUrl

* tappxBidAdapter :: remove unused params

* tappxBidAdapter :: add bcid and bcrid to requests

Co-authored-by: marc_tappx <[email protected]>
  • Loading branch information
prebidtappx and marc_tappx authored Jul 21, 2021
1 parent 1381f34 commit df23aec
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
60 changes: 45 additions & 15 deletions modules/tappxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { config } from '../src/config.js';
const BIDDER_CODE = 'tappx';
const TTL = 360;
const CUR = 'USD';
const TAPPX_BIDDER_VERSION = '0.1.10623';
const TAPPX_BIDDER_VERSION = '0.1.10714';
const TYPE_CNN = 'prebidjs';
const LOG_PREFIX = '[TAPPX]: ';
const VIDEO_SUPPORT = ['instream'];
Expand Down Expand Up @@ -225,11 +225,11 @@ function buildOneRequest(validBidRequests, bidderRequest) {
hostDomain = hostInfo.domain;

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

// let requests = [];
let payload = {};
Expand All @@ -249,12 +249,12 @@ function buildOneRequest(validBidRequests, bidderRequest) {
payload.app = app;
api[0] = utils.deepAccess(validBidRequests, 'params.api') ? utils.deepAccess(validBidRequests, 'params.api') : [3, 5];
} else {
let bundle = _extractPageUrl(validBidRequests, bidderRequest);
let site = {};
site.name = (bidderRequest && refererInfo) ? utils.parseUrl(refererInfo.referer).hostname : window.location.hostname;
site.bundle = (bidderRequest && refererInfo) ? utils.parseUrl(refererInfo.referer).hostname : window.location.hostname;
site.domain = (bidderRequest && refererInfo) ? utils.parseUrl(refererInfo.referer).hostname : window.location.hostname;
publisher.name = (bidderRequest && refererInfo) ? utils.parseUrl(refererInfo.referer).hostname : window.location.hostname;
publisher.domain = (bidderRequest && refererInfo) ? utils.parseUrl(refererInfo.referer).hostname : window.location.hostname;
site.name = bundle;
site.domain = bundle;
publisher.name = bundle;
publisher.domain = bundle;
tagid = `${site.name}_typeAdBanVid_${getOs()}`;
payload.site = site;
}
Expand Down Expand Up @@ -339,7 +339,6 @@ function buildOneRequest(validBidRequests, bidderRequest) {
}

let bidder = {};
bidder.tappxkey = TAPPXKEY;
bidder.endpoint = ENDPOINT;
bidder.host = hostInfo.url;
bidder.bidfloor = BIDFLOOR;
Expand Down Expand Up @@ -368,12 +367,6 @@ function buildOneRequest(validBidRequests, bidderRequest) {
geo.country = utils.deepAccess(validBidRequests, 'params.geo.country');
// < Device object

// > Params
let params = {};
params.host = 'tappx.com';
params.bidfloor = BIDFLOOR;
// < Params

// > GDPR
let user = {};
user.ext = {};
Expand Down Expand Up @@ -410,6 +403,15 @@ function buildOneRequest(validBidRequests, bidderRequest) {
}
// < GDPR

// > Payload Ext
let payloadExt = {};
payloadExt.bidder = {};
payloadExt.bidder.tappxkey = TAPPXKEY;
payloadExt.bidder.mktag = MKTAG;
payloadExt.bidder.bcid = utils.deepAccess(validBidRequests, 'params.bcid');
payloadExt.bidder.bcrid = utils.deepAccess(validBidRequests, 'params.bcrid');
// < Payload Ext

// > Payload
payload.id = validBidRequests.auctionId;
payload.test = utils.deepAccess(validBidRequests, 'params.test') ? 1 : 0;
Expand All @@ -418,9 +420,9 @@ function buildOneRequest(validBidRequests, bidderRequest) {
payload.bidder = BIDDER_CODE;
payload.imp = [imp];
payload.user = user;
payload.ext = payloadExt;

payload.device = device;
payload.params = params;
payload.regs = regs;
// < Payload

Expand Down Expand Up @@ -491,4 +493,32 @@ export function _checkParamDataType(key, value, datatype) {
return undefined;
}

export function _extractPageUrl(validBidRequests, bidderRequest) {
let domainUrl = utils.deepAccess(validBidRequests, 'params.domainUrl');

if (typeof domainUrl == 'undefined' || domainUrl == null) {
domainUrl = config.getConfig('pageUrl') || utils.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;
}
}

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;
}

registerBidder(spec);
42 changes: 26 additions & 16 deletions modules/tappxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ Ads sizes available: [300,250], [320,50], [320,480], [480,320], [728,90], [768,1
tappxkey: "pub-1234-android-1234",
endpoint: "ZZ1234PBJS",
bidfloor: 0.005,
test: true // Optional for testing purposes
mktag: "123456", // Optional: tappx mktag
test: true, // Optional: for testing purposes
domainUrl: "www.example.com", // Optional: add domain site
ext: { // Optional: extra params
foo: "bar"
}
}
}
]
Expand Down Expand Up @@ -62,21 +67,26 @@ Ads sizes available: [300,250], [320,50], [320,480], [480,320], [728,90], [768,1
tappxkey: "pub-1234-desktop-1234",
endpoint: "VZ12TESTCTV",
bidfloor: 0.005,
test: true,
video: { // optional
skippable: true, // optional
minduration: 5, // optional
maxduration: 30, // optional
startdelay: 5, // optional
playbackmethod: [1,3], // optional
api: [ 1, 2 ], // optional
protocols: [ 2, 3 ], // optional
battr: [ 13, 14 ], // optional
linearity: 1, // optional
placement: 2, // optional
minbitrate: 10, // optional
maxbitrate: 10 // optional
}
mktag: "123456", // Optional: tappx mktag
test: true, // Optional: for testing purposes
domainUrl: "www.example.com", // Optional: add domain site
video: { // Optional
skippable: true, // Optional
minduration: 5, // Optional
maxduration: 30, // Optional
startdelay: 5, // Optional
playbackmethod: [1,3], // Optional
api: [ 1, 2 ], // Optional
protocols: [ 2, 3 ], // Optional
battr: [ 13, 14 ], // Optional
linearity: 1, // Optional
placement: 2, // Optional
minbitrate: 10, // Optional
maxbitrate: 10 // Optional
},
ext: { // Optional: extra params
foo: "bar"
}
}
}]
}
Expand Down

0 comments on commit df23aec

Please sign in to comment.