Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RE-4009: Release 14/01/2025 #993

Merged
merged 6 commits into from
Jan 9, 2025
Merged
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
43 changes: 24 additions & 19 deletions analytics/pubmatic/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,30 @@ func getPartnerRecordsByImp(ao analytics.AuctionObject, rCtx *models.RequestCtx)
}

pr := PartnerRecord{
PartnerID: partnerID, // prebid biddercode
BidderCode: seat, // pubmatic biddercode: pubmatic2
Latency1: rCtx.BidderResponseTimeMillis[seat], // it is set inside auctionresponsehook for all bidders
KGPV: kgpv,
KGPSV: kgpsv,
BidID: utils.GetOriginalBidId(bid.ID),
OrigBidID: utils.GetOriginalBidId(bid.ID),
DefaultBidStatus: 0, // this will be always 0 , decide whether to drop this field in future
ServerSide: 1,
MatchedImpression: rCtx.MatchedImpression[seat],
OriginalCPM: models.GetGrossEcpm(bidExt.OriginalBidCPM),
OriginalCur: bidExt.OriginalBidCur,
DealID: bid.DealID,
Nbr: nbr,
Adformat: adFormat,
NetECPM: tracker.Tracker.PartnerInfo.NetECPM,
GrossECPM: tracker.Tracker.PartnerInfo.GrossECPM,
PartnerSize: tracker.Tracker.PartnerInfo.AdSize,
ADomain: tracker.Tracker.PartnerInfo.Advertiser,
PartnerID: partnerID, // prebid biddercode
BidderCode: seat, // pubmatic biddercode: pubmatic2
Latency1: rCtx.BidderResponseTimeMillis[seat], // it is set inside auctionresponsehook for all bidders
KGPV: kgpv,
KGPSV: kgpsv,
BidID: utils.GetOriginalBidId(bid.ID),
OrigBidID: utils.GetOriginalBidId(bid.ID),
DefaultBidStatus: 0, // this will be always 0 , decide whether to drop this field in future
ServerSide: 1,
MatchedImpression: rCtx.MatchedImpression[seat],
OriginalCPM: models.GetGrossEcpm(bidExt.OriginalBidCPM),
OriginalCur: bidExt.OriginalBidCur,
DealID: bid.DealID,
Nbr: nbr,
Adformat: adFormat,
NetECPM: tracker.Tracker.PartnerInfo.NetECPM,
GrossECPM: tracker.Tracker.PartnerInfo.GrossECPM,
PartnerSize: tracker.Tracker.PartnerInfo.AdSize,
ADomain: tracker.Tracker.PartnerInfo.Advertiser,
MultiBidMultiFloorFlag: tracker.Tracker.PartnerInfo.MultiBidMultiFloorFlag,
}

if pr.MultiBidMultiFloorFlag == 0 && bidExt.MultiBidMultiFloorValue > 0 {
pr.MultiBidMultiFloorFlag = 1
}

if pr.NetECPM == 0 {
Expand Down
55 changes: 29 additions & 26 deletions analytics/pubmatic/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,16 @@ func TestGetPartnerRecordsByImpForTracker(t *testing.T) {
"bid-id-1": {
Tracker: models.Tracker{
PartnerInfo: models.Partner{
Adformat: models.Native,
KGPV: "kgpv",
NetECPM: 10,
GrossECPM: 12,
AdSize: "15x15",
FloorValue: 1,
FloorRuleValue: 2,
Advertiser: "sony.com",
PriceBucket: "10.00",
Adformat: models.Native,
KGPV: "kgpv",
NetECPM: 10,
GrossECPM: 12,
AdSize: "15x15",
FloorValue: 1,
FloorRuleValue: 2,
Advertiser: "sony.com",
PriceBucket: "10.00",
MultiBidMultiFloorFlag: 1,
},
LoggerData: models.LoggerData{
KGPSV: "kgpsv",
Expand All @@ -728,23 +729,24 @@ func TestGetPartnerRecordsByImpForTracker(t *testing.T) {
partners: map[string][]PartnerRecord{
"imp1": {
{
PartnerID: "pubmatic",
BidderCode: "pubmatic",
PartnerSize: "15x15",
BidID: "bid-id-1",
OrigBidID: "bid-id-1",
DealID: "-1",
ServerSide: 1,
OriginalCur: "USD",
Adformat: models.Native,
NetECPM: 10,
GrossECPM: 12,
FloorValue: 1,
FloorRuleValue: 2,
ADomain: "sony.com",
KGPV: "kgpv",
KGPSV: "kgpsv",
PriceBucket: "10.00",
PartnerID: "pubmatic",
BidderCode: "pubmatic",
PartnerSize: "15x15",
BidID: "bid-id-1",
OrigBidID: "bid-id-1",
DealID: "-1",
ServerSide: 1,
OriginalCur: "USD",
Adformat: models.Native,
NetECPM: 10,
GrossECPM: 12,
FloorValue: 1,
FloorRuleValue: 2,
ADomain: "sony.com",
KGPV: "kgpv",
KGPSV: "kgpsv",
PriceBucket: "10.00",
MultiBidMultiFloorFlag: 1,
},
},
},
Expand Down Expand Up @@ -1029,6 +1031,7 @@ func TestGetPartnerRecordsByImpForDefaultBids(t *testing.T) {
},
},
},
TagID: "adunit_1234",
},
},
},
Expand Down
9 changes: 5 additions & 4 deletions analytics/pubmatic/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ type PartnerRecord struct {
OriginalCur string `json:"ocry"`
MetaData *MetaData `json:"md,omitempty"`

FloorValue float64 `json:"fv,omitempty"`
FloorRuleValue float64 `json:"frv,omitempty"`
Nbr *openrtb3.NoBidReason `json:"nbr,omitempty"` // NonBR reason code
PriceBucket string `json:"pb,omitempty"`
FloorValue float64 `json:"fv,omitempty"`
FloorRuleValue float64 `json:"frv,omitempty"`
Nbr *openrtb3.NoBidReason `json:"nbr,omitempty"` // NonBR reason code
PriceBucket string `json:"pb,omitempty"`
MultiBidMultiFloorFlag int `json:"mbmf,omitempty"`
}

type MetaData struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ require (
git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3
git.pubmatic.com/vastunwrap v0.0.0-00010101000000-000000000000
github.com/PubMatic-OpenWrap/fastxml v0.0.0-20241125102315-0d8f851a6e52
github.com/beevik/etree/110 v0.0.0-00010101000000-000000000000
github.com/diegoholiveira/jsonlogic/v3 v3.5.3
github.com/go-sql-driver/mysql v1.7.1
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -89,6 +88,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
35 changes: 28 additions & 7 deletions modules/pubmatic/openwrap/adapters/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,18 @@ func builderSmaato(params BidderParameters) (json.RawMessage, error) {
jsonStr := bytes.Buffer{}
jsonStr.WriteByte('{')

if publisherID, ok := getString(params.FieldMap["publisherId"]); !ok {
publisherID, ok := getString(params.FieldMap["publisherId"])
if !ok {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, "publisherId")
} else {
fmt.Fprintf(&jsonStr, `"publisherId":"%s",`, publisherID)
}
fmt.Fprintf(&jsonStr, `"publisherId":"%s"`, publisherID)

if adspaceID, ok := getString(params.FieldMap["adspaceId"]); ok {
fmt.Fprintf(&jsonStr, `,"adspaceId":"%s"`, adspaceID)
}

if adspaceID, ok := getString(params.FieldMap["adspaceId"]); !ok {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, "adspaceId")
} else {
fmt.Fprintf(&jsonStr, `"adspaceId":"%s"`, adspaceID)
if adbreakID, ok := getString(params.FieldMap["adbreakId"]); ok {
fmt.Fprintf(&jsonStr, `,"adbreakId":"%s"`, adbreakID)
}

jsonStr.WriteByte('}')
Expand Down Expand Up @@ -730,3 +732,22 @@ func builderAidem(params BidderParameters) (json.RawMessage, error) {

return jsonStr.Bytes(), nil
}

func builderCompass(params BidderParameters) (json.RawMessage, error) {
jsonStr := bytes.Buffer{}
jsonStr.WriteByte('{')
oneOf := []string{"placementId", "endpointId"}
for _, param := range oneOf {
if key, ok := getString(params.FieldMap[param]); ok {
fmt.Fprintf(&jsonStr, `"%s":"%s"`, param, key)
break
}
}
// len=0 (no mandatory params present)
if jsonStr.Len() == 1 {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, oneOf)
}

jsonStr.WriteByte('}')
return jsonStr.Bytes(), nil
}
126 changes: 118 additions & 8 deletions modules/pubmatic/openwrap/adapters/bidders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,19 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
args args
want json.RawMessage
}{
{
name: "all_missing",
args: args{
reqID: "",
width: nil,
height: nil,
fieldMap: map[string]interface{}{},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
},
{
name: "publisherId missing",
args: args{
Expand All @@ -2009,6 +2022,7 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
height: nil,
fieldMap: map[string]interface{}{
"adspaceId": "1234",
"adbreakId": "4567",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
Expand All @@ -2029,23 +2043,25 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
want: json.RawMessage(`{"publisherId": "1234"}`),
},
{
name: "publisherId & adspaceId both are missing",
name: "adbreakId missing",
args: args{
reqID: "",
width: nil,
height: nil,
fieldMap: map[string]interface{}{},

width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
want: json.RawMessage(`{"publisherId": "1234"}`),
},
{
name: "All params are present",
name: "publisherId_adspaceId__present",
args: args{

width: nil,
Expand All @@ -2060,6 +2076,53 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
},
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456"}`),
},
{
name: "publisherId_adbreakId__present",
args: args{

width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
"adbreakId": "3456",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: json.RawMessage(`{"publisherId": "1234","adbreakId": "3456"}`),
},
{
name: "adspaceId_and_adbreakId_present",
args: args{
width: nil,
height: nil,
fieldMap: map[string]interface{}{
"adspaceId": "1234",
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
},
{
name: "all_params_are_present",
args: args{
width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
"adspaceId": "3456",
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456","adbreakId": "7899"}`),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -3119,3 +3182,50 @@ func Test_builderAidem(t *testing.T) {
})
}
}

func TestBuilderCompass(t *testing.T) {
type args struct {
params BidderParameters
}
tests := []struct {
name string
args args
want json.RawMessage
wantErr bool
}{
{
name: "Valid Scenerio (oneOf placementId or endpointId) is present-placementId",
args: args{params: BidderParameters{FieldMap: JSONObject{"placementId": "dbdsfh"}}},
want: json.RawMessage(`{"placementId": "dbdsfh"}`),
wantErr: false,
},
{
name: "Valid Scenerio (oneOf placementId or endpointId) is present-endpointId",
args: args{params: BidderParameters{FieldMap: JSONObject{"endpointId": "dbdsfh"}}},
want: json.RawMessage(`{"endpointId": "dbdsfh"}`),
wantErr: false,
},
{
name: "Valid Scenerio (oneOf placementId or endpointId), Both are present",
args: args{params: BidderParameters{FieldMap: JSONObject{"placementId": "sdhks", "endpointId": "sdjksd"}}},
want: json.RawMessage(`{"placementId": "sdhks"}`),
wantErr: false,
},
{
name: "Invalid Scenerio (None Of placementId or endpointId) is present",
args: args{params: BidderParameters{FieldMap: JSONObject{}}},
want: json.RawMessage(``),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := builderCompass(tt.args.params)
if (err != nil) != tt.wantErr {
t.Errorf("builderCompass() error = %v, wantErr %v", err, tt.wantErr)
return
}
AssertJSON(t, tt.want, got)
})
}
}
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/adapters/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func initBidderBuilderFactory() {
string(openrtb_ext.BidderKargo): builderKargo,
string(openrtb_ext.BidderPGAMSsp): builderPGAMSSP,
string(openrtb_ext.BidderAidem): builderAidem,
string(openrtb_ext.BidderCompass): builderCompass,
}
}

Expand Down
Loading
Loading