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

new TapHype bidder adapter #3319

Merged
merged 13 commits into from
Dec 3, 2018
12 changes: 8 additions & 4 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function _createBidResponse(response) {
}
}

function _isViewabilityMeasurable() {
return !_isIframe();
function _isViewabilityMeasurable(element) {
return !_isIframe() && element !== null;
}

function _getViewability(element, topWin, { w, h } = {}) {
Expand All @@ -46,12 +46,16 @@ function _createServerRequest(bidRequest, gdprConsent) {
const sizes = _transformSizes(bidRequest.sizes);
const minSize = _getMinSize(sizes);

const viewabilityAmount = _isViewabilityMeasurable()
const viewabilityAmount = _isViewabilityMeasurable(element)
? _getViewability(element, utils.getWindowTop(), minSize)
: NON_MEASURABLE;

const contributeViewability = ViewabilityContributor(viewabilityAmount);

if (element === null) {
utils.logWarn(`Unable to locate element with id: '${bidRequest.adUnitCode}'`);
}

/*
* Infer data for the request payload
*/
Expand Down Expand Up @@ -90,7 +94,7 @@ function _createServerRequest(bidRequest, gdprConsent) {
'version': '$prebid.version$'
}]
}
}
};

// Finally, set the openRTB 'test' param if this is to be a test bid
if (params.test === 1) {
Expand Down
19 changes: 19 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,28 @@ function _handleDigitrustId(eids) {
}
}

function _handleTTDId(eids) {
let adsrvrOrgId = config.getConfig('adsrvrOrgId');
if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) {
eids.push({
'source': 'adserver.org',
'uids': [
{
'id': adsrvrOrgId.TDID,
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}
]
});
}
}

function _handleEids(payload) {
let eids = [];
_handleDigitrustId(eids);
_handleTTDId(eids);
if (eids.length > 0) {
payload.user.eids = eids;
}
Expand Down
1 change: 1 addition & 0 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var sizeMap = {
61: '1000x1000',
64: '580x500',
65: '640x480',
66: '930x600',
67: '320x480',
68: '1800x1000',
72: '320x320',
Expand Down
12 changes: 4 additions & 8 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { getTopWindowLocation, parseSizesInput, logError, generateUUID, deepAccess, isEmpty } from '../src/utils';
import { getTopWindowLocation, parseSizesInput, logError, generateUUID, isEmpty } from '../src/utils';
import { BANNER, VIDEO } from '../src/mediaTypes';
import find from 'core-js/library/fn/array/find';
import { config } from '../src/config';

const BIDDER_CODE = 'sonobi';
Expand Down Expand Up @@ -104,12 +103,10 @@ export const spec = {
}

Object.keys(bidResponse.slots).forEach(slot => {
const bid = bidResponse.slots[slot];
const bidId = _getBidIdFromTrinityKey(slot);
const bidRequest = find(bidderRequests, bidReqest => bidReqest.bidId === bidId);
const videoMediaType = deepAccess(bidRequest, 'mediaTypes.video');
const mediaType = bidRequest.mediaType || (videoMediaType ? 'video' : null);
const mediaType = (bid.sbi_ct === 'video') ? 'video' : null;
const createCreative = _creative(mediaType);
const bid = bidResponse.slots[slot];
if (bid.sbi_aid && bid.sbi_mouse && bid.sbi_size) {
const [
width = 1,
Expand All @@ -132,8 +129,7 @@ export const spec = {
bids.dealId = bid.sbi_dozer;
}

const creativeType = bid.sbi_ct;
if (creativeType && (creativeType === 'video' || creativeType === 'outstream')) {
if (mediaType === 'video') {
bids.mediaType = 'video';
bids.vastUrl = createCreative(bidResponse.sbi_dc, bid.sbi_aid);
delete bids.ad;
Expand Down
45 changes: 45 additions & 0 deletions modules/taphypeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {registerBidder} from 'src/adapters/bidderFactory';

export const spec = {
code: 'taphype',
isBidRequestValid: function (bid) {
return !!bid.params.placementId;
},
buildRequests: function (bidRequests) {
const requests = bidRequests.map(function (bid) {
const params = {
placementId: bid.params.placementId,
url: encodeURIComponent(window.location.href),
size: bid.sizes[0][0] + 'x' + bid.sizes[0][1],
rnd: Math.random(),
bidId: bid.bidId,
};

return {method: 'GET', url: 'https://us-central1-taphype-internal.cloudfunctions.net/th-prebid', data: params, options: {withCredentials: false}}
});

return requests;
},
interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse || !serverResponse.body || !serverResponse.body.ad) {
return [];
}

const bid = serverResponse.body;
const sizes = bid.size.split(',');

return [{
requestId: bidRequest.data.bidId,
cpm: bid.price,
width: sizes[0],
height: sizes[1],
creativeId: bidRequest.data.bidId,
currency: bid.currency || 'USD',
netRevenue: true,
ad: bid.ad,
ttl: 360
}];
},
};

registerBidder(spec);
32 changes: 32 additions & 0 deletions modules/taphypeBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Overview

Module Name: TapHype Bidder Adapter
Module Type: Bidder Adapter
Maintainer: admin@taphype.com

# Description

You can use this adapter to get a bid from taphype.com.


# Test Parameters
```javascript
var adUnits = [
{
code: 'div-taphype-example',
sizes: [[300, 250]],
bids: [
{
bidder: "taphype",
params: {
placementId: 12345
}
}
]
}
];
```

Where:

* placementId - TapHype Placement ID
52 changes: 27 additions & 25 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ exports.transformAdServerTargetingObj = function (targeting) {
* Read an adUnit object and return the sizes used in an [[728, 90]] format (even if they had [728, 90] defined)
* Preference is given to the `adUnit.mediaTypes.banner.sizes` object over the `adUnit.sizes`
* @param {object} adUnit one adUnit object from the normal list of adUnits
* @returns {array[array[number]]} array of arrays containing numeric sizes
* @returns {Array.<number[]>} array of arrays containing numeric sizes
*/
export function getAdUnitSizes(adUnit) {
if (!adUnit) {
Expand All @@ -151,8 +151,8 @@ export function getAdUnitSizes(adUnit) {

/**
* Parse a GPT-Style general size Array like `[[300, 250]]` or `"300x250,970x90"` into an array of sizes `["300x250"]` or '['300x250', '970x90']'
* @param {array[array|number]} sizeObj Input array or double array [300,250] or [[300,250], [728,90]]
* @return {array[string]} Array of strings like `["300x250"]` or `["300x250", "728x90"]`
* @param {(Array.<number[]>|Array.<number>)} sizeObj Input array or double array [300,250] or [[300,250], [728,90]]
* @return {Array.<string>} Array of strings like `["300x250"]` or `["300x250", "728x90"]`
*/
export function parseSizesInput(sizeObj) {
var parsedSizes = [];
Expand Down Expand Up @@ -190,7 +190,7 @@ export function parseSizesInput(sizeObj) {
}

return parsedSizes;
};
}

// parse a GPT style sigle size array, (i.e [300,250])
// into an AppNexus style string, (i.e. 300x250)
Expand All @@ -199,7 +199,7 @@ export function parseGPTSingleSizeArray(singleSize) {
if (exports.isArray(singleSize) && singleSize.length === 2 && (!isNaN(singleSize[0]) && !isNaN(singleSize[1]))) {
return singleSize[0] + 'x' + singleSize[1];
}
};
}

/**
* @deprecated This function will be removed soon. Use http://prebid.org/dev-docs/bidder-adaptor.html#referrers
Expand All @@ -215,7 +215,7 @@ exports.getTopWindowLocation = function() {
if (loc) return parse(loc, {'decodeSearchAsString': true});
}
return exports.getWindowLocation();
}
};

/**
* @deprecated This function will be removed soon. Use http://prebid.org/dev-docs/bidder-adaptor.html#referrers
Expand Down Expand Up @@ -375,9 +375,9 @@ exports.getParameterByName = getParameterByName;

/**
* This function validates paramaters.
* @param {object[string]} paramObj [description]
* @param {Object} paramObj [description]
* @param {string[]} requiredParamsArr [description]
* @return {bool} Bool if paramaters are valid
* @return {boolean} Bool if paramaters are valid
*/
exports.hasValidBidRequest = function (paramObj, requiredParamsArr, adapter) {
var found = false;
Expand Down Expand Up @@ -439,11 +439,11 @@ exports.isNumber = function(object) {

exports.isPlainObject = function(object) {
return exports.isA(object, tObject);
}
};

exports.isBoolean = function(object) {
return exports.isA(object, tBoolean);
}
};

/**
* Return if the object is "empty";
Expand Down Expand Up @@ -552,16 +552,18 @@ var hasOwn = function (objectToCheck, propertyToCheckFor) {
exports.insertElement = function(elm, doc, target) {
doc = doc || document;
let elToAppend;
const head = doc.getElementsByTagName('head');
if (target) {
elToAppend = doc.getElementsByTagName(target);
} else {
elToAppend = doc.getElementsByTagName('head');
elToAppend = head;
}
try {
elToAppend = elToAppend.length ? elToAppend : doc.getElementsByTagName('body');
if (elToAppend.length) {
elToAppend = elToAppend[0];
elToAppend.insertBefore(elm, elToAppend.firstChild);
const refChild = head && head[0] === elToAppend ? null : elToAppend.firstChild;
return elToAppend.insertBefore(elm, refChild);
}
} catch (e) {}
};
Expand Down Expand Up @@ -669,8 +671,8 @@ exports.createTrackPixelIframeHtml = function (url, encodeUri = true, sandbox =

/**
* Returns iframe document in a browser agnostic way
* @param {object} iframe reference
* @return {object} iframe `document` reference
* @param {Object} iframe reference
* @return {Object} iframe `document` reference
*/
exports.getIframeDocument = function (iframe) {
if (!iframe) {
Expand Down Expand Up @@ -874,7 +876,7 @@ export function delayExecution(func, numRequiredCalls) {
* @export
* @param {array} xs
* @param {string} key
* @returns {${key_value}: ${groupByArray}, key_value: {groupByArray}}
* @returns {Object} {${key_value}: ${groupByArray}, key_value: {groupByArray}}
*/
export function groupBy(xs, key) {
return xs.reduce(function(rv, x) {
Expand All @@ -885,7 +887,7 @@ export function groupBy(xs, key) {

/**
* deepAccess utility function useful for doing safe access (will not throw exceptions) of deep object paths.
* @param {object} obj The object containing the values you would like to access.
* @param {Object} obj The object containing the values you would like to access.
* @param {string|number} path Object path to the value you would like to access. Non-strings are coerced to strings.
* @returns {*} The value found at the specified object path, or undefined if path is not found.
*/
Expand All @@ -905,7 +907,7 @@ export function deepAccess(obj, path) {

/**
* Returns content for a friendly iframe to execute a URL in script tag
* @param {url} URL to be executed in a script tag in a friendly iframe
* @param {string} url URL to be executed in a script tag in a friendly iframe
* <!--PRE_SCRIPT_TAG_MACRO--> and <!--POST_SCRIPT_TAG_MACRO--> are macros left to be replaced if required
*/
export function createContentToExecuteExtScriptInFriendlyFrame(url) {
Expand All @@ -919,9 +921,9 @@ export function createContentToExecuteExtScriptInFriendlyFrame(url) {
/**
* Build an object consisting of only defined parameters to avoid creating an
* object with defined keys and undefined values.
* @param {object} object The object to pick defined params out of
* @param {Object} object The object to pick defined params out of
* @param {string[]} params An array of strings representing properties to look for in the object
* @returns {object} An object containing all the specified values that are defined
* @returns {Object} An object containing all the specified values that are defined
*/
export function getDefinedParams(object, params) {
return params
Expand Down Expand Up @@ -966,8 +968,8 @@ export function getBidderRequest(bidRequests, bidder, adUnitCode) {
}
/**
* Returns user configured bidder params from adunit
* @param {object} adunits
* @param {string} adunit code
* @param {Object} adUnits
* @param {string} adUnitCode code
* @param {string} bidder code
* @return {Array} user configured param for the given bidder adunit configuration
*/
Expand Down Expand Up @@ -1002,7 +1004,7 @@ const compareCodeAndSlot = (slot, adUnitCode) => slot.getAdUnitPath() === adUnit

/**
* Returns filter function to match adUnitCode in slot
* @param {object} slot GoogleTag slot
* @param {Object} slot GoogleTag slot
* @return {function} filter function
*/
export function isAdUnitCodeMatchingSlot(slot) {
Expand Down Expand Up @@ -1041,9 +1043,9 @@ export function unsupportedBidderMessage(adUnit, bidder) {
* @return {Object} object
*/
export function deletePropertyFromObject(object, prop) {
let result = Object.assign({}, object)
let result = Object.assign({}, object);
delete result[prop];
return result
return result;
}

/**
Expand Down Expand Up @@ -1081,7 +1083,7 @@ export function convertCamelToUnderscore(value) {
* normally read from bidder params
* eg { foo: ['bar', 'baz'], fizz: ['buzz'] }
* becomes [{ key: 'foo', value: ['bar', 'baz']}, {key: 'fizz', value: ['buzz']}]
* @param {Object{Arrays}} keywords object of arrays representing keyvalue pairs
* @param {Object} keywords object of arrays representing keyvalue pairs
* @param {string} paramName name of parent object (eg 'keywords') containing keyword data, used in error handling
*/
export function transformBidderParamKeywords(keywords, paramName = 'keywords') {
Expand Down
Loading