Skip to content

Commit

Permalink
enhance fledge (prebid#11455)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikagotso authored and f.caspar committed May 14, 2024
1 parent 0b8b6ec commit 6691499
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 31 deletions.
38 changes: 34 additions & 4 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
logError,
deepAccess,
isInteger,
logWarn, getBidIdParameter
logWarn, getBidIdParameter, isEmptyStr
} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import {
Expand Down Expand Up @@ -254,16 +254,38 @@ export const spec = {
}))
.flat()

let fledgeAuctionConfigs = deepAccess(ext, 'fledge_auction_configs');
let fledgeAuctionConfigs = null;
if (isArray(ext?.igbid)) {
const seller = ext.seller
const decisionLogicUrl = ext.decisionLogicUrl
const sellerTimeout = ext.sellerTimeout
ext.igbid.filter(item => isValidIgBid(item)).forEach((igbid) => {
const perBuyerSignals = {}
igbid.igbuyer.filter(item => isValidIgBuyer(item)).forEach(buyerItem => {
perBuyerSignals[buyerItem.igdomain] = buyerItem.buyerdata
})
const interestGroupBuyers = [...Object.keys(perBuyerSignals)]
if (interestGroupBuyers.length) {
fledgeAuctionConfigs = fledgeAuctionConfigs || {}
fledgeAuctionConfigs[igbid.impid] = {
seller,
decisionLogicUrl,
sellerTimeout,
interestGroupBuyers: interestGroupBuyers,
perBuyerSignals,
}
}
})
}
if (fledgeAuctionConfigs) {
fledgeAuctionConfigs = Object.entries(fledgeAuctionConfigs).map(([bidId, cfg]) => {
return {
bidId,
config: Object.assign({
auctionSignals: {},
auctionSignals: {}
}, cfg)
}
});
})
return {
bids,
fledgeAuctionConfigs,
Expand Down Expand Up @@ -367,4 +389,12 @@ function _getBidFloors(bid) {
return !isNaN(paramValue) ? paramValue : undefined
}

function isValidIgBid(igBid) {
return !isEmptyStr(igBid.impid) && isArray(igBid.igbuyer) && igBid.igbuyer.length
}

function isValidIgBuyer(igBuyer) {
return !isEmptyStr(igBuyer.igdomain)
}

registerBidder(spec)
132 changes: 105 additions & 27 deletions test/spec/modules/sovrnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,26 +844,56 @@ describe('sovrnBidAdapter', function() {
}]
}],
ext: {
fledge_auction_configs: {
'test_bid_id': {
seller: 'ap.lijit.com',
interestGroupBuyers: ['dsp1.com'],
sellerTimeout: 0,
perBuyerSignals: {
'dsp1.com': {
bid_macros: 0.1,
disallowed_adv_ids: [
'8765',
'4321'
],
}
seller: 'seller.lijit.com',
decisionLogicUrl: 'https://decision.lijit.com',
igbid: [{
impid: 'test_imp_id',
igbuyer: [{
igdomain: 'ap.lijit.com',
buyerdata: {
base_bid_micros: 0.1,
use_bid_multiplier: true,
multiplier: '1.3'
}
}
}
}, {
igdomain: 'buyer2.com',
buyerdata: {}
}, {
igdomain: 'buyer3.com',
buyerdata: {}
}]
}, {
impid: 'test_imp_id_2',
igbuyer: [{
igdomain: 'ap2.lijit.com',
buyerdata: {
base_bid_micros: '0.2',
}
}]
}, {
impid: '',
igbuyer: [{
igdomain: 'ap3.lijit.com',
buyerdata: {
base_bid_micros: '0.3',
}
}]
}, {
impid: 'test_imp_id_3',
igbuyer: [{
igdomain: '',
buyerdata: {
base_bid_micros: '0.3',
}
}]
}, {
impid: 'test_imp_id_4',
igbuyer: []
}]
}
}
}
let invalidFledgeResponse = {
let emptyFledgeResponse = {
body: {
id: '37386aade21a71',
seatbid: [{
Expand All @@ -879,25 +909,73 @@ describe('sovrnBidAdapter', function() {
}]
}],
ext: {
fledge_auction_configs: {
igbid: {
}
}
}
}
it('should return fledge auction configs alongside bids', function () {
let expectedResponse = {
requestId: '263c448586f5a1',
cpm: 0.45882675,
width: 728,
height: 90,
creativeId: 'creativelycreatedcreativecreative',
dealId: null,
currency: 'USD',
netRevenue: true,
mediaType: 'banner',
ttl: 60000,
meta: { advertiserDomains: [] },
ad: decodeURIComponent(`<!-- Creative --><img src=<!-- NURL -->>`)
}
let expectedFledgeResponse = [
{
bidId: 'test_imp_id',
config: {
seller: 'seller.lijit.com',
decisionLogicUrl: 'https://decision.lijit.com',
sellerTimeout: undefined,
auctionSignals: {},
interestGroupBuyers: ['ap.lijit.com', 'buyer2.com', 'buyer3.com'],
perBuyerSignals: {
'ap.lijit.com': {
base_bid_micros: 0.1,
use_bid_multiplier: true,
multiplier: '1.3'
},
'buyer2.com': {},
'buyer3.com': {}
}
}
},
{
bidId: 'test_imp_id_2',
config: {
seller: 'seller.lijit.com',
decisionLogicUrl: 'https://decision.lijit.com',
sellerTimeout: undefined,
auctionSignals: {},
interestGroupBuyers: ['ap2.lijit.com'],
perBuyerSignals: {
'ap2.lijit.com': {
base_bid_micros: '0.2',
}
}
}
}
]

it('should return valid fledge auction configs alongside bids', function () {
const result = spec.interpretResponse(fledgeResponse)
expect(result).to.have.property('bids')
expect(result).to.have.property('fledgeAuctionConfigs')
expect(result.fledgeAuctionConfigs.length).to.equal(1)
expect(result.fledgeAuctionConfigs[0].bidId).to.equal('test_bid_id')
expect(result.fledgeAuctionConfigs[0].config).to.not.be.undefined
expect(result.fledgeAuctionConfigs[0].config).to.contain.keys('seller', 'interestGroupBuyers', 'sellerTimeout', 'perBuyerSignals')
expect(result.fledgeAuctionConfigs.length).to.equal(2)
expect(result.fledgeAuctionConfigs).to.deep.equal(expectedFledgeResponse)
})
it('should ignore invalid fledge auction configs', function () {
const result = spec.interpretResponse(invalidFledgeResponse)
expect(result).to.have.property('bids')
expect(result).to.have.property('fledgeAuctionConfigs')
expect(result.fledgeAuctionConfigs.length).to.equal(0)
it('should ignore empty fledge auction configs array', function () {
const result = spec.interpretResponse(emptyFledgeResponse)
expect(result.length).to.equal(1)
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse))
})
})

Expand Down

0 comments on commit 6691499

Please sign in to comment.