Skip to content

Commit

Permalink
UOE-9681,UOE-9670: Add OWS hosted PBS vanilla endpoint, for prebid.js…
Browse files Browse the repository at this point in the history
… DIY client (#583)
  • Loading branch information
AvinashKapre authored Nov 7, 2023
1 parent f357d5f commit 32c62e1
Show file tree
Hide file tree
Showing 8 changed files with 598 additions and 51 deletions.
9 changes: 9 additions & 0 deletions modules/pubmatic/openwrap/auctionresponsehook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func (m OpenWrap) handleAuctionResponseHook(
result.DebugMessages = append(result.DebugMessages, "error: request-ctx not found in handleBeforeValidationHook()")
return result, nil
}

//SSHB request should not execute module
if rctx.Sshb == "1" || rctx.Endpoint == models.EndpointHybrid {
return result, nil
}
if rctx.Endpoint == models.EndpointOWS2S {
return result, nil
}

defer func() {
moduleCtx.ModuleContext["rctx"] = rctx
m.metricEngine.RecordPublisherResponseTimeStats(rctx.PubIDStr, int(time.Since(time.Unix(rctx.StartTime, 0)).Milliseconds()))
Expand Down
53 changes: 40 additions & 13 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/url"
"strconv"
"strings"

"github.com/buger/jsonparser"
"github.com/prebid/openrtb/v19/openrtb2"
Expand Down Expand Up @@ -46,6 +47,18 @@ func (m OpenWrap) handleBeforeValidationHook(
}
}()

//Do not execute the module for requests processed in SSHB(8001)
if rCtx.Sshb == "1" {
result.Reject = false
return result, nil
}

if rCtx.Endpoint == models.EndpointHybrid {
//TODO: Add bidder params fix
result.Reject = false
return result, nil
}

pubID, err := getPubID(*payload.BidRequest)
if err != nil {
result.NbrCode = nbr.InvalidPublisherID
Expand Down Expand Up @@ -154,6 +167,19 @@ func (m OpenWrap) handleBeforeValidationHook(
var isAdPodImpression bool
imp := payload.BidRequest.Imp[i]

impExt := &models.ImpExtension{}
if len(imp.Ext) != 0 {
err := json.Unmarshal(imp.Ext, impExt)
if err != nil {
result.NbrCode = nbr.InternalError
err = errors.New("failed to parse imp.ext: " + imp.ID)
result.Errors = append(result.Errors, err.Error())
return result, err
}
}
if rCtx.Endpoint == models.EndpointOWS2S {
imp.TagID = getTagID(imp, impExt)
}
if imp.TagID == "" {
result.NbrCode = nbr.InvalidImpressionTagID
err = errors.New("tagid missing for imp: " + imp.ID)
Expand Down Expand Up @@ -184,17 +210,6 @@ func (m OpenWrap) handleBeforeValidationHook(
}
}

impExt := &models.ImpExtension{}
if len(imp.Ext) != 0 {
err := json.Unmarshal(imp.Ext, impExt)
if err != nil {
result.NbrCode = nbr.InternalError
err = errors.New("failed to parse imp.ext: " + imp.ID)
result.Errors = append(result.Errors, err.Error())
return result, err
}
}

div := ""
if impExt.Wrapper != nil {
div = impExt.Wrapper.Div
Expand Down Expand Up @@ -439,7 +454,7 @@ func (m *OpenWrap) applyProfileChanges(rctx models.RequestCtx, bidRequest *openr
}

if cur, ok := rctx.PartnerConfigMap[models.VersionLevelConfigID][models.AdServerCurrency]; ok {
bidRequest.Cur = []string{cur}
bidRequest.Cur = append(bidRequest.Cur, cur)
}
if bidRequest.TMax == 0 {
bidRequest.TMax = rctx.TMax
Expand Down Expand Up @@ -797,7 +812,6 @@ func (m OpenWrap) setTimeout(rCtx models.RequestCtx) int64 {
// if ssauction flag is not set and platform is dislay, then by default send all bids
// if ssauction flag is not set and platform is in-app, then check if profile setting sendAllBids is set to 1
func isSendAllBids(rctx models.RequestCtx) bool {

//if ssauction is set to 0 in the request
if rctx.SSAuction == 0 {
return true
Expand Down Expand Up @@ -844,3 +858,16 @@ func getPubID(bidRequest openrtb2.BidRequest) (pubID int, err error) {
}
return pubID, err
}

func getTagID(imp openrtb2.Imp, impExt *models.ImpExtension) string {
//priority for tagId is imp.ext.gpid > imp.TagID > imp.ext.data.pbadslot
if impExt.Gpid != "" {
if idx := strings.Index(impExt.Gpid, "#"); idx != -1 {
return impExt.Gpid[:idx]
}
return impExt.Gpid
} else if imp.TagID != "" {
return imp.TagID
}
return impExt.Data.PbAdslot
}
Loading

0 comments on commit 32c62e1

Please sign in to comment.