Skip to content
Open
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
85 changes: 62 additions & 23 deletions adapters/rtbhouse/rtbhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ func (adapter *RTBHouseAdapter) MakeRequests(
var publisherId string

for _, imp := range openRTBRequest.Imp {
rtbhouseExt, err := getImpressionExt(imp)
impExtMap := make(map[string]interface{})
err := json.Unmarshal(imp.Ext, &impExtMap)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: "Bidder extension not provided or can't be unmarshalled",
}}
}

rtbhouseExt, err := getImpressionExt(impExtMap)
if err != nil {
return nil, []error{err}
}
Expand Down Expand Up @@ -100,9 +108,13 @@ func (adapter *RTBHouseAdapter) MakeRequests(
imp.BidFloor = bidFloor
}

// remove PAAPI signals from imp.Ext. RTB House pauses PAAPI support,
// the bidder should not get any PAAPI signals
newImpExt, err := clearAuctionEnvironment(&imp)
if imp.TagID == "" {
imp.TagID = getTagIDFromImpExt(impExtMap, imp.ID)
}

// remove PAAPI signals
clearAuctionEnvironment(impExtMap)
newImpExt, err := json.Marshal(impExtMap)
if err != nil {
errs = append(errs, err)
return nil, errs
Expand Down Expand Up @@ -199,44 +211,71 @@ func setPublisherID(request *openrtb2.BidRequest, publisherId string) error {
return nil
}

func clearAuctionEnvironment(imp *openrtb2.Imp) (json.RawMessage, error) {
var objmap map[string]interface{}
err := json.Unmarshal(imp.Ext, &objmap)
if err != nil {
return nil, err
}

func clearAuctionEnvironment(impExtMap map[string]interface{}) {
keysToDelete := []string{"ae", "igs", "paapi"}
for _, key := range keysToDelete {
_, exists := objmap[key]
if exists {
delete(objmap, key)
delete(impExtMap, key)
}
}

func getTagIDFromImpExt(impExtMap map[string]interface{}, impID string) string {
// imp.ext.gpid
if gpid, ok := impExtMap["gpid"].(string); ok && gpid != "" {
return gpid
}

dataMap, hasData := impExtMap["data"].(map[string]interface{})
if hasData {
// imp.ext.data.adserver.adslot
if adserver, ok := dataMap["adserver"].(map[string]interface{}); ok {
if adslot, ok := adserver["adslot"].(string); ok && adslot != "" {
return adslot
}
}

// imp.ext.data.pbAdSlot
if pbAdSlot, ok := dataMap["pbadslot"].(string); ok && pbAdSlot != "" {
return pbAdSlot
}
}

newImpExt, err := json.Marshal(objmap)
if err != nil {
return nil, err
// imp.ID as fallback
if impID != "" {
return impID
}

return newImpExt, nil
return ""
}

func getImpressionExt(imp openrtb2.Imp) (*openrtb_ext.ExtImpRTBHouse, error) {
var bidderExt adapters.ExtImpBidder
if err := jsonutil.Unmarshal(imp.Ext, &bidderExt); err != nil {
func getImpressionExt(impExtMap map[string]interface{}) (*openrtb_ext.ExtImpRTBHouse, error) {
var bidderVal interface{}
var found bool

// Check for bidder parameters in imp.ext.bidder
if val, ok := impExtMap["bidder"]; ok {
bidderVal = val
found = true
}

if !found {
return nil, &errortypes.BadInput{
Message: "Bidder extension not provided or can't be unmarshalled",
}
}

bidderBytes, err := json.Marshal(bidderVal)
if err != nil {
return nil, &errortypes.BadInput{
Message: "Bidder extension not provided or can't be unmarshalled",
}
}

var rtbhouseExt openrtb_ext.ExtImpRTBHouse
if err := jsonutil.Unmarshal(bidderExt.Bidder, &rtbhouseExt); err != nil {
if err := jsonutil.Unmarshal(bidderBytes, &rtbhouseExt); err != nil {
return nil, &errortypes.BadInput{
Message: "Error while unmarshaling bidder extension",
}
}

return &rtbhouseExt, nil
}

Expand Down
3 changes: 2 additions & 1 deletion adapters/rtbhouse/rtbhousetest/exemplary/ae-igs-removal.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
],
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
Expand All @@ -50,7 +51,7 @@
},
"someOtherField": "should-remain"
},
"id": "test-imp-id"
"tagid": "test-imp-id"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"publisherId": "app-publisher-123"
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion adapters/rtbhouse/rtbhousetest/exemplary/app_banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-imp-id"
}]
},
"impIDs":["test-imp-id"]
Expand Down
3 changes: 2 additions & 1 deletion adapters/rtbhouse/rtbhousetest/exemplary/app_native.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-native-imp"
}
],
"app": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-imp-id"
}]
},
"impIDs":["test-imp-id"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"bidfloor": 3.00
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"bidfloor": 2
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"publisherId": "12345"
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"publisherId": "12345"
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"publisherId": "new-publisher-123"
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"publisherId": "first-publisher"
}
},
"id": "test-imp-id-1"
"id": "test-imp-id-1",
"tagid": "test-imp-id-1"
},
{
"banner": {
Expand All @@ -76,7 +77,8 @@
"publisherId": "second-publisher"
}
},
"id": "test-imp-id-2"
"id": "test-imp-id-2",
"tagid": "test-imp-id-2"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-native-imp"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-native-imp"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"publisherId": "12345"
}
},
"id": "test-imp-id"
"id": "test-imp-id",
"tagid": "test-imp-id"
}
],
"site": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-imp-id"
}]
},
"impIDs":["test-imp-id"]
Expand Down
3 changes: 2 additions & 1 deletion adapters/rtbhouse/rtbhousetest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"ext": {
"bidder": {}
}
},
"tagid": "test-imp-id"
}]
},
"impIDs":["test-imp-id"]
Expand Down
Loading
Loading