Skip to content

Commit

Permalink
IX: add privacy sandbox support (prebid#3252)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Corbo <[email protected]>
  • Loading branch information
2 people authored and SuprPhatAnon committed Dec 7, 2023
1 parent c72fef6 commit eb07ab9
Show file tree
Hide file tree
Showing 5 changed files with 577 additions and 0 deletions.
29 changes: 29 additions & 0 deletions adapters/ix/ix.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ type IxDiag struct {
MultipleSiteIds string `json:"multipleSiteIds,omitempty"`
}

type auctionConfig struct {
BidId string `json:"bidId,omitempty"`
Config json.RawMessage `json:"config,omitempty"`
}

type ixRespExt struct {
AuctionConfig []auctionConfig `json:"protectedAudienceAuctionConfigs,omitempty"`
}

func (a *IxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requests := make([]*adapters.RequestData, 0, len(request.Imp))
errs := make([]error, 0)
Expand Down Expand Up @@ -273,6 +282,26 @@ func (a *IxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalReque
}
}

if bidResponse.Ext != nil {
var bidRespExt ixRespExt
if err := json.Unmarshal(bidResponse.Ext, &bidRespExt); err != nil {
return nil, append(errs, err)
}

if bidRespExt.AuctionConfig != nil {
bidderResponse.FledgeAuctionConfigs = make([]*openrtb_ext.FledgeAuctionConfig, 0, len(bidRespExt.AuctionConfig))
for _, config := range bidRespExt.AuctionConfig {
if config.Config != nil {
fledgeAuctionConfig := &openrtb_ext.FledgeAuctionConfig{
ImpId: config.BidId,
Config: config.Config,
}
bidderResponse.FledgeAuctionConfigs = append(bidderResponse.FledgeAuctionConfigs, fledgeAuctionConfig)
}
}
}
}

return bidderResponse, errs
}

Expand Down
106 changes: 106 additions & 0 deletions adapters/ix/ix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,109 @@ func TestMakeRequestsErrIxDiag(t *testing.T) {
_, errs := bidder.MakeRequests(req, nil)
assert.Len(t, errs, 1)
}

func TestPABidResponse(t *testing.T) {
bidder := &IxAdapter{}

mockedReq := &openrtb2.BidRequest{
Imp: []openrtb2.Imp{{
ID: "1_1",
Banner: &openrtb2.Banner{
Format: []openrtb2.Format{{W: 300, H: 250}},
},
Ext: json.RawMessage(
`{
"ae": 1,
"bidder": {
"siteID": "123456"
}
}`,
)},
},
}
mockedExtReq := &adapters.RequestData{}
mockedBidResponse := &openrtb2.BidResponse{
ID: "test-1",
SeatBid: []openrtb2.SeatBid{{
Seat: "Buyer",
Bid: []openrtb2.Bid{{
ID: "1",
ImpID: "1_1",
Price: 1.23,
AdID: "123",
Ext: json.RawMessage(
`{
"prebid": {
"video": {
"duration": 60,
"primary_category": "IAB18-1"
}
}
}`,
),
}},
}},
}

testCases := []struct {
name string
ext json.RawMessage
expectedLen int
}{
{
name: "properly formatted",
ext: json.RawMessage(
`{
"protectedAudienceAuctionConfigs": [{
"bidId": "test-imp-id",
"config": {
"seller": "https://seller.com",
"decisionLogicUrl": "https://ssp.com/decision-logic.js",
"interestGroupBuyers": [
"https://buyer.com"
],
"sellerSignals": {
"callbackUrl": "https://callbackurl.com"
},
"perBuyerSignals": {
"https://buyer.com": []
}
}
}]
}`,
),
expectedLen: 1,
},
{
name: "no protected audience auction configs returned",
ext: json.RawMessage(`{}`),
expectedLen: 0,
},
{
name: "no config",
ext: json.RawMessage(
`{
"protectedAudienceAuctionConfigs": [{
"bidId": "test-imp-id"
}]
}`,
),
expectedLen: 0,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mockedBidResponse.Ext = tc.ext
body, _ := json.Marshal(mockedBidResponse)
mockedRes := &adapters.ResponseData{
StatusCode: 200,
Body: body,
}
bidResponse, errors := bidder.MakeBids(mockedReq, mockedExtReq, mockedRes)

assert.Nil(t, errors)
assert.Len(t, bidResponse.FledgeAuctionConfigs, tc.expectedLen)
})
}
}
171 changes: 171 additions & 0 deletions adapters/ix/ixtest/exemplary/fledge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
},
{
"w": 600,
"h": 800
}
]
},
"ext": {
"bidder": {
"siteId": "569749"
},
"ae": 1
}
}
],
"site": {
"page": "https://www.example.com/"
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://host/endpoint",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
},
{
"w": 600,
"h": 800
}
]
},
"ext": {
"bidder": {
"siteId": "569749"
},
"ae": 1
}
}
],
"site": {
"page": "https://www.example.com/",
"publisher": {
"id": "569749"
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "958",
"bid": [
{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"https://advertiser.example.com"
],
"cid": "958",
"crid": "29681110",
"h": 250,
"w": 300,
"ext": {
"ix": {}
}
}
]
}
],
"bidid": "5778926625248726496",
"cur": "USD",
"ext": {
"protectedAudienceAuctionConfigs": [{
"bidId": "test-imp-id",
"config": {
"seller": "https://seller.com",
"decisionLogicUrl": "https://ssp.com/decision-logic.js",
"interestGroupBuyers": [
"https://buyer.com"
],
"sellerSignals": {
"callbackURL": "https://callbackurl.com"
},
"perBuyerSignals": {
"https://buyer.com": []
}
}
}]
}
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"adid": "29681110",
"adomain": [
"https://advertiser.example.com"
],
"cid": "958",
"crid": "29681110",
"w": 300,
"h": 250,
"ext": {
"ix": {}
}
},
"type": "banner"
}
],
"fledgeauctionconfigs": [{
"impid": "test-imp-id",
"config": {
"seller": "https://seller.com",
"decisionLogicUrl": "https://ssp.com/decision-logic.js",
"interestGroupBuyers": [
"https://buyer.com"
],
"sellerSignals": {
"callbackURL": "https://callbackurl.com"
},
"perBuyerSignals": {
"https://buyer.com": []
}
}
}]
}
]
}
Loading

0 comments on commit eb07ab9

Please sign in to comment.