Skip to content

Commit

Permalink
RAS Bid Adapter: fledge support (#10477)
Browse files Browse the repository at this point in the history
* add fledge support to rasBidAdapter

* add unit test, add params to auction signals
  • Loading branch information
wsusrasp committed Oct 3, 2023
1 parent 2ad6400 commit 2905b4c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 4 deletions.
52 changes: 48 additions & 4 deletions modules/rasBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,36 @@ const getGdprParams = (bidderRequest) => {
return queryString;
};

const parseAuctionConfigs = (serverResponse, bidRequest) => {
if (isEmpty(bidRequest)) {
return null;
}
const auctionConfigs = [];
const gctx = serverResponse && serverResponse.body?.gctx;

bidRequest.bidIds.filter(bid => bid.fledgeEnabled).forEach((bid) => {
auctionConfigs.push({
'bidId': bid.bidId,
'config': {
'seller': 'https://csr.onet.pl',
'decisionLogicUrl': `https://csr.onet.pl/${encodeURIComponent(bid.params.network)}/v1/protected-audience-api/decision-logic.js`,
'interestGroupBuyers': ['https://csr.onet.pl'],
'auctionSignals': {
'params': bid.params,
'sizes': bid.sizes,
'gctx': gctx
}
}
});
});

if (auctionConfigs.length === 0) {
return null;
} else {
return auctionConfigs;
}
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
Expand All @@ -146,8 +176,16 @@ export const spec = {
const slotsQuery = getSlots(bidRequests);
const contextQuery = getContextParams(bidRequests, bidderRequest);
const gdprQuery = getGdprParams(bidderRequest);
const bidIds = bidRequests.map((bid) => ({ slot: bid.params.slot, bidId: bid.bidId }));
const fledgeEligible = Boolean(bidderRequest && bidderRequest.fledgeEnabled);
const network = bidRequests[0].params.network;
const bidIds = bidRequests.map((bid) => ({
slot: bid.params.slot,
bidId: bid.bidId,
sizes: getAdUnitSizes(bid),
params: bid.params,
fledgeEnabled: fledgeEligible
}));

return [{
method: 'GET',
url: getEndpoint(network) + contextQuery + slotsQuery + gdprQuery,
Expand All @@ -157,10 +195,16 @@ export const spec = {

interpretResponse: function (serverResponse, bidRequest) {
const response = serverResponse.body;
if (!response || !response.ads || response.ads.length === 0) {
return [];

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

if (fledgeAuctionConfigs) {
// Return a tuple of bids and auctionConfigs. It is possible that bids could be null.
return {bids, fledgeAuctionConfigs};
} else {
return bids;
}
return response.ads.map(buildBid).filter((bid) => !isEmpty(bid));
}
};

Expand Down
52 changes: 52 additions & 0 deletions test/spec/modules/rasBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spec } from 'modules/rasBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import {getAdUnitSizes} from '../../../src/utils';

const CSR_ENDPOINT = 'https://csr.onet.pl/4178463/csr-006/csr.json?nid=4178463&';

Expand Down Expand Up @@ -192,5 +193,56 @@ describe('rasBidAdapter', function () {
const resp = spec.interpretResponse({ body: res }, {});
expect(resp).to.deep.equal([]);
});

it('should generate auctionConfig when fledge is enabled', function () {
let bidRequest = {
method: 'GET',
url: 'https://example.com',
bidIds: [{
slot: 'top',
bidId: '123',
network: 'testnetwork',
sizes: ['300x250'],
params: {
site: 'testsite',
area: 'testarea',
network: 'testnetwork'
},
fledgeEnabled: true
},
{
slot: 'top',
bidId: '456',
network: 'testnetwork',
sizes: ['300x250'],
params: {
site: 'testsite',
area: 'testarea',
network: 'testnetwork'
},
fledgeEnabled: false
}]
};

let auctionConfigs = [{
'bidId': '123',
'config': {
'seller': 'https://csr.onet.pl',
'decisionLogicUrl': 'https://csr.onet.pl/testnetwork/v1/protected-audience-api/decision-logic.js',
'interestGroupBuyers': ['https://csr.onet.pl'],
'auctionSignals': {
'params': {
site: 'testsite',
area: 'testarea',
network: 'testnetwork'
},
'sizes': ['300x250'],
'gctx': '1234567890'
}
}
}];
const resp = spec.interpretResponse({body: {gctx: '1234567890'}}, bidRequest);
expect(resp).to.deep.equal({bids: [], fledgeAuctionConfigs: auctionConfigs});
});
});
});

0 comments on commit 2905b4c

Please sign in to comment.