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

RAS Bid Adapter: fledge support #10477

Merged
merged 2 commits into from
Oct 3, 2023
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
52 changes: 48 additions & 4 deletions modules/rasBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@ const getGdprParams = (bidderRequest) => {
return queryString;
};

const parseAuctionConfigs = (serverResponse, bidRequest) => {
if (isEmpty(bidRequest)) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not append fledge if it is empty?

Copy link
Contributor Author

@wsusrasp wsusrasp Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the first iteration of implementation we were planning to return the configs in the serverResponse so if it was empty we would return null, but as you pointed out now there is no reason to do that. I'll correct the code.

}
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 @@ -145,8 +175,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 @@ -156,10 +194,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});
});
});
});