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 #20

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 6 additions & 49 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export const ADAPTER_VERSION = 36;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const PROFILE_ID_INLINE = 207;
const FLEDGE_SELLER_DOMAIN = 'https://grid-mercury.criteo.com';
const FLEDGE_SELLER_TIMEOUT = 500;
const FLEDGE_DECISION_LOGIC_URL = 'https://grid-mercury.criteo.com/fledge/decision';
export const PROFILE_ID_PUBLISHERTAG = 185;
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
const LOG_PREFIX = 'Criteo: ';
Expand Down Expand Up @@ -284,53 +281,13 @@ export const spec = {
});
}

if (isArray(body.ext?.igbid)) {
const seller = body.ext.seller || FLEDGE_SELLER_DOMAIN;
const sellerTimeout = body.ext.sellerTimeout || FLEDGE_SELLER_TIMEOUT;
body.ext.igbid.forEach((igbid) => {
const perBuyerSignals = {};
igbid.igbuyer.forEach(buyerItem => {
perBuyerSignals[buyerItem.origin] = buyerItem.buyerdata;
});
const bidRequest = request.bidRequests.find(b => b.bidId === igbid.impid);
const bidId = bidRequest.bidId;
let sellerSignals = body.ext.sellerSignals || {};
if (!sellerSignals.floor && bidRequest.params.bidFloor) {
sellerSignals.floor = bidRequest.params.bidFloor;
}
let perBuyerTimeout = { '*': 500 };
if (sellerSignals.perBuyerTimeout) {
for (const buyer in sellerSignals.perBuyerTimeout) {
perBuyerTimeout[buyer] = sellerSignals.perBuyerTimeout[buyer];
}
}
let perBuyerGroupLimits = { '*': 60 };
if (sellerSignals.perBuyerGroupLimits) {
for (const buyer in sellerSignals.perBuyerGroupLimits) {
perBuyerGroupLimits[buyer] = sellerSignals.perBuyerGroupLimits[buyer];
}
}
if (body?.ext?.sellerSignalsPerImp !== undefined) {
const sellerSignalsPerImp = body.ext.sellerSignalsPerImp[bidId];
if (sellerSignalsPerImp !== undefined) {
sellerSignals = {...sellerSignals, ...sellerSignalsPerImp};
}
if (isArray(body.ext?.igi)) {
body.ext.igi.forEach((igi) => {
if (isArray(igi?.igs)) {
igi.igs.forEach((igs) => {
fledgeAuctionConfigs.push(igs);
});
}
fledgeAuctionConfigs.push({
bidId,
config: {
seller,
sellerSignals,
sellerTimeout,
perBuyerSignals,
perBuyerTimeout,
perBuyerGroupLimits,
auctionSignals: {},
decisionLogicUrl: FLEDGE_DECISION_LOGIC_URL,
interestGroupBuyers: Object.keys(perBuyerSignals),
sellerCurrency: sellerSignals.currency || '???',
},
});
});
}

Expand Down
8 changes: 5 additions & 3 deletions modules/luceadBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import {getUniqueIdentifierStr, logInfo, deepSetValue} from '../src/utils.js';
import {fetch} from '../src/ajax.js';

const bidderCode = 'lucead';
const bidderName = 'Lucead';
let baseUrl = 'https://lucead.com';
let staticUrl = 'https://s.lucead.com';
let companionUrl = 'https://cdn.jsdelivr.net/gh/lucead/prebid-js-external-js-lucead@master/dist/prod.min.js';
let endpointUrl = 'https://prebid.lucead.com/go';
const defaultCurrency = 'EUR';
const defaultTtl = 500;
const aliases = ['adliveplus'];

function isDevEnv() {
return location.hostname.endsWith('.ngrok-free.app') || location.href.startsWith('https://ayads.io/test');
return location.hash.includes('prebid-dev') || location.href.startsWith('https://ayads.io/test');
}

function isBidRequestValid(bidRequest) {
return !!bidRequest?.params?.placementId;
}

export function log(msg, obj) {
logInfo('Lucead - ' + msg, obj);
logInfo(`${bidderName} - ${msg}`, obj);
}

function buildRequests(bidRequests, bidderRequest) {
Expand Down Expand Up @@ -149,7 +151,7 @@ function onTimeout(timeoutData) {
export const spec = {
code: bidderCode,
// gvlid: BIDDER_GVLID,
aliases: [],
aliases,
isBidRequestValid,
buildRequests,
interpretResponse,
Expand Down
4 changes: 2 additions & 2 deletions modules/luceadBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const adUnits = [
sizes: [[300, 250]],
bids: [
{
bidder: "lucead",
bidder: 'lucead',
params: {
placementId: '1',
placementId: '2',
}
}
]
Expand Down
271 changes: 271 additions & 0 deletions modules/setupadBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
import {
_each,
createTrackPixelHtml,
deepAccess,
isStr,
getBidIdParameter,
triggerPixel,
logWarn,
} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';

const BIDDER_CODE = 'setupad';
const ENDPOINT = 'https://prebid.setupad.io/openrtb2/auction';
const SYNC_ENDPOINT = 'https://cookie.stpd.cloud/sync?';
const REPORT_ENDPOINT = 'https://adapter-analytics.setupad.io/api/adapter-analytics';
const GVLID = 1241;
const TIME_TO_LIVE = 360;
const biddersCreativeIds = {};

function getEids(bidRequest) {
if (deepAccess(bidRequest, 'userIdAsEids')) return bidRequest.userIdAsEids;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
gvlid: GVLID,

isBidRequestValid: function (bid) {
return !!(bid.params.placement_id && isStr(bid.params.placement_id));
},

buildRequests: function (validBidRequests, bidderRequest) {
const requests = [];

_each(validBidRequests, function (bid) {
const id = getBidIdParameter('placement_id', bid.params);
const accountId = getBidIdParameter('account_id', bid.params);
const auctionId = bid.auctionId;
const bidId = bid.bidId;
const eids = getEids(bid) || undefined;
let sizes = bid.sizes;
if (sizes && !Array.isArray(sizes[0])) sizes = [sizes];

const site = {
page: bidderRequest?.refererInfo?.page,
ref: bidderRequest?.refererInfo?.ref,
domain: bidderRequest?.refererInfo?.domain,
};
const device = {
w: bidderRequest?.ortb2?.device?.w,
h: bidderRequest?.ortb2?.device?.h,
};

const payload = {
id: bid?.bidderRequestId,
ext: {
prebid: {
storedrequest: {
id: accountId || 'default',
},
},
},
user: { ext: { eids } },
device,
site,
imp: [],
};

const imp = {
id: bid.adUnitCode,
ext: {
prebid: {
storedrequest: { id },
},
},
};

if (deepAccess(bid, 'mediaTypes.banner')) {
imp.banner = {
format: (sizes || []).map((s) => {
return { w: s[0], h: s[1] };
}),
};
}

payload.imp.push(imp);

const gdprConsent = bidderRequest && bidderRequest.gdprConsent;
const uspConsent = bidderRequest && bidderRequest.uspConsent;

if (gdprConsent || uspConsent) {
payload.regs = { ext: {} };

if (uspConsent) payload.regs.ext.us_privacy = uspConsent;

if (gdprConsent) {
if (typeof gdprConsent.gdprApplies !== 'undefined') {
payload.regs.ext.gdpr = gdprConsent.gdprApplies ? 1 : 0;
}

if (typeof gdprConsent.consentString !== 'undefined') {
payload.user.ext.consent = gdprConsent.consentString;
}
}
}
const params = bid.params;

requests.push({
method: 'POST',
url: ENDPOINT,
data: JSON.stringify(payload),
options: {
contentType: 'text/plain',
withCredentials: true,
},

bidId,
params,
auctionId,
});
});

return requests;
},

interpretResponse: function (serverResponse, bidRequest) {
if (
!serverResponse ||
!serverResponse.body ||
typeof serverResponse.body != 'object' ||
Object.keys(serverResponse.body).length === 0
) {
logWarn('no response or body is malformed');
return [];
}

const serverBody = serverResponse.body;
const bidResponses = [];

_each(serverBody.seatbid, (res) => {
_each(res.bid, (bid) => {
const requestId = bidRequest.bidId;
const params = bidRequest.params;
const { ad, adUrl } = getAd(bid);

const bidResponse = {
requestId,
params,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.id,
currency: serverBody.cur,
netRevenue: true,
ttl: TIME_TO_LIVE,
meta: {
advertiserDomains: bid.adomain || [],
},
};

// set a seat for creativeId for triggerPixel url
biddersCreativeIds[bidResponse.creativeId] = res.seat;

bidResponse.ad = ad;
bidResponse.adUrl = adUrl;
bidResponses.push(bidResponse);
});
});

return bidResponses;
},

getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) {
if (!responses?.length) return [];

const syncs = [];
const bidders = getBidders(responses);

if (syncOptions.iframeEnabled && bidders) {
const queryParams = [];

queryParams.push(`bidders=${bidders}`);
queryParams.push('gdpr=' + +gdprConsent.gdprApplies);
queryParams.push('gdpr_consent=' + gdprConsent.consentString);
queryParams.push('usp_consent=' + (uspConsent || ''));

const strQueryParams = queryParams.join('&');

syncs.push({
type: 'iframe',
url: SYNC_ENDPOINT + strQueryParams + '&type=iframe',
});

return syncs;
}

return [];
},

onBidWon: function (bid) {
let bidder = bid.bidder || bid.bidderCode;
const auctionId = bid.auctionId;
if (bidder !== BIDDER_CODE) return;

let params;
if (bid.params) {
params = Array.isArray(bid.params) ? bid.params : [bid.params];
} else {
if (Array.isArray(bid.bids)) {
params = bid.bids.map((singleBid) => singleBid.params);
}
}

if (!params?.length) return;

const placementIdsArray = [];
params.forEach((param) => {
if (!param.placement_id) return;
placementIdsArray.push(param.placement_id);
});

const placementIds = (placementIdsArray.length && placementIdsArray.join(';')) || '';

if (!placementIds) return;

let extraBidParams = '';

// find the winning bidder by using creativeId as identification
if (biddersCreativeIds.hasOwnProperty(bid.creativeId) && biddersCreativeIds[bid.creativeId]) {
bidder = biddersCreativeIds[bid.creativeId];
}

// Add extra parameters
extraBidParams = `&cpm=${bid.originalCpm}&currency=${bid.originalCurrency}`;

const url = `${REPORT_ENDPOINT}?event=bidWon&bidder=${bidder}&placementIds=${placementIds}&auctionId=${auctionId}${extraBidParams}&timestamp=${Date.now()}`;
triggerPixel(url);
},
};

function getBidders(serverResponse) {
const bidders = serverResponse
.map((res) => Object.keys(res.body.ext.responsetimemillis || []))
.flat(1);

if (bidders.length) {
return encodeURIComponent(JSON.stringify([...new Set(bidders)]));
}
}

function getAd(bid) {
let ad, adUrl;

switch (deepAccess(bid, 'ext.prebid.type')) {
default:
if (bid.adm && bid.nurl) {
ad = bid.adm;
ad += createTrackPixelHtml(decodeURIComponent(bid.nurl));
} else if (bid.adm) {
ad = bid.adm;
} else if (bid.nurl) {
adUrl = bid.nurl;
}
}

return { ad, adUrl };
}

registerBidder(spec);
Loading