Skip to content

Commit

Permalink
UOE-11092-P1: Supporing OM based impression tracker for partners (#920)
Browse files Browse the repository at this point in the history
* UOE-11092: Support enable/disable imp_counting_method(1px) feature for bidders

Co-authored-by: Avinash Kapre <[email protected]>
  • Loading branch information
PubMatic-OpenWrap and AvinashKapre authored Sep 26, 2024
1 parent bcc32d1 commit 0babd5d
Show file tree
Hide file tree
Showing 18 changed files with 739 additions and 160 deletions.
5 changes: 5 additions & 0 deletions modules/pubmatic/openwrap/auctionresponsehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (m OpenWrap) handleAuctionResponseHook(
return result, nil
}

//Impression counting method enabled bidders
if rctx.Endpoint == models.EndpointV25 || rctx.Endpoint == models.EndpointAppLovinMax {
rctx.ImpCountingMethodEnabledBidders = m.pubFeatures.GetImpCountingMethodEnabledBidders()
}

var winningAdpodBidIds map[string][]string
var errs []error
if rctx.IsCTVRequest {
Expand Down
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/auctionresponsehook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ func TestAuctionResponseHookForApplovinMax(t *testing.T) {
mockEngine.EXPECT().RecordPublisherResponseTimeStats(gomock.Any(), gomock.Any())
mockFeature.EXPECT().IsFscApplicable(gomock.Any(), gomock.Any(), gomock.Any()).Return(false)
mockEngine.EXPECT().RecordPartnerResponseTimeStats(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
mockFeature.EXPECT().GetImpCountingMethodEnabledBidders().Return(map[string]struct{}{})
return mockEngine
},
},
Expand Down
3 changes: 2 additions & 1 deletion modules/pubmatic/openwrap/entrypointhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func (m OpenWrap) handleEntrypointHook(
WakandaDebug: &wakanda.Debug{
Config: m.cfg.Wakanda,
},
SendBurl: endpoint == models.EndpointAppLovinMax || getSendBurl(payload.Body),
SendBurl: endpoint == models.EndpointAppLovinMax || getSendBurl(payload.Body),
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
}

if rCtx.IsCTVRequest {
Expand Down
142 changes: 74 additions & 68 deletions modules/pubmatic/openwrap/entrypointhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,18 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) {
Name: "KADUSERCOOKIE",
Value: `7D75D25F-FAC9-443D-B2D1-B17FEE11E027`,
},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "5890",
Endpoint: models.EndpointV25,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "5890",
Endpoint: models.EndpointV25,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
},
},
},
Expand Down Expand Up @@ -173,29 +174,30 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) {
want: hookstage.HookResult[hookstage.EntrypointPayload]{
ModuleContext: hookstage.ModuleContext{
"rctx": models.RequestCtx{
PubIDStr: "5890",
PubID: 5890,
ProfileID: 5890,
DisplayID: 1,
DisplayVersionID: 1,
SSAuction: -1,
Debug: true,
UA: "go-test",
IP: "127.0.0.1",
IsCTVRequest: false,
TrackerEndpoint: "t.pubmatic.com",
VideoErrorTrackerEndpoint: "t.pubmatic.com/error",
LoggerImpressionID: "4df09505-d0b2-4d70-94d9-dc41e8e777f7",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "5890",
Endpoint: models.EndpointV25,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
PubIDStr: "5890",
PubID: 5890,
ProfileID: 5890,
DisplayID: 1,
DisplayVersionID: 1,
SSAuction: -1,
Debug: true,
UA: "go-test",
IP: "127.0.0.1",
IsCTVRequest: false,
TrackerEndpoint: "t.pubmatic.com",
VideoErrorTrackerEndpoint: "t.pubmatic.com/error",
LoggerImpressionID: "4df09505-d0b2-4d70-94d9-dc41e8e777f7",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "5890",
Endpoint: models.EndpointV25,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
},
},
},
Expand Down Expand Up @@ -276,17 +278,18 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) {
Name: "KADUSERCOOKIE",
Value: `7D75D25F-FAC9-443D-B2D1-B17FEE11E027`,
},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "43563",
Endpoint: models.EndpointWebS2S,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "43563",
Endpoint: models.EndpointWebS2S,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
},
},
},
Expand Down Expand Up @@ -337,17 +340,18 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) {
Name: "KADUSERCOOKIE",
Value: `7D75D25F-FAC9-443D-B2D1-B17FEE11E027`,
},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "43563",
Endpoint: models.EndpointWebS2S,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "43563",
Endpoint: models.EndpointWebS2S,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
},
},
},
Expand Down Expand Up @@ -500,17 +504,18 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) {
Name: "KADUSERCOOKIE",
Value: `7D75D25F-FAC9-443D-B2D1-B17FEE11E027`,
},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "5890",
Endpoint: models.EndpointV25,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
OriginCookie: "go-test",
Aliases: make(map[string]string),
ImpBidCtx: make(map[string]models.ImpCtx),
PrebidBidderCode: make(map[string]string),
BidderResponseTimeMillis: make(map[string]int),
ProfileIDStr: "5890",
Endpoint: models.EndpointV25,
MetricsEngine: mockEngine,
SeatNonBids: make(map[string][]openrtb_ext.NonBid),
Method: "POST",
WakandaDebug: &wakanda.Debug{},
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
},
},
},
Expand Down Expand Up @@ -593,7 +598,8 @@ func TestOpenWrap_handleEntrypointHook(t *testing.T) {
},
},
},
SendBurl: true,
SendBurl: true,
ImpCountingMethodEnabledBidders: make(map[string]struct{}),
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions modules/pubmatic/openwrap/models/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ const (
PixelPosAbove = "above"
PixelPosBelow = "below"

//constants for tracker impCountingMethod
ImpCountingMethod = "imp_ct_mthd"

DealIDNotApplicable = "na"
DealTierNotApplicable = "na"
PwtDealTier = "pwtdealtier"
Expand Down Expand Up @@ -593,6 +596,7 @@ const (
FeatureMaxFloors = 5
FeatureBidRecovery = 6
FeatureApplovinMultiFloors = 7
FeatureImpCountingMethod = 8
)

// constants for applovinmax requests
Expand Down
61 changes: 31 additions & 30 deletions modules/pubmatic/openwrap/models/openwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,37 @@ type RequestCtx struct {

BidderResponseTimeMillis map[string]int

Endpoint string
PubIDStr, ProfileIDStr string // TODO: remove this once we completely move away from header-bidding
MetricsEngine metrics.MetricsEngine
ReturnAllBidStatus bool // ReturnAllBidStatus stores the value of request.ext.prebid.returnallbidstatus
Sshb string //Sshb query param to identify that the request executed heder-bidding or not, sshb=1(executed HB(8001)), sshb=2(reverse proxy set from HB(8001->8000)), sshb=""(direct request(8000)).
DCName string
CachePutMiss int // to be used in case of CTV JSON endpoint/amp/inapp-ott-video endpoint
CurrencyConversion func(from string, to string, value float64) (float64, error)
MatchedImpression map[string]int
CustomDimensions map[string]CustomDimension
AmpVideoEnabled bool //AmpVideoEnabled indicates whether to include a Video object in an AMP request.
IsTBFFeatureEnabled bool
VastUnwrapEnabled bool
VastUnwrapStatsEnabled bool
AppLovinMax AppLovinMax
LoggerDisabled bool
TrackerDisabled bool
ProfileType int
ProfileTypePlatform int
AppPlatform int
AppIntegrationPath *int
AppSubIntegrationPath *int
Method string
Errors []error
RedirectURL string
ResponseFormat string
WakandaDebug wakanda.WakandaDebug
PriceGranularity *openrtb_ext.PriceGranularity
IsMaxFloorsEnabled bool
SendBurl bool
Endpoint string
PubIDStr, ProfileIDStr string // TODO: remove this once we completely move away from header-bidding
MetricsEngine metrics.MetricsEngine
ReturnAllBidStatus bool // ReturnAllBidStatus stores the value of request.ext.prebid.returnallbidstatus
Sshb string //Sshb query param to identify that the request executed heder-bidding or not, sshb=1(executed HB(8001)), sshb=2(reverse proxy set from HB(8001->8000)), sshb=""(direct request(8000)).
DCName string
CachePutMiss int // to be used in case of CTV JSON endpoint/amp/inapp-ott-video endpoint
CurrencyConversion func(from string, to string, value float64) (float64, error)
MatchedImpression map[string]int
CustomDimensions map[string]CustomDimension
AmpVideoEnabled bool //AmpVideoEnabled indicates whether to include a Video object in an AMP request.
IsTBFFeatureEnabled bool
VastUnwrapEnabled bool
VastUnwrapStatsEnabled bool
AppLovinMax AppLovinMax
LoggerDisabled bool
TrackerDisabled bool
ProfileType int
ProfileTypePlatform int
AppPlatform int
AppIntegrationPath *int
AppSubIntegrationPath *int
Method string
Errors []error
RedirectURL string
ResponseFormat string
WakandaDebug wakanda.WakandaDebug
PriceGranularity *openrtb_ext.PriceGranularity
IsMaxFloorsEnabled bool
SendBurl bool
ImpCountingMethodEnabledBidders map[string]struct{} // Bidders who have enabled ImpCountingMethod feature

// Adpod
AdruleFlag bool
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/models/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type OWTracker struct {
PriceModel string
PriceCurrency string
BidType string `json:"-"` // video, banner, native
DspId int `json:"-"` // dsp id
IsOMEnabled bool `json:"-"` // is om enabled
}

// Tracker tracker url creation parameters
Expand Down
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/publisherfeature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type Feature interface {
IsBidRecoveryEnabled(pubID int, profileID int) bool
IsApplovinMultiFloorsEnabled(pubID int, profileID string) bool
GetApplovinMultiFloors(pubID int, profileID string) models.ApplovinAdUnitFloors
GetImpCountingMethodEnabledBidders() map[string]struct{}
}
48 changes: 48 additions & 0 deletions modules/pubmatic/openwrap/publisherfeature/impcountingmethod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package publisherfeature

import (
"strings"

"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

type impCountingMethod struct {
enabledBidders [2]map[string]struct{}
index int32
}

func newImpCountingMethod() impCountingMethod {
return impCountingMethod{
enabledBidders: [2]map[string]struct{}{
make(map[string]struct{}),
make(map[string]struct{}),
},
index: 0,
}
}

func (fe *feature) updateImpCountingMethodEnabledBidders() {
if fe.publisherFeature == nil {
return
}

enabledBidders := make(map[string]struct{})
for pubID, feature := range fe.publisherFeature {
if val, ok := feature[models.FeatureImpCountingMethod]; ok && pubID == 0 && val.Enabled == 1 {
bidders := strings.Split(val.Value, ",")
for _, bidder := range bidders {
bidder = strings.TrimSpace(bidder)
if bidder != "" {
enabledBidders[bidder] = struct{}{}
}
}
}
}

fe.impCountingMethod.enabledBidders[fe.impCountingMethod.index^1] = enabledBidders
fe.impCountingMethod.index ^= 1
}

func (fe *feature) GetImpCountingMethodEnabledBidders() map[string]struct{} {
return fe.impCountingMethod.enabledBidders[fe.impCountingMethod.index]
}
Loading

0 comments on commit 0babd5d

Please sign in to comment.