Skip to content

Commit

Permalink
Merge branch 'master' into goldbach-adapter-update
Browse files Browse the repository at this point in the history
  • Loading branch information
bevenio committed Dec 10, 2024
2 parents 600e69b + 39e6418 commit a66165f
Show file tree
Hide file tree
Showing 94 changed files with 1,850 additions and 903 deletions.
2 changes: 1 addition & 1 deletion libraries/appnexusUtils/anKeywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function getANMapFromOrtbSegments(ortb2) {
let ortbSegsArrObj = deepAccess(ortb2, path) || [];
ortbSegsArrObj.forEach(segObj => {
// only read segment data from known sources
const segtax = ORTB_SEGTAX_KEY_MAP[deepAccess(segObj, 'ext.segtax')];
const segtax = ORTB_SEGTAX_KEY_MAP[segObj?.ext?.segtax];
if (segtax) {
segObj.segment.forEach(seg => {
// if source was in multiple locations of ortb or had multiple segments in same area, stack them together into an array
Expand Down
4 changes: 1 addition & 3 deletions libraries/fpdUtils/pageInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as utils from '../../src/utils.js';

/**
* get page title
* @returns {string}
Expand Down Expand Up @@ -67,7 +65,7 @@ export function getReferrer(bidRequest = {}, bidderRequest = {}) {
if (bidRequest.params && bidRequest.params.referrer) {
pageUrl = bidRequest.params.referrer;
} else {
pageUrl = utils.deepAccess(bidderRequest, 'refererInfo.page');
pageUrl = bidderRequest?.refererInfo?.page;
}
return pageUrl;
}
3 changes: 3 additions & 0 deletions libraries/ortb2Utils/currency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getCurrencyFromBidderRequest(bidderRequest) {
return bidderRequest?.ortb2?.ext?.prebid?.adServerCurrency;
}
3 changes: 1 addition & 2 deletions libraries/ortbConverter/processors/banner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
createTrackPixelHtml,
deepAccess,
inIframe,
mergeDeep,
sizesToSizeTuples,
Expand All @@ -15,7 +14,7 @@ import {BANNER} from '../../../src/mediaTypes.js';
export function fillBannerImp(imp, bidRequest, context) {
if (context.mediaType && context.mediaType !== BANNER) return;

const bannerParams = deepAccess(bidRequest, 'mediaTypes.banner');
const bannerParams = bidRequest?.mediaTypes?.banner;
if (bannerParams) {
const banner = {
topframe: inIframe() === true ? 0 : 1
Expand Down
6 changes: 3 additions & 3 deletions libraries/ortbConverter/processors/video.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {deepAccess, isEmpty, logWarn, mergeDeep, sizesToSizeTuples, sizeTupleToRtbSize} from '../../../src/utils.js';
import {isEmpty, logWarn, mergeDeep, sizesToSizeTuples, sizeTupleToRtbSize} from '../../../src/utils.js';
import {VIDEO} from '../../../src/mediaTypes.js';

import {ORTB_VIDEO_PARAMS} from '../../../src/video.js';

export function fillVideoImp(imp, bidRequest, context) {
if (context.mediaType && context.mediaType !== VIDEO) return;

const videoParams = deepAccess(bidRequest, 'mediaTypes.video');
const videoParams = bidRequest?.mediaTypes?.video;
if (!isEmpty(videoParams)) {
const video = Object.fromEntries(
// Parameters that share the same name & semantics between pbjs adUnits and imp.video
Expand All @@ -27,7 +27,7 @@ export function fillVideoImp(imp, bidRequest, context) {

export function fillVideoResponse(bidResponse, seatbid, context) {
if (bidResponse.mediaType === VIDEO) {
if (deepAccess(context.imp, 'video.w') && deepAccess(context.imp, 'video.h')) {
if (context?.imp?.video?.w && context?.imp?.video?.h) {
[bidResponse.playerWidth, bidResponse.playerHeight] = [context.imp.video.w, context.imp.video.h];
}

Expand Down
3 changes: 2 additions & 1 deletion modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {deepAccess, deepClone, deepSetValue, mergeDeep, parseSizesInput, setOnAny} from '../src/utils.js';
import {config} from '../src/config.js';
import {Renderer} from '../src/Renderer.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';

const { getConfig } = config;

Expand Down Expand Up @@ -60,7 +61,7 @@ export const spec = {
const pt = setOnAny(validBidRequests, 'params.pt') || setOnAny(validBidRequests, 'params.priceType') || 'net';
const tid = bidderRequest.ortb2?.source?.tid;
const test = setOnAny(validBidRequests, 'params.test');
const currency = getConfig('currency.adServerCurrency');
const currency = getCurrencyFromBidderRequest(bidderRequest);
const cur = currency && [ currency ];
const eids = setOnAny(validBidRequests, 'userIdAsEids');
const schain = setOnAny(validBidRequests, 'schain');
Expand Down
27 changes: 14 additions & 13 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {deepAccess, getBidIdParameter} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js';
import {escapeUnsafeChars} from '../libraries/htmlEscape/htmlEscape.js';
import { escapeUnsafeChars } from '../libraries/htmlEscape/htmlEscape.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { tryAppendQueryString } from '../libraries/urlUtils/urlUtils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { deepAccess, getBidIdParameter } from '../src/utils.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -61,7 +61,7 @@ export const spec = {
data = tryAppendQueryString(data, 't', 'json3');
data = tryAppendQueryString(data, 'transactionid', validReq.ortb2Imp?.ext?.tid);
data = tryAppendQueryString(data, 'sizes', getSizes(validReq));
data = tryAppendQueryString(data, 'currency', getCurrencyType());
data = tryAppendQueryString(data, 'currency', getCurrencyType(bidderRequest));
data = tryAppendQueryString(data, 'pbver', '$prebid.version$');
data = tryAppendQueryString(data, 'sdkname', 'prebidjs');
data = tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION);
Expand Down Expand Up @@ -94,7 +94,8 @@ export const spec = {
method: 'GET',
url: url,
data: data,
bidRequest: validBidRequests[i]
bidRequest: validBidRequests[i],
bidderRequest
});
}
return serverRequests;
Expand All @@ -119,7 +120,7 @@ export const spec = {
height: body.h ? body.h : 1,
creativeId: body.creativeid || '',
dealId: body.dealid || '',
currency: getCurrencyType(),
currency: getCurrencyFromBidderRequest(bidRequests.bidderRequest),
netRevenue: true,
ttl: body.ttl || 10,
};
Expand Down Expand Up @@ -304,9 +305,9 @@ function getSizes(validReq) {
/**
* @return {?string} USD or JPY
*/
function getCurrencyType() {
if (config.getConfig('currency.adServerCurrency') && config.getConfig('currency.adServerCurrency').toUpperCase() === 'USD') return 'USD';
return 'JPY';
function getCurrencyType(bidderRequest) {
const adServerCurrency = getCurrencyFromBidderRequest(bidderRequest) || ''
return adServerCurrency.toUpperCase() === 'USD' ? 'USD' : 'JPY'
}

/**
Expand Down
14 changes: 6 additions & 8 deletions modules/admaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {getValue, formatQS, logError, deepAccess, isArray, getBidIdParameter} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { deepAccess, formatQS, getBidIdParameter, getValue, isArray, logError } from '../src/utils.js';
import {getUserSyncParams} from '../libraries/userSyncUtils/userSyncUtils.js';
import { interpretNativeAd } from '../libraries/precisoUtils/bidNativeUtils.js';

Expand Down Expand Up @@ -56,6 +56,7 @@ export const spec = {
const ortb = bidderRequest.ortb2;
const networkId = getValue(validBidRequests[0].params, 'networkId');
let host = getValue(validBidRequests[0].params, 'host');
const currency = getCurrencyFromBidderRequest(bidderRequest) || 'TRY';
const bidderName = validBidRequests[0].bidder;

const payload = {
Expand Down Expand Up @@ -84,10 +85,7 @@ export const spec = {
tmax: parseInt(tmax)
};

if (config.getConfig('currency.adServerCurrency')) {
payload.ext.cur = config.getConfig('currency.adServerCurrency');
}

payload.ext.cur = currency;
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
const consentStr = (bidderRequest.gdprConsent.consentString)
? bidderRequest.gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : '';
Expand Down
17 changes: 9 additions & 8 deletions modules/adotBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Renderer} from '../src/Renderer.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {isArray, isBoolean, isFn, isPlainObject, isStr, logError, replaceAuctionPrice} from '../src/utils.js';
import {find} from '../src/polyfill.js';
import {config} from '../src/config.js';
import {OUTSTREAM} from '../src/video.js';
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { find } from '../src/polyfill.js';
import { isArray, isBoolean, isFn, isPlainObject, isStr, logError, replaceAuctionPrice } from '../src/utils.js';
import { OUTSTREAM } from '../src/video.js';
import { NATIVE_ASSETS_IDS as NATIVE_ID_MAPPING, NATIVE_ASSETS as NATIVE_PLACEMENTS } from '../libraries/braveUtils/nativeAssets.js';

/**
Expand Down Expand Up @@ -310,7 +311,7 @@ function buildImpFromAdUnit(adUnit, bidderRequest) {
if (!mediaType) return null;

const media = IMP_BUILDER[mediaType](mediaTypes[mediaType], bidderRequest, adUnit)
const currency = config.getConfig('currency.adServerCurrency') || DEFAULT_CURRENCY;
const currency = getCurrencyFromBidderRequest(bidderRequest) || DEFAULT_CURRENCY;
const bidfloor = getMainFloor(adUnit, media.format, mediaType, currency);

return {
Expand Down
9 changes: 5 additions & 4 deletions modules/audiencerunBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import {
_each,
deepAccess,
Expand All @@ -8,9 +12,6 @@ import {
logError,
triggerPixel,
} from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -136,7 +137,7 @@ export const spec = {
referer: deepAccess(bidderRequest, 'refererInfo.topmostLocation'),
// TODO: please do not send internal data structures over the network
refererInfo: deepAccess(bidderRequest, 'refererInfo.legacy'),
currencyCode: config.getConfig('currency.adServerCurrency'),
currencyCode: getCurrencyFromBidderRequest(bidderRequest),
timeout: config.getConfig('bidderTimeout'),
bids,
};
Expand Down
33 changes: 25 additions & 8 deletions modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { getCurrencyFromBidderRequest } from '../libraries/ortb2Utils/currency.js';
import { getAllOrtbKeywords } from '../libraries/keywords/keywords.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getRefererInfo } from '../src/refererDetection.js';
import {
buildUrl,
deepAccess, getBidIdParameter,
deepAccess, generateUUID, getBidIdParameter,
getValue,
isArray,
isPlainObject,
logInfo,
logWarn,
triggerPixel
} from '../src/utils.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js';
import { getStorageManager } from '../src/storageManager.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
Expand All @@ -21,9 +22,11 @@ import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js';

const BIDDER_CODE = 'beop';
const ENDPOINT_URL = 'https://hb.beop.io/bid';
const COOKIE_NAME = 'beopid';
const TCF_VENDOR_ID = 666;

const validIdRegExp = /^[0-9a-fA-F]{24}$/
const storage = getStorageManager({bidderCode: BIDDER_CODE});

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -53,7 +56,7 @@ export const spec = {
* @return ServerRequest Info describing the request to the BeOp's server
*/
buildRequests: function(validBidRequests, bidderRequest) {
const slots = validBidRequests.map(beOpRequestSlotsMaker);
const slots = validBidRequests.map((bid) => beOpRequestSlotsMaker(bid, bidderRequest));
const firstPartyData = bidderRequest.ortb2 || {};
const psegs = firstPartyData.user?.ext?.permutive || firstPartyData.user?.ext?.data?.permutive || [];
const userBpSegs = firstPartyData.user?.ext?.bpsegs || firstPartyData.user?.ext?.data?.bpsegs || [];
Expand All @@ -64,6 +67,19 @@ export const spec = {
const kwdsFromRequest = firstSlot.kwds;
let keywords = getAllOrtbKeywords(bidderRequest.ortb2, kwdsFromRequest);

let beopid = '';
if (storage.cookiesAreEnabled) {
beopid = storage.getCookie(COOKIE_NAME, undefined);
if (!beopid) {
beopid = generateUUID();
let expirationDate = new Date();
expirationDate.setTime(expirationDate.getTime() + 86400 * 183 * 1000);
storage.setCookie(COOKIE_NAME, beopid, expirationDate.toUTCString());
}
} else {
storage.setCookie(COOKIE_NAME, '', 0);
}

const payloadObject = {
at: new Date().toString(),
nid: firstSlot.nid,
Expand All @@ -74,6 +90,7 @@ export const spec = {
lang: (window.navigator.language || window.navigator.languages[0]),
kwds: keywords,
dbg: false,
fg: beopid,
slts: slots,
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
gdpr_applies: gdpr ? gdpr.gdprApplies : false,
Expand Down Expand Up @@ -142,9 +159,9 @@ function buildTrackingParams(data, info, value) {
};
}

function beOpRequestSlotsMaker(bid) {
function beOpRequestSlotsMaker(bid, bidderRequest) {
const bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes');
const publisherCurrency = config.getConfig('currency.adServerCurrency') || getValue(bid.params, 'currency') || 'EUR';
const publisherCurrency = getCurrencyFromBidderRequest(bidderRequest) || getValue(bid.params, 'currency') || 'EUR';
let floor;
if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]});
Expand Down
38 changes: 36 additions & 2 deletions modules/bidmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { replaceAuctionPrice, isNumber, deepAccess, isFn } from '../src/utils.js';

export const END_POINT = 'https://adapter.bidmatic.io/ortb-client';
const HOST = 'https://adapter.bidmatic.io';
const BIDDER_CODE = 'bidmatic';
const DEFAULT_CURRENCY = 'USD';
export const SYNC_URL = `${HOST}/sync.html`;
export const END_POINT = `${HOST}/ortb-client`;

export const converter = ortbConverter({
context: {
Expand Down Expand Up @@ -59,14 +61,43 @@ export const converter = ortbConverter({
}
});

const PROCESSED_SOURCES = {};

export function createUserSyncs(processedSources, syncOptions, gdprConsent, uspConsent, gppConsent) {
if (syncOptions?.iframeEnabled) {
return Object.entries(processedSources)
.filter(([_, syncMade]) => syncMade === 0)
.map(([sourceId]) => {
processedSources[sourceId] = 1

let url = `${SYNC_URL}?aid=${sourceId}`
if (gdprConsent && gdprConsent.gdprApplies) {
url += `&gdpr=${+(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`
}
if (uspConsent) {
url += `&usp=${uspConsent}`;
}
if (gppConsent) {
url += `&gpp=${gppConsent.gppString}&gpp_sid=${gppConsent.applicableSections?.toString()}`
}
return {
type: 'iframe',
url
};
})
}
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
gvlid: 1134,
isBidRequestValid: function (bid) {
return isNumber(deepAccess(bid, 'params.source'))
},

getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent, gppConsent) {
return createUserSyncs(PROCESSED_SOURCES, syncOptions, gdprConsent, uspConsent, gppConsent);
},
buildRequests: function (validBidRequests, bidderRequest) {
const requestsBySource = validBidRequests.reduce((acc, bidRequest) => {
acc[bidRequest.params.source] = acc[bidRequest.params.source] || [];
Expand All @@ -75,6 +106,9 @@ export const spec = {
}, {});

return Object.entries(requestsBySource).map(([source, bidRequests]) => {
if (!PROCESSED_SOURCES[source]) {
PROCESSED_SOURCES[source] = 0;
}
const data = converter.toORTB({ bidRequests, bidderRequest });
const url = new URL(END_POINT);
url.searchParams.append('source', source);
Expand Down
6 changes: 6 additions & 0 deletions modules/bidmaticBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ var adUnits = [{
}]
}]
```


# Testing
```gulp test-only --file=./test/spec/modules/bidmaticBidAdapter_spec.js```
```gulp test-coverage --file=./test/spec/modules/bidmaticBidAdapter_spec.js```
```gulp view-coverage```
Loading

0 comments on commit a66165f

Please sign in to comment.