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

Merged
merged 7 commits into from
Mar 15, 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
2 changes: 1 addition & 1 deletion modules/pstudioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'pstudio';
const ENDPOINT = 'https://nft-exchange.pre-prod.pstudio.tadex.id/prebid-bid'
const ENDPOINT = 'https://exchange.pstudio.tadex.id/prebid-bid'
const TIME_TO_LIVE = 300;
// in case that the publisher limits number of user syncs, thisse syncs will be discarded from the end of the list
// so more improtant syncing calls should be at the start of the list
Expand Down
200 changes: 178 additions & 22 deletions modules/rasBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { isEmpty, parseSizesInput, deepAccess } from '../src/utils.js';
import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js';
import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import {
isEmpty,
parseSizesInput,
deepAccess
} from '../src/utils.js';
import { getAllOrtbKeywords } from '../libraries/keywords/keywords.js';
import { getAdUnitSizes } from '../libraries/sizeUtils/sizeUtils.js';

const BIDDER_CODE = 'ras';
const VERSION = '1.0';
Expand Down Expand Up @@ -56,28 +60,156 @@ function parseParams(params, bidderRequest) {
}
}
}
if (bidderRequest?.ortb2?.regs?.ext?.dsa?.required !== undefined) {
newParams.dsainfo = bidderRequest?.ortb2?.regs?.ext?.dsa?.required;
}
return newParams;
}

const buildBid = (ad) => {
if (ad.type === 'empty') {
/**
* @param url string
* @param type number // 1 - img, 2 - js
* @returns an object { event: 1, method: 1 or 2, url: 'string' }
*/
function prepareItemEventtrackers(url, type) {
return {
event: 1,
method: type,
url: url
};
}

function prepareEventtrackers(emsLink, imp, impression, impression1, impressionJs1) {
const eventtrackers = [prepareItemEventtrackers(emsLink, 1)];

if (imp) {
eventtrackers.push(prepareItemEventtrackers(imp, 1));
}

if (impression) {
eventtrackers.push(prepareItemEventtrackers(impression, 1));
}

if (impression1) {
eventtrackers.push(prepareItemEventtrackers(impression1, 1));
}

if (impressionJs1) {
eventtrackers.push(prepareItemEventtrackers(impressionJs1, 2));
}

return eventtrackers;
}

function parseOrtbResponse(ad) {
if (!(ad.data?.fields && ad.data?.meta)) {
return false;
}

const { image, Image, title, url, Headline, Thirdpartyclicktracker, imp, impression, impression1, impressionJs1 } = ad.data.fields;
const { dsaurl, height, width, adclick } = ad.data.meta;
const emsLink = ad.ems_link;
const link = adclick + (url || Thirdpartyclicktracker);
const eventtrackers = prepareEventtrackers(emsLink, imp, impression, impression1, impressionJs1);
const ortb = {
ver: '1.2',
assets: [
{
id: 2,
img: {
url: image || Image || '',
w: width,
h: height
}
},
{
id: 4,
title: {
text: title || Headline || ''
}
},
{
id: 3,
data: {
value: deepAccess(ad, 'data.meta.advertiser_name', null),
type: 1
}
}
],
link: {
url: link
},
eventtrackers
};

if (dsaurl) {
ortb.privacy = dsaurl
}

return ortb
}

function parseNativeResponse(ad) {
if (!(ad.data?.fields && ad.data?.meta)) {
return false;
}

const { image, Image, title, leadtext, url, Calltoaction, Body, Headline, Thirdpartyclicktracker } = ad.data.fields;
const { dsaurl, height, width, adclick } = ad.data.meta;
const link = adclick + (url || Thirdpartyclicktracker);
const nativeResponse = {
sendTargetingKeys: false,
title: title || Headline || '',
image: {
url: image || Image || '',
width,
height
},

clickUrl: link,
cta: Calltoaction || '',
body: leadtext || Body || '',
sponsoredBy: deepAccess(ad, 'data.meta.advertiser_name', null) || '',
ortb: parseOrtbResponse(ad)
};

if (dsaurl) {
nativeResponse.privacyLink = dsaurl;
}

return nativeResponse
}

const buildBid = (ad, mediaType) => {
if (ad.type === 'empty' || mediaType === undefined) {
return null;
}
return {

const data = {
requestId: ad.id,
cpm: ad.bid_rate ? ad.bid_rate.toFixed(2) : 0,
width: ad.width || 0,
height: ad.height || 0,
ttl: 300,
creativeId: ad.adid ? parseInt(ad.adid.split(',')[2], 10) : 0,
netRevenue: true,
currency: ad.currency || 'USD',
dealId: null,
meta: {
mediaType: BANNER
},
ad: ad.html || null
};
actgMatch: ad.actg_match || 0,
meta: { mediaType: BANNER },
mediaType: BANNER,
ad: ad.html || null,
width: ad.width || 0,
height: ad.height || 0
}

if (mediaType === 'native') {
data.meta = { mediaType: NATIVE };
data.mediaType = NATIVE;
data.native = parseNativeResponse(ad) || {};

delete data.ad;
}

return data;
};

const getContextParams = (bidRequests, bidderRequest) => {
Expand All @@ -102,18 +234,24 @@ const getSlots = (bidRequests) => {
for (let i = 0; i < batchSize; i++) {
const adunit = bidRequests[i];
const slotSequence = deepAccess(adunit, 'params.slotSequence');

const sizes = parseSizesInput(getAdUnitSizes(adunit)).join(',');
const creFormat = getAdUnitCreFormat(adunit);
const sizes = creFormat === 'native' ? 'fluid' : parseSizesInput(getAdUnitSizes(adunit)).join(',');

queryString += `&slot${i}=${encodeURIComponent(adunit.params.slot)}&id${i}=${encodeURIComponent(adunit.bidId)}&composition${i}=CHILD`;

if (sizes.length) {
if (creFormat === 'native') {
queryString += `&cre_format${i}=native`;
}

if (sizes) {
queryString += `&iusizes${i}=${encodeURIComponent(sizes)}`;
}
if (slotSequence !== undefined) {

if (slotSequence !== undefined && slotSequence !== null) {
queryString += `&pos${i}=${encodeURIComponent(slotSequence)}`;
}
}

return queryString;
};

Expand Down Expand Up @@ -160,9 +298,24 @@ const parseAuctionConfigs = (serverResponse, bidRequest) => {
}
}

const getAdUnitCreFormat = (adUnit) => {
if (!adUnit) {
return;
}

let creFormat = 'html';
let mediaTypes = Object.keys(adUnit.mediaTypes);

if (mediaTypes && mediaTypes.length === 1 && mediaTypes.includes('native')) {
creFormat = 'native';
}

return creFormat;
}

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

isBidRequestValid: function (bidRequest) {
if (!bidRequest || !bidRequest.params || typeof bidRequest.params !== 'object') {
Expand All @@ -183,7 +336,8 @@ export const spec = {
bidId: bid.bidId,
sizes: getAdUnitSizes(bid),
params: bid.params,
fledgeEnabled: fledgeEligible
fledgeEnabled: fledgeEligible,
mediaType: (bid.mediaTypes && bid.mediaTypes.banner) ? 'display' : NATIVE
}));

return [{
Expand All @@ -195,9 +349,11 @@ export const spec = {

interpretResponse: function (serverResponse, bidRequest) {
const response = serverResponse.body;

const fledgeAuctionConfigs = parseAuctionConfigs(serverResponse, bidRequest);
const bids = (!response || !response.ads || response.ads.length === 0) ? [] : response.ads.map(buildBid).filter((bid) => !isEmpty(bid));
const bids = (!response || !response.ads || response.ads.length === 0) ? [] : response.ads.map((ad, index) => buildBid(
ad,
bidRequest?.bidIds?.[index]?.mediaType || 'banner'
)).filter((bid) => !isEmpty(bid));

if (fledgeAuctionConfigs) {
// Return a tuple of bids and auctionConfigs. It is possible that bids could be null.
Expand Down
4 changes: 2 additions & 2 deletions modules/rasBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Maintainer: support@ringpublishing.com
# Description

Module that connects to Ringer Axel Springer demand sources.
Only banner format is supported.
Only banner and native format is supported.

# Test Parameters
```js
Expand Down Expand Up @@ -49,4 +49,4 @@ var adUnits = [{
| pageContext.keyValues | optional | Object | Key-values associated with this ad unit (case-insensitive); following characters are not allowed in the values: `" ' = ! + # * ~ ; ^ ( ) < > [ ] & @` | `{}` |
| pageContext.keyValues.ci | optional | String | Content unique identifier | `"932016a5-02fc-4d5c-b643-fafc2f270f06"` |
| pageContext.keyValues.adunit | optional | String | Ad unit name | `"example_com/sport"` |
| customParams | optional | Object | Custom request params | `{}` |
| customParams | optional | Object | Custom request params | `{}` |
4 changes: 4 additions & 0 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export const sharethroughAdapterSpec = {
req.regs.ext.gpp_sid = bidderRequest.ortb2.regs.gpp_sid;
}

if (bidderRequest?.ortb2?.regs?.ext?.dsa) {
req.regs.ext.dsa = bidderRequest.ortb2.regs.ext.dsa;
}

const imps = bidRequests
.map((bidReq) => {
const impression = { ext: {} };
Expand Down
23 changes: 15 additions & 8 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,11 @@ export const spec = {
}
iv = iv || getBidIdParameter('iv', bid.params)

const floorInfo = (bid.getFloor && typeof bid.getFloor === 'function') ? bid.getFloor({
currency: 'USD',
mediaType: bid.mediaTypes && bid.mediaTypes.banner ? 'banner' : 'video',
size: '*'
}) : {}
floorInfo.floor = floorInfo.floor || getBidIdParameter('bidfloor', bid.params)

const imp = {
adunitcode: bid.adUnitCode,
id: bid.bidId,
tagid: String(getBidIdParameter('tagid', bid.params)),
bidfloor: floorInfo.floor
bidfloor: _getBidFloors(bid)
}

if (deepAccess(bid, 'mediaTypes.banner')) {
Expand Down Expand Up @@ -332,4 +325,18 @@ function _buildVideoRequestObj(bid) {
return videoObj
}

function _getBidFloors(bid) {
const floorInfo = (bid.getFloor && typeof bid.getFloor === 'function') ? bid.getFloor({
currency: 'USD',
mediaType: bid.mediaTypes && bid.mediaTypes.banner ? 'banner' : 'video',
size: '*'
}) : {}
const floorModuleValue = parseFloat(floorInfo.floor)
if (!isNaN(floorModuleValue)) {
return floorModuleValue
}
const paramValue = parseFloat(getBidIdParameter('bidfloor', bid.params))
return !isNaN(paramValue) ? paramValue : undefined
}

registerBidder(spec)
Loading