Skip to content

Commit

Permalink
Merge pull request #14 from prebid/master
Browse files Browse the repository at this point in the history
Sync with master
  • Loading branch information
pm-nitin-shirsat authored Jul 1, 2024
2 parents 8761239 + d236eb1 commit b8e21bd
Show file tree
Hide file tree
Showing 37 changed files with 743 additions and 1,899 deletions.
12 changes: 12 additions & 0 deletions libraries/processResponse/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { logError } from '../../src/utils.js';

export function getBidFromResponse(respItem, LOG_ERROR_MESS) {
if (!respItem) {
logError(LOG_ERROR_MESS.emptySeatbid);
} else if (!respItem.bid) {
logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem));
} else if (!respItem.bid[0]) {
logError(LOG_ERROR_MESS.noBid);
}
return respItem && respItem.bid && respItem.bid[0];
}
19 changes: 9 additions & 10 deletions libraries/vidazooUtils/bidderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export function appendUserIdsToRequestPayload(payloadRef, userIds) {
let key;
_each(userIds, (userId, idSystemProviderName) => {
key = `uid.${idSystemProviderName}`;

switch (idSystemProviderName) {
case 'lipb':
payloadRef[key] = userId.lipbid;
Expand All @@ -217,7 +218,7 @@ export function getVidazooSessionId(storage) {
return getStorageItem(storage, SESSION_ID_KEY) || '';
}

export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, webSessionId, storage, bidderVersion, bidderCode, getUniqueRequestData) {
export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, storage, bidderVersion, bidderCode, getUniqueRequestData) {
const {
params,
bidId,
Expand All @@ -234,7 +235,7 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
const {ext} = params;
let {bidFloor} = params;
const hashUrl = hashCode(topWindowUrl);
const uniqueRequestData = isFn(getUniqueRequestData) ? getUniqueRequestData(hashUrl) : {};
const uniqueRequestData = isFn(getUniqueRequestData) ? getUniqueRequestData(hashUrl, bid) : {};
const uniqueDealId = getUniqueDealId(storage, hashUrl);
const pId = extractPID(params);
const isStorageAllowed = bidderSettings.get(bidderCode, 'storageAllowed');
Expand Down Expand Up @@ -285,7 +286,6 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
bidderRequestsCount: bidderRequestsCount,
bidderWinsCount: bidderWinsCount,
bidderTimeout: bidderTimeout,
webSessionId: webSessionId,
...uniqueRequestData
};

Expand Down Expand Up @@ -331,13 +331,13 @@ export function buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidder
return data;
}

export function createInterpretResponseFn(bidderCode) {
export function createInterpretResponseFn(bidderCode, allowSingleRequest) {
return function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body) {
return [];
}

const singleRequestMode = config.getConfig(`${bidderCode}.singleRequest`);
const singleRequestMode = allowSingleRequest && config.getConfig(`${bidderCode}.singleRequest`);
const reqBidId = deepAccess(request, 'data.bidId');
const {results} = serverResponse.body;

Expand Down Expand Up @@ -410,12 +410,12 @@ export function createInterpretResponseFn(bidderCode) {
}
}

export function createBuildRequestsFn(createRequestDomain, createUniqueRequestData, webSessionId, storage, bidderCode, bidderVersion) {
export function createBuildRequestsFn(createRequestDomain, createUniqueRequestData, storage, bidderCode, bidderVersion, allowSingleRequest) {
function buildRequest(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout) {
const {params} = bid;
const cId = extractCID(params);
const subDomain = extractSubDomain(params);
const data = buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, webSessionId, storage, bidderVersion, bidderCode, createUniqueRequestData);
const data = buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, storage, bidderVersion, bidderCode, createUniqueRequestData);
const dto = {
method: 'POST', url: `${createRequestDomain(subDomain)}/prebid/multi/${cId}`, data: data
};
Expand All @@ -428,7 +428,7 @@ export function createBuildRequestsFn(createRequestDomain, createUniqueRequestDa
const subDomain = extractSubDomain(params);
const data = bidRequests.map(bid => {
const sizes = parseSizesInput(bid.sizes);
return buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, webSessionId, storage, bidderVersion, bidderCode, createUniqueRequestData)
return buildRequestData(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout, storage, bidderVersion, bidderCode, createUniqueRequestData)
});
const chunkSize = Math.min(20, config.getConfig(`${bidderCode}.chunkSize`) || 10);

Expand All @@ -445,11 +445,10 @@ export function createBuildRequestsFn(createRequestDomain, createUniqueRequestDa
}

return function buildRequests(validBidRequests, bidderRequest) {
// TODO: does the fallback make sense here?
const topWindowUrl = bidderRequest.refererInfo.page || bidderRequest.refererInfo.topmostLocation;
const bidderTimeout = config.getConfig('bidderTimeout');

const singleRequestMode = config.getConfig('vidazoo.singleRequest');
const singleRequestMode = allowSingleRequest && config.getConfig(`${bidderCode}.singleRequest`);

const requests = [];

Expand Down
16 changes: 9 additions & 7 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,18 @@ function onGetBidRequestData(bidReqConfig, callback, config) {

const adUnits = bidReqConfig.adUnits || getGlobal().adUnits || [];
adUnits.forEach(adUnit => {
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
const ortb2Imp = deepAccess(adUnit, 'ortb2Imp');

// A divId is required to compute the slot position and later to track viewability.
// If nothing has been explicitly set, we try to get the divId from the GPT slot and fallback to the adUnit code in last resort.
if (!deepAccess(ortb2Imp, 'ext.data.divId')) {
const divId = getGptSlotInfoForAdUnitCode(adUnit.code).divId;
let divId = deepAccess(ortb2Imp, 'ext.data.divId')
if (!divId) {
divId = getGptSlotInfoForAdUnitCode(adUnit.code).divId;
deepSetValue(ortb2Imp, `ext.data.divId`, divId || adUnit.code);
}

const slotPosition = getSlotPosition(adUnit);
const slotPosition = getSlotPosition(divId);
deepSetValue(ortb2Imp, `ext.data.adg_rtd.adunit_position`, slotPosition);

// It is expected that the publisher set a `adUnits[].ortb2Imp.ext.data.placement` value.
Expand Down Expand Up @@ -430,7 +433,7 @@ function getElementFromTopWindow(element, currentWindow) {
}
};

function getSlotPosition(adUnit) {
function getSlotPosition(divId) {
if (!isSafeFrameWindow() && !canAccessWindowTop()) {
return '';
}
Expand All @@ -451,16 +454,15 @@ function getSlotPosition(adUnit) {
// window.top based computing
const wt = getWindowTop();
const d = wt.document;
const adUnitElementId = deepAccess(adUnit, 'ortb2Imp.ext.data.divId');

let domElement;

if (inIframe() === true) {
const ws = getWindowSelf();
const currentElement = ws.document.getElementById(adUnitElementId);
const currentElement = ws.document.getElementById(divId);
domElement = getElementFromTopWindow(currentElement, ws);
} else {
domElement = wt.document.getElementById(adUnitElementId);
domElement = wt.document.getElementById(divId);
}

if (!domElement) {
Expand Down
11 changes: 3 additions & 8 deletions modules/carodaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
deepSetValue,
logError,
mergeDeep,
parseSizesInput
sizeTupleToRtbSize,
sizesToSizeTuples
} from '../src/utils.js';
import { config } from '../src/config.js';

Expand Down Expand Up @@ -195,13 +196,7 @@ function getImps (validBidRequests, common) {
};
const bannerParams = deepAccess(bid, 'mediaTypes.banner');
if (bannerParams && bannerParams.sizes) {
const sizes = parseSizesInput(bannerParams.sizes);
const format = sizes.map(size => {
const [width, height] = size.split('x');
const w = parseInt(width, 10);
const h = parseInt(height, 10);
return { w, h };
});
const format = sizesToSizeTuples(bannerParams.sizes).map(sizeTupleToRtbSize);
imp.banner = {
format
};
Expand Down
88 changes: 52 additions & 36 deletions modules/cpmstarBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import {getBidIdParameter} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO, BANNER } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';

const BIDDER_CODE = 'cpmstar';

Expand All @@ -12,15 +12,18 @@ const ENDPOINT_PRODUCTION = 'https://server.cpmstar.com/view.aspx';

const DEFAULT_TTL = 300;
const DEFAULT_CURRENCY = 'USD';
const DEFAULT_NET_REVENUE = true;

function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
export const converter = ortbConverter({
context: {
ttl: DEFAULT_TTL,
netRevenue: DEFAULT_NET_REVENUE
}
});

export const spec = {
code: BIDDER_CODE,
gvlid: 1317,
supportedMediaTypes: [BANNER, VIDEO],
pageID: Math.floor(Math.random() * 10e6),

Expand All @@ -43,22 +46,30 @@ export const spec = {

buildRequests: function (validBidRequests, bidderRequest) {
var requests = [];
// This reference to window.top can cause issues when loaded in an iframe if not protected with a try/catch.

for (var i = 0; i < validBidRequests.length; i++) {
var bidRequest = validBidRequests[i];
var referer = bidderRequest.refererInfo.page ? bidderRequest.refererInfo.page : bidderRequest.refererInfo.domain;
referer = encodeURIComponent(referer);
var e = getBidIdParameter('endpoint', bidRequest.params);
var ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION;
var mediaType = spec.getMediaType(bidRequest);
var playerSize = spec.getPlayerSize(bidRequest);
var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : '');
var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') +
'&json=c_b&mv=1&poolid=' + getBidIdParameter('placementId', bidRequest.params) +
'&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) +
'&requestid=' + bidRequest.bidId +
'&referer=' + encodeURIComponent(referer);
const referer = bidderRequest.refererInfo.page ? bidderRequest.refererInfo.page : bidderRequest.refererInfo.domain;
const e = utils.getBidIdParameter('endpoint', bidRequest.params);
const ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION;
const url = new URL(ENDPOINT);
const body = {};
const mediaType = spec.getMediaType(bidRequest);
const playerSize = spec.getPlayerSize(bidRequest);
url.searchParams.set('media', mediaType);
if (mediaType == VIDEO) {
url.searchParams.set('fv', 0);
if (playerSize) {
url.searchParams.set('w', playerSize?.[0]);
url.searchParams.set('h', playerSize?.[1]);
}
}
url.searchParams.set('json', 'c_b');
url.searchParams.set('mv', 1);
url.searchParams.set('poolid', utils.getBidIdParameter('placementId', bidRequest.params));
url.searchParams.set('reachedTop', bidderRequest.refererInfo.reachedTop);
url.searchParams.set('requestid', bidRequest.bidId);
url.searchParams.set('referer', referer);

if (bidRequest.schain && bidRequest.schain.nodes) {
var schain = bidRequest.schain;
Expand All @@ -67,45 +78,49 @@ export const spec = {
for (var i2 = 0; i2 < schain.nodes.length; i2++) {
var node = schain.nodes[i2];
schainString += '!' +
fixedEncodeURIComponent(node.asi || '') + ',' +
fixedEncodeURIComponent(node.sid || '') + ',' +
fixedEncodeURIComponent(node.hp || '') + ',' +
fixedEncodeURIComponent(node.rid || '') + ',' +
fixedEncodeURIComponent(node.name || '') + ',' +
fixedEncodeURIComponent(node.domain || '');
(node.asi || '') + ',' +
(node.sid || '') + ',' +
(node.hp || '') + ',' +
(node.rid || '') + ',' +
(node.name || '') + ',' +
(node.domain || '');
}
url += '&schain=' + schainString;
url.searchParams.set('schain', schainString);
}

if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString != null) {
url += '&gdpr_consent=' + bidderRequest.gdprConsent.consentString;
url.searchParams.set('gdpr_consent', bidderRequest.gdprConsent.consentString);
}
if (bidderRequest.gdprConsent.gdprApplies != null) {
url += '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? 1 : 0);
url.searchParams.set('gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
}
}

if (bidderRequest.uspConsent != null) {
url += '&us_privacy=' + bidderRequest.uspConsent;
url.searchParams.set('us_privacy', bidderRequest.uspConsent);
}

if (config.getConfig('coppa')) {
url += '&tfcd=' + (config.getConfig('coppa') ? 1 : 0);
url.searchParams.set('tfcd', (config.getConfig('coppa') ? 1 : 0));
}

let body = {};
let adUnitCode = bidRequest.adUnitCode;
if (adUnitCode) {
body.adUnitCode = adUnitCode;
}
if (mediaType == VIDEO) {
body.video = utils.deepAccess(bidRequest, 'mediaTypes.video');
} else if (mediaType == BANNER) {
body.banner = utils.deepAccess(bidRequest, 'mediaTypes.banner');
}

const ortb = converter.toORTB({ bidderRequest, bidRequests: [bidRequest] });
Object.assign(body, ortb);

requests.push({
method: 'POST',
url: url,
url: url.toString(),
bidRequest: bidRequest,
data: body
});
Expand Down Expand Up @@ -144,7 +159,7 @@ export const spec = {
width: rawBid.width || 0,
height: rawBid.height || 0,
currency: rawBid.currency ? rawBid.currency : DEFAULT_CURRENCY,
netRevenue: rawBid.netRevenue ? rawBid.netRevenue : true,
netRevenue: rawBid.netRevenue ? rawBid.netRevenue : DEFAULT_NET_REVENUE,
ttl: rawBid.ttl ? rawBid.ttl : DEFAULT_TTL,
creativeId: rawBid.creativeid || 0,
meta: {
Expand Down Expand Up @@ -191,4 +206,5 @@ export const spec = {
}

};

registerBidder(spec);
5 changes: 1 addition & 4 deletions modules/cpmstarBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
```
Module Name: Cpmstar Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
gdpr_supported: true
usp_supported: true
coppa_supported: true
Maintainer: [email protected]
```

# Description
Expand Down
2 changes: 1 addition & 1 deletion modules/dailymotionBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const spec = {
const pixelSyncs = [];

serverResponses.forEach((response) => {
(response.user_syncs || []).forEach((syncUrl) => {
(response?.body?.userSyncs || []).forEach((syncUrl) => {
if (syncUrl.type === 'image') {
pixelSyncs.push({ url: syncUrl.url, type: 'image' });
}
Expand Down
14 changes: 2 additions & 12 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Renderer } from '../src/Renderer.js';
import { VIDEO, BANNER } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { getStorageManager } from '../src/storageManager.js';
import { getBidFromResponse } from '../libraries/processResponse/index.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -441,7 +442,7 @@ export const spec = {

if (!errorMessage && serverResponse.seatbid) {
serverResponse.seatbid.forEach(respItem => {
_addBidResponse(_getBidFromResponse(respItem), bidRequest, bidResponses, RendererConst, bidderCode);
_addBidResponse(getBidFromResponse(respItem, LOG_ERROR_MESS), bidRequest, bidResponses, RendererConst, bidderCode);
});
}
if (errorMessage) logError(errorMessage);
Expand Down Expand Up @@ -512,17 +513,6 @@ function _getFloor (mediaTypes, bid) {
return floor;
}

function _getBidFromResponse(respItem) {
if (!respItem) {
logError(LOG_ERROR_MESS.emptySeatbid);
} else if (!respItem.bid) {
logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem));
} else if (!respItem.bid[0]) {
logError(LOG_ERROR_MESS.noBid);
}
return respItem && respItem.bid && respItem.bid[0];
}

function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst, bidderCode) {
if (!serverBid) return;
let errorMessage;
Expand Down
Loading

0 comments on commit b8e21bd

Please sign in to comment.