Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
antosarho authored Mar 4, 2024
2 parents f7369af + 94bb619 commit 0124682
Show file tree
Hide file tree
Showing 14 changed files with 1,772 additions and 325 deletions.
32 changes: 28 additions & 4 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
deepSetValue,
isEmpty,
isEmptyStr,
isPlainObject,
logError,
logInfo,
logWarn,
Expand All @@ -21,8 +22,8 @@ import {getRefererInfo} from '../src/refererDetection.js';
import {getStorageManager} from '../src/storageManager.js';
import {uspDataHandler, gppDataHandler} from '../src/adapterManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
import { GreedyPromise } from '../src/utils/promise.js';
import { loadExternalScript } from '../src/adloader.js';
import {GreedyPromise} from '../src/utils/promise.js';
import {loadExternalScript} from '../src/adloader.js';

/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
Expand All @@ -39,6 +40,7 @@ export const ID5_PRIVACY_STORAGE_NAME = `${ID5_STORAGE_NAME}_privacy`;
const LOCAL_STORAGE = 'html5';
const LOG_PREFIX = 'User ID - ID5 submodule: ';
const ID5_API_CONFIG_URL = 'https://id5-sync.com/api/config/prebid';
const ID5_DOMAIN = 'id5-sync.com';

// order the legacy cookie names in reverse priority order so the last
// cookie in the array is the most preferred to use
Expand Down Expand Up @@ -146,9 +148,17 @@ export const id5IdSubmodule = {
id5id: {
uid: universalUid,
ext: ext
}
},
};

if (isPlainObject(ext.euid)) {
responseObj.euid = {
uid: ext.euid.uids[0].id,
source: ext.euid.source,
ext: {provider: ID5_DOMAIN}
}
}

const abTestingResult = deepAccess(value, 'ab_testing.result');
switch (abTestingResult) {
case 'control':
Expand Down Expand Up @@ -232,14 +242,28 @@ export const id5IdSubmodule = {
getValue: function(data) {
return data.uid
},
source: 'id5-sync.com',
source: ID5_DOMAIN,
atype: 1,
getUidExt: function(data) {
if (data.ext) {
return data.ext;
}
}
},
'euid': {
getValue: function (data) {
return data.uid;
},
getSource: function (data) {
return data.source;
},
atype: 3,
getUidExt: function (data) {
if (data.ext) {
return data.ext;
}
}
}
},
};

Expand Down
129 changes: 129 additions & 0 deletions modules/opscoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {deepAccess, deepSetValue, isArray, logInfo} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

const ENDPOINT = 'https://exchange.ops.co/openrtb2/auction';
const BIDDER_CODE = 'opsco';
const DEFAULT_BID_TTL = 300;
const DEFAULT_CURRENCY = 'USD';
const DEFAULT_NET_REVENUE = true;

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

isBidRequestValid: (bid) => !!(bid.params &&
bid.params.placementId &&
bid.params.publisherId &&
bid.mediaTypes?.banner?.sizes &&
Array.isArray(bid.mediaTypes?.banner?.sizes)),

buildRequests: (validBidRequests, bidderRequest) => {
const {publisherId, placementId, siteId} = validBidRequests[0].params;

const payload = {
id: bidderRequest.bidderRequestId,
imp: validBidRequests.map(bidRequest => ({
id: bidRequest.bidId,
banner: {format: extractSizes(bidRequest)},
ext: {
opsco: {
placementId: placementId,
publisherId: publisherId,
}
}
})),
site: {
id: siteId,
publisher: {id: publisherId},
domain: bidderRequest.refererInfo?.domain,
page: bidderRequest.refererInfo?.page,
ref: bidderRequest.refererInfo?.ref,
},
};

if (isTest(validBidRequests[0])) {
payload.test = 1;
}

if (bidderRequest.gdprConsent) {
deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
}
const eids = deepAccess(validBidRequests[0], 'userIdAsEids');
if (eids && eids.length !== 0) {
deepSetValue(payload, 'user.ext.eids', eids);
}

const schainData = deepAccess(validBidRequests[0], 'schain.nodes');
if (isArray(schainData) && schainData.length > 0) {
deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain);
}

if (bidderRequest.uspConsent) {
deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

return {
method: 'POST',
url: ENDPOINT,
data: JSON.stringify(payload),
};
},

interpretResponse: (serverResponse) => {
const response = (serverResponse || {}).body;
const bidResponses = response?.seatbid?.[0]?.bid?.map(bid => ({
requestId: bid.impid,
cpm: bid.price,
width: bid.w,
height: bid.h,
ad: bid.adm,
ttl: typeof bid.exp === 'number' ? bid.exp : DEFAULT_BID_TTL,
creativeId: bid.crid,
netRevenue: DEFAULT_NET_REVENUE,
currency: DEFAULT_CURRENCY,
meta: {advertiserDomains: bid?.adomain || []},
mediaType: bid.mediaType || bid.mtype
})) || [];

if (!bidResponses.length) {
logInfo('opsco.interpretResponse :: No valid responses');
}

return bidResponses;
},

getUserSyncs: (syncOptions, serverResponses) => {
logInfo('opsco.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses);
if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) {
return [];
}
let syncs = [];
serverResponses.forEach(resp => {
const userSync = deepAccess(resp, 'body.ext.usersync');
if (userSync) {
const syncDetails = Object.values(userSync).flatMap(value => value.syncs || []);
syncDetails.forEach(syncDetail => {
const type = syncDetail.type === 'iframe' ? 'iframe' : 'image';
if ((type === 'iframe' && syncOptions.iframeEnabled) || (type === 'image' && syncOptions.pixelEnabled)) {
syncs.push({type, url: syncDetail.url});
}
});
}
});

logInfo('opsco.getUserSyncs result=%o', syncs);
return syncs;
}
};

function extractSizes(bidRequest) {
return (bidRequest.mediaTypes?.banner?.sizes || []).map(([width, height]) => ({w: width, h: height}));
}

function isTest(validBidRequest) {
return validBidRequest.params?.test === true;
}

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

```
Module Name: Opsco Bid Adapter
Module Type: Bidder Adapter
Maintainer: prebid@ops.co
```

# Description

Module that connects to Opscos's demand sources.

# Test Parameters

## Banner

```
var adUnits = [
{
code: 'test-ad',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]]
}
},
bids: [{
bidder: 'opsco',
params: {
placementId: '1234',
publisherId: '9876',
test: true
}
}],
}
];
```
5 changes: 3 additions & 2 deletions modules/pubmaticAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function executeBidsLoggerCall(e, highestCpmBids) {
// getGptSlotInfoForAdUnitCode returns gptslot corresponding to adunit provided as input.
let slotObject = {
'sn': adUnitId,
'au': origAdUnit.adUnitId || getGptSlotInfoForAdUnitCode(adUnitId)?.gptSlot || adUnitId,
'au': origAdUnit.owAdUnitId || getGptSlotInfoForAdUnitCode(adUnitId)?.gptSlot || adUnitId,
'mt': getAdUnitAdFormats(origAdUnit),
'sz': getSizesForAdUnit(adUnit, adUnitId),
'ps': gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestCpmBids.filter(bid => bid.adUnitCode === adUnitId)),
Expand Down Expand Up @@ -450,6 +450,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
return;
}
let origAdUnit = getAdUnit(cache.auctions[auctionId].origAdUnits, adUnitId) || {};
let owAdUnitId = origAdUnit.owAdUnitId || getGptSlotInfoForAdUnitCode(adUnitId)?.gptSlot || adUnitId;
let auctionCache = cache.auctions[auctionId];
let floorData = auctionCache.floorData;
let wiid = cache.auctions[auctionId]?.wiid || auctionId;
Expand All @@ -466,7 +467,7 @@ function executeBidWonLoggerCall(auctionId, adUnitId) {
pixelURL += '&pid=' + enc(profileId);
pixelURL += '&pdvid=' + enc(profileVersionId);
pixelURL += '&slot=' + enc(adUnitId);
pixelURL += '&au=' + enc(origAdUnit.adUnitId || adUnitId);
pixelURL += '&au=' + enc(owAdUnitId);
pixelURL += '&pn=' + enc(adapterName);
pixelURL += '&bc=' + enc(winningBid.bidderCode || winningBid.bidder);
pixelURL += '&en=' + enc(winningBid.bidResponse.bidPriceUSD);
Expand Down
Loading

0 comments on commit 0124682

Please sign in to comment.