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

[pull] master from prebid:master #24

Merged
merged 8 commits into from
Apr 10, 2024
79 changes: 41 additions & 38 deletions modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const ADAGIO_GVLID = 617;
const VERSION = '3.0.0';
const PREBID_VERSION = '$prebid.version$';
const ENDPOINT = 'https://c.4dex.io/pba.gif';
const CURRENCY_USD = 'USD';
const ADAGIO_CODE = 'adagio';
const cache = {
auctions: {},
getAuction: function(auctionId, adUnitCode) {
Expand Down Expand Up @@ -92,17 +94,11 @@ function removeDuplicates(arr, getKey) {
});
};

function getAdapterNameForAlias(aliasName) {
return adapterManager.aliasRegistry[aliasName] || aliasName;
};

function isAdagio(value) {
if (!value) {
function isAdagio(alias) {
if (!alias) {
return false
}

return value.toLowerCase().includes('adagio') ||
getAdapterNameForAlias(value).toLowerCase().includes('adagio');
return (alias + adapterManager.aliasRegistry[alias]).toLowerCase().includes(ADAGIO_CODE);
};

function getMediaTypeAlias(mediaType) {
Expand All @@ -129,6 +125,26 @@ function addKeyPrefix(obj, prefix) {
}, {});
}

function getUsdCpm(cpm, currency) {
let netCpm = cpm

if (typeof currency === 'string' && currency.toUpperCase() !== CURRENCY_USD) {
if (typeof getGlobal().convertCurrency === 'function') {
netCpm = parseFloat(Number(getGlobal().convertCurrency(cpm, currency, CURRENCY_USD))).toFixed(3);
} else {
netCpm = null
}
}
return netCpm
}

function getCurrencyData(bid) {
return {
netCpm: getUsdCpm(bid.cpm, bid.currency),
orginalCpm: getUsdCpm(bid.originalCpm, bid.originalCurrency)
}
}

/**
* sendRequest to Adagio. It filter null values and encode each query param.
* @param {Object} qp
Expand Down Expand Up @@ -258,7 +274,7 @@ function handlerAuctionInit(event) {
t_v: params.testVersion || null,
mts: mediaTypesKeys.join(','),
ban_szs: bannerSizes.join(','),
bdrs: bidders.map(bidder => getAdapterNameForAlias(bidder.bidder)).sort().join(','),
bdrs: bidders.map(bidder => bidder.bidder).sort().join(','),
adg_mts: adagioMediaTypes.join(',')
};

Expand Down Expand Up @@ -299,56 +315,43 @@ function handlerAuctionEnd(event) {

const adUnitCodes = cache.getAllAdUnitCodes(auctionId);
adUnitCodes.forEach(adUnitCode => {
const mapper = (bidder) => event.bidsReceived.find(bid => bid.adUnitCode === adUnitCode && bid.bidder === bidder) ? '1' : '0';
const bidResponseMapper = (bidder) => {
const bid = event.bidsReceived.find(bid => bid.adUnitCode === adUnitCode && bid.bidder === bidder)
return bid ? '1' : '0'
}
const bidCpmMapper = (bidder) => {
const bid = event.bidsReceived.find(bid => bid.adUnitCode === adUnitCode && bid.bidder === bidder)
return bid ? getCurrencyData(bid).netCpm : null
}

cache.updateAuction(auctionId, adUnitCode, {
bdrs_bid: cache.getBiddersFromAuction(auctionId, adUnitCode).map(mapper).join(',')
bdrs_bid: cache.getBiddersFromAuction(auctionId, adUnitCode).map(bidResponseMapper).join(','),
bdrs_cpm: cache.getBiddersFromAuction(auctionId, adUnitCode).map(bidCpmMapper).join(',')
});
sendNewBeacon(auctionId, adUnitCode);
});
}

function handlerBidWon(event) {
let auctionId = getTargetedAuctionId(event);

if (!guard.bidTracked(auctionId, event.adUnitCode)) {
return;
}

let adsCurRateToUSD = (event.currency === 'USD') ? 1 : null;
let ogCurRateToUSD = (event.originalCurrency === 'USD') ? 1 : null;
try {
if (typeof getGlobal().convertCurrency === 'function') {
// Currency module is loaded, we can calculate the conversion rate.

// Get the conversion rate from the original currency to USD.
ogCurRateToUSD = getGlobal().convertCurrency(1, event.originalCurrency, 'USD');
// Get the conversion rate from the ad server currency to USD.
adsCurRateToUSD = getGlobal().convertCurrency(1, event.currency, 'USD');
}
} catch (error) {
logError('Error on Adagio Analytics Adapter - handlerBidWon', error);
}
const currencyData = getCurrencyData(event)

const adagioAuctionCacheId = (
(event.latestTargetedAuctionId && event.latestTargetedAuctionId !== event.auctionId)
? cache.getAdagioAuctionId(event.auctionId)
: null);

cache.updateAuction(auctionId, event.adUnitCode, {
win_bdr: getAdapterNameForAlias(event.bidder),
win_bdr: event.bidder,
win_mt: getMediaTypeAlias(event.mediaType),
win_ban_sz: event.mediaType === BANNER ? `${event.width}x${event.height}` : null,

// ad server currency
win_cpm: event.cpm,
cur: event.currency,
cur_rate: adsCurRateToUSD,

// original currency from bidder
og_cpm: event.originalCpm,
og_cur: event.originalCurrency,
og_cur_rate: ogCurRateToUSD,
win_net_cpm: currencyData.netCpm,
win_og_cpm: currencyData.orginalCpm,

// cache bid id
auct_id_c: adagioAuctionCacheId,
Expand Down Expand Up @@ -428,7 +431,7 @@ adagioAdapter.enableAnalytics = config => {

adapterManager.registerAnalyticsAdapter({
adapter: adagioAdapter,
code: 'adagio',
code: ADAGIO_CODE,
gvlid: ADAGIO_GVLID,
});

Expand Down
113 changes: 14 additions & 99 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
_each,
cleanObj,
contains,
createTrackPixelHtml,
deepAccess,
Expand All @@ -20,7 +19,6 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {find} from '../src/polyfill.js';
import {config} from '../src/config.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js';

/**
Expand All @@ -39,7 +37,7 @@ const VIDEO_FPD = ['battr', 'pos'];
const NATIVE_FPD = ['battr', 'api'];
const BANNER_PARAMS = ['pos'];
const BANNER_FPD = ['btype', 'battr', 'pos', 'api'];
const VERSION = '1.6';
const VERSION = '1.7';
const SYNC_IFRAME = 1;
const SYNC_IMAGE = 2;
const SYNC_TYPES = {
Expand All @@ -48,29 +46,6 @@ const SYNC_TYPES = {
};
const GVLID = 14;

const NATIVE_MODEL = [
{name: 'title', assetType: 'title'},
{name: 'icon', assetType: 'img', type: 1},
{name: 'image', assetType: 'img', type: 3},
{name: 'body', assetType: 'data', type: 2},
{name: 'body2', assetType: 'data', type: 10},
{name: 'sponsoredBy', assetType: 'data', type: 1},
{name: 'phone', assetType: 'data', type: 8},
{name: 'address', assetType: 'data', type: 9},
{name: 'price', assetType: 'data', type: 6},
{name: 'salePrice', assetType: 'data', type: 7},
{name: 'cta', assetType: 'data', type: 12},
{name: 'rating', assetType: 'data', type: 3},
{name: 'downloads', assetType: 'data', type: 5},
{name: 'likes', assetType: 'data', type: 4},
{name: 'displayUrl', assetType: 'data', type: 11}
];

const NATIVE_INDEX = NATIVE_MODEL.reduce((acc, val, idx) => {
acc[val.name] = {id: idx, ...val};
return acc;
}, {});

const MULTI_FORMAT_SUFFIX = '__mf';
const MULTI_FORMAT_SUFFIX_BANNER = 'b' + MULTI_FORMAT_SUFFIX;
const MULTI_FORMAT_SUFFIX_VIDEO = 'v' + MULTI_FORMAT_SUFFIX;
Expand Down Expand Up @@ -139,9 +114,6 @@ export const spec = {
* @returns {ServerRequest[]}
*/
buildRequests: function (bidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
bidRequests = convertOrtbRequestToProprietaryNative(bidRequests);

let impGroups = groupImpressionsByHostZone(bidRequests, bidderRequest.refererInfo);
let requests = [];
let schain = bidRequests[0].schain;
Expand Down Expand Up @@ -199,7 +171,9 @@ export const spec = {
prBid.height = imp.video.h;
} else if ('native' in imp) {
prBid.mediaType = NATIVE;
prBid.native = buildNativeAd(JSON.parse(rtbBid.adm));
prBid.native = {
ortb: buildNativeAd(rtbBid.adm)
};
}
if (isStr(rtbBid.dealid)) {
prBid.dealId = rtbBid.dealid;
Expand Down Expand Up @@ -345,11 +319,9 @@ function buildImps(bidRequest, secure) {
} else {
typedImp = imp;
}
let nativeRequest = buildNativeRequest(mediaTypes.native);
typedImp.native = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, NATIVE_FPD),
ver: '1.1',
request: JSON.stringify(nativeRequest)
request: JSON.stringify(bidRequest.nativeOrtbRequest)
};
initImpBidfloor(typedImp, bidRequest, sizes, isMultiformat ? '*' : NATIVE);
result.push(typedImp);
Expand All @@ -371,51 +343,6 @@ function getDefinedParamsOrEmpty(object, params) {
return getDefinedParams(object, params);
}

/**
* Builds native request from native adunit
*/
function buildNativeRequest(nativeReq) {
let request = {ver: '1.1', assets: []};
for (let k of Object.keys(nativeReq)) {
let v = nativeReq[k];
let desc = NATIVE_INDEX[k];
if (desc === undefined) {
continue;
}
let assetRoot = {
id: desc.id,
required: ~~v.required,
};
if (desc.assetType === 'img') {
assetRoot[desc.assetType] = buildImageAsset(desc, v);
} else if (desc.assetType === 'data') {
assetRoot.data = cleanObj({type: desc.type, len: v.len});
} else if (desc.assetType === 'title') {
assetRoot.title = {len: v.len || 90};
} else {
return;
}
request.assets.push(assetRoot);
}
return request;
}

/**
* Builds image asset request
*/
function buildImageAsset(desc, val) {
let img = {
type: desc.type
};
if (val.sizes) {
[img.w, img.h] = val.sizes;
} else if (val.aspect_ratios) {
img.wmin = val.aspect_ratios[0].min_width;
img.hmin = val.aspect_ratios[0].min_height;
}
return cleanObj(img);
}

/**
* Checks if configuration allows specified sync method
* @param syncRule {Object}
Expand Down Expand Up @@ -540,12 +467,11 @@ function makeRegulations(bidderRequest) {
* @returns
*/
function makeBaseRequest(bidderRequest, imps, fpd) {
let {timeout} = bidderRequest;
let request = {
'id': bidderRequest.bidderRequestId,
'imp': imps,
'at': 1,
'tmax': parseInt(timeout)
'tmax': parseInt(bidderRequest.timeout)
};
if (!isEmpty(fpd.bcat)) {
request.bcat = fpd.bcat;
Expand Down Expand Up @@ -665,26 +591,15 @@ function validateNativeImageSize(img) {
}

/**
* Creates native ad for native 1.1 response
* Creates native ad for native 1.2 response
*/
function buildNativeAd(nativeResp) {
const {assets, link, imptrackers, jstracker, privacy} = nativeResp.native;
let nativeAd = {
clickUrl: link.url,
impressionTrackers: imptrackers,
javascriptTrackers: jstracker ? [jstracker] : undefined,
privacyLink: privacy,
};
_each(assets, asset => {
let assetName = NATIVE_MODEL[asset.id].name;
let assetType = NATIVE_MODEL[asset.id].assetType;
nativeAd[assetName] = asset[assetType].text || asset[assetType].value || cleanObj({
url: asset[assetType].url,
width: asset[assetType].w,
height: asset[assetType].h
});
});
return cleanObj(nativeAd);
function buildNativeAd(adm) {
let resp = JSON.parse(adm);
// temporary workaround for top-level native object wrapper
if ('native' in resp) {
resp = resp.native;
}
return resp;
}

function stripMultiformatSuffix(impid) {
Expand Down
5 changes: 4 additions & 1 deletion modules/agmaAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { config } from '../src/config.js';
const GVLID = 1122;
const ModuleCode = 'agma';
const analyticsType = 'endpoint';
const scriptVersion = '1.7.1';
const scriptVersion = '1.8.0';
const batchDelayInMs = 1000;
const agmaURL = 'https://pbc.agma-analytics.de/v1';
const pageViewId = generateUUID();
Expand Down Expand Up @@ -127,6 +127,7 @@ export const getPayload = (auctionIds, options) => {
};

if (useExtendedPayload) {
const device = config.getConfig('device') || {};
const { x, y } = getScreen();
const userIdsAsEids = getUserIDs();
payload = {
Expand All @@ -141,6 +142,8 @@ export const getPayload = (auctionIds, options) => {
pageUrl: ri.page,
screenWidth: x,
screenHeight: y,
deviceWidth: device.w || screen.width,
deviceHeight: device.h || screen.height,
userIdsAsEids,
};
}
Expand Down
1 change: 1 addition & 0 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const spec = {
aliases: [
{ code: 'appnexusAst', gvlid: 32 },
{ code: 'emxdigital', gvlid: 183 },
{ code: 'emetriq', gvlid: 213 },
{ code: 'pagescience', gvlid: 32 },
{ code: 'gourmetads', gvlid: 32 },
{ code: 'matomy', gvlid: 32 },
Expand Down
5 changes: 4 additions & 1 deletion modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ function buildRequests(validBidRequests, bidderRequest) {
data.gppString = bidderRequest.ortb2.regs.gpp
data.gppSid = Array.isArray(bidderRequest.ortb2.regs.gpp_sid) ? bidderRequest.ortb2.regs.gpp_sid.join(',') : ''
}
const dsa = deepAccess(bidderRequest, 'ortb2.regs.ext.dsa');
if (dsa) {
data.dsa = dsa
}
if (coppa) {
data.coppa = coppa;
}
Expand Down Expand Up @@ -549,7 +553,6 @@ function interpretResponse(serverResponse, bidRequest) {
mediaType: type || mediaType
};
let sizes = parseSizesInput(bidRequest.sizes);

if (maxw && maxh) {
sizes = [`${maxw}x${maxh}`];
} else if (product === 5 && includes(sizes, '1x1')) {
Expand Down
Loading
Loading