Skip to content

Commit

Permalink
Merge branch 'prebid:master' into tradplus
Browse files Browse the repository at this point in the history
  • Loading branch information
tradplus authored Nov 22, 2024
2 parents 820707d + 3406b59 commit 5629eb1
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 194 deletions.
16 changes: 11 additions & 5 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,12 +1132,17 @@ func validateRequestExt(req *openrtb_ext.RequestWrapper) []error {
}

func validateTargeting(t *openrtb_ext.ExtRequestTargeting) error {
if t != nil {
if t.PriceGranularity != nil {
if err := validatePriceGranularity(t.PriceGranularity); err != nil {
return err
}
if t == nil {
return nil
}

if t.PriceGranularity != nil {
if err := validatePriceGranularity(t.PriceGranularity); err != nil {
return err
}
}

if t.MediaTypePriceGranularity != nil {
if t.MediaTypePriceGranularity.Video != nil {
if err := validatePriceGranularity(t.MediaTypePriceGranularity.Video); err != nil {
return err
Expand All @@ -1154,6 +1159,7 @@ func validateTargeting(t *openrtb_ext.ExtRequestTargeting) error {
}
}
}

return nil
}

Expand Down
47 changes: 27 additions & 20 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ func TestValidateTargeting(t *testing.T) {
expectedError: nil,
},
{
name: "price granularity ranges out of order",
name: "pricegranularity-ranges-out-of-order",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
PriceGranularity: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Expand All @@ -2000,9 +2000,16 @@ func TestValidateTargeting(t *testing.T) {
expectedError: errors.New(`Price granularity error: range list must be ordered with increasing "max"`),
},
{
name: "media type price granularity video correct",
name: "mediatypepricegranularity-nil",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: nil,
},
expectedError: nil,
},
{
name: "mediatypepricegranularity-video-ok",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Video: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2014,9 +2021,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: nil,
},
{
name: "media type price granularity banner correct",
name: "mediatypepricegranularity-banner-ok",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2028,9 +2035,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: nil,
},
{
name: "media type price granularity native correct",
name: "mediatypepricegranularity-native-ok",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Native: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2042,9 +2049,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: nil,
},
{
name: "media type price granularity video and banner correct",
name: "mediatypepricegranularity-video+banner-ok",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2062,9 +2069,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: nil,
},
{
name: "media type price granularity video incorrect",
name: "mediatypepricegranularity-video-invalid",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Video: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2076,9 +2083,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: errors.New("Price granularity error: increment must be a nonzero positive number"),
},
{
name: "media type price granularity banner incorrect",
name: "mediatypepricegranularity-banner-invalid",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2090,9 +2097,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: errors.New("Price granularity error: range list must be ordered with increasing \"max\""),
},
{
name: "media type price granularity native incorrect",
name: "mediatypepricegranularity-native-invalid",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Native: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2104,9 +2111,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: errors.New("Price granularity error: range list must be ordered with increasing \"max\""),
},
{
name: "media type price granularity video correct and banner incorrect",
name: "mediatypepricegranularity-video-ok-banner-invalid",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Banner: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2124,9 +2131,9 @@ func TestValidateTargeting(t *testing.T) {
expectedError: errors.New("Price granularity error: range list must be ordered with increasing \"max\""),
},
{
name: "media type price granularity native incorrect and banner correct",
name: "mediatypepricegranularity-native-invalid-banner-ok",
givenTargeting: &openrtb_ext.ExtRequestTargeting{
MediaTypePriceGranularity: openrtb_ext.MediaTypePriceGranularity{
MediaTypePriceGranularity: &openrtb_ext.MediaTypePriceGranularity{
Native: &openrtb_ext.PriceGranularity{
Precision: ptrutil.ToPtr(2),
Ranges: []openrtb_ext.GranularityRange{
Expand All @@ -2147,7 +2154,7 @@ func TestValidateTargeting(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expectedError, validateTargeting(tc.givenTargeting), "Targeting")
assert.Equal(t, tc.expectedError, validateTargeting(tc.givenTargeting))
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
]
},
"includewinners": true,
"includebidderkeys": true,
"mediatypepricegranularity": {}
"includebidderkeys": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@
]
},
"includewinners": true,
"includebidderkeys": true,
"mediatypepricegranularity": {}
"includebidderkeys": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@
]
},
"includewinners": true,
"includebidderkeys": true,
"mediatypepricegranularity": {}
"includebidderkeys": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@
]
},
"includewinners": true,
"includebidderkeys": true,
"mediatypepricegranularity": {}
"includebidderkeys": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@
]
},
"includewinners": true,
"includebidderkeys": true,
"mediatypepricegranularity": {}
"includebidderkeys": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@
]
},
"includewinners": true,
"includebidderkeys": true,
"mediatypepricegranularity": {}
"includebidderkeys": true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
}
]
},
"mediatypepricegranularity": {},
"includewinners": true,
"includebidderkeys": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
}
]
},
"mediatypepricegranularity": {},
"includewinners": true,
"includebidderkeys": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
}
]
},
"mediatypepricegranularity": {},
"includewinners": true,
"includebidderkeys": true
},
Expand Down
2 changes: 1 addition & 1 deletion endpoints/openrtb2/video_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestCreateBidExtensionTargeting(t *testing.T) {
require.NotNil(t, ex.lastRequest, "The request never made it into the Exchange.")

// assert targeting set to default
expectedRequestExt := `{"prebid":{"cache":{"vastxml":{}},"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":20,"increment":0.1}]},"mediatypepricegranularity":{},"includebidderkeys":true,"includewinners":true,"includebrandcategory":{"primaryadserver":1,"publisher":"","withcategory":true}}}}`
expectedRequestExt := `{"prebid":{"cache":{"vastxml":{}},"targeting":{"pricegranularity":{"precision":2,"ranges":[{"min":0,"max":20,"increment":0.1}]},"includebidderkeys":true,"includewinners":true,"includebrandcategory":{"primaryadserver":1,"withcategory":true}}}}`
assert.JSONEq(t, expectedRequestExt, string(ex.lastRequest.Ext))
}

Expand Down
61 changes: 35 additions & 26 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,33 +498,30 @@ func buildRequestExtForBidder(bidder string, req *openrtb_ext.RequestWrapper, re
}
prebid := reqExt.GetPrebid()

// Resolve alternatebiddercode
// Resolve Alternate Bidder Codes
var reqABC *openrtb_ext.ExtAlternateBidderCodes
if prebid != nil && prebid.AlternateBidderCodes != nil {
reqABC = prebid.AlternateBidderCodes
}
alternateBidderCodes := buildRequestExtAlternateBidderCodes(bidder, cfgABC, reqABC)

var prebidNew openrtb_ext.ExtRequestPrebid
if prebid == nil {
prebidNew = openrtb_ext.ExtRequestPrebid{
BidderParams: reqExtBidderParams[bidder],
AlternateBidderCodes: alternateBidderCodes,
}
} else {
// Copy Allowed Fields
// Per: https://docs.prebid.org/prebid-server/endpoints/openrtb2/pbs-endpoint-auction.html#prebid-server-ortb2-extension-summary
prebidNew = openrtb_ext.ExtRequestPrebid{
BidderParams: reqExtBidderParams[bidder],
AlternateBidderCodes: alternateBidderCodes,
Channel: prebid.Channel,
CurrencyConversions: prebid.CurrencyConversions,
Debug: prebid.Debug,
Integration: prebid.Integration,
MultiBid: buildRequestExtMultiBid(bidder, prebid.MultiBid, alternateBidderCodes),
Sdk: prebid.Sdk,
Server: prebid.Server,
}
// Build New/Filtered Prebid Ext
prebidNew := openrtb_ext.ExtRequestPrebid{
BidderParams: reqExtBidderParams[bidder],
AlternateBidderCodes: alternateBidderCodes,
}

// Copy Allowed Fields
// Per: https://docs.prebid.org/prebid-server/endpoints/openrtb2/pbs-endpoint-auction.html#prebid-server-ortb2-extension-summary
if prebid != nil {
prebidNew.Channel = prebid.Channel
prebidNew.CurrencyConversions = prebid.CurrencyConversions
prebidNew.Debug = prebid.Debug
prebidNew.Integration = prebid.Integration
prebidNew.MultiBid = buildRequestExtMultiBid(bidder, prebid.MultiBid, alternateBidderCodes)
prebidNew.Sdk = prebid.Sdk
prebidNew.Server = prebid.Server
prebidNew.Targeting = buildRequestExtTargeting(prebid.Targeting)
}

reqExt.SetPrebid(&prebidNew)
Expand Down Expand Up @@ -586,6 +583,18 @@ func buildRequestExtMultiBid(adapter string, reqMultiBid []*openrtb_ext.ExtMulti
return nil
}

func buildRequestExtTargeting(t *openrtb_ext.ExtRequestTargeting) *openrtb_ext.ExtRequestTargeting {
if t == nil || t.IncludeBrandCategory == nil {
return nil
}

// only include fields bidders can use to influence their response and which does
// not expose information about other bidders or restricted auction processing
return &openrtb_ext.ExtRequestTargeting{
IncludeBrandCategory: t.IncludeBrandCategory,
}
}

func isBidderInExtAlternateBidderCodes(adapter, currentMultiBidBidder string, adapterABC *openrtb_ext.ExtAlternateBidderCodes) bool {
if adapterABC != nil {
if abc, ok := adapterABC.Bidders[adapter]; ok {
Expand Down Expand Up @@ -924,15 +933,15 @@ func getExtCacheInstructions(requestExtPrebid *openrtb_ext.ExtRequestPrebid) ext
func getExtTargetData(requestExtPrebid *openrtb_ext.ExtRequestPrebid, cacheInstructions extCacheInstructions) *targetData {
if requestExtPrebid != nil && requestExtPrebid.Targeting != nil {
return &targetData{
includeWinners: *requestExtPrebid.Targeting.IncludeWinners,
includeBidderKeys: *requestExtPrebid.Targeting.IncludeBidderKeys,
alwaysIncludeDeals: requestExtPrebid.Targeting.AlwaysIncludeDeals,
includeBidderKeys: ptrutil.ValueOrDefault(requestExtPrebid.Targeting.IncludeBidderKeys),
includeCacheBids: cacheInstructions.cacheBids,
includeCacheVast: cacheInstructions.cacheVAST,
includeFormat: requestExtPrebid.Targeting.IncludeFormat,
priceGranularity: *requestExtPrebid.Targeting.PriceGranularity,
mediaTypePriceGranularity: requestExtPrebid.Targeting.MediaTypePriceGranularity,
includeWinners: ptrutil.ValueOrDefault(requestExtPrebid.Targeting.IncludeWinners),
mediaTypePriceGranularity: ptrutil.ValueOrDefault(requestExtPrebid.Targeting.MediaTypePriceGranularity),
preferDeals: requestExtPrebid.Targeting.PreferDeals,
alwaysIncludeDeals: requestExtPrebid.Targeting.AlwaysIncludeDeals,
priceGranularity: ptrutil.ValueOrDefault(requestExtPrebid.Targeting.PriceGranularity),
}
}

Expand Down
Loading

0 comments on commit 5629eb1

Please sign in to comment.