Skip to content

Commit

Permalink
UOE-11098: Pass user.ext.sessionduration and user.ext.impdepth ORTB r…
Browse files Browse the repository at this point in the history
…equest to OW partners (#922)
  • Loading branch information
Pubmatic-Supriya-Patil authored Oct 9, 2024
1 parent c8c0012 commit 47cef0e
Show file tree
Hide file tree
Showing 12 changed files with 551 additions and 194 deletions.
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/applovinmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func updateUser(signalUser *openrtb2.User, maxRequest *openrtb2.BidRequest) {
}

maxRequest.User.Data = signalUser.Data
maxRequest.User.Ext = setIfKeysExists(signalUser.Ext, maxRequest.User.Ext, "consent", "eids")
maxRequest.User.Ext = setIfKeysExists(signalUser.Ext, maxRequest.User.Ext, "consent", "eids", "sessionduration", "impdepth")
}

func setIfKeysExists(source []byte, target []byte, keys ...string) []byte {
Expand Down
32 changes: 32 additions & 0 deletions modules/pubmatic/openwrap/applovinmax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,38 @@ func TestUpdateUser(t *testing.T) {
},
want: &openrtb2.User{ID: "maxID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"consent":"consent_string","eids":[{"source":"amxid","uids":[{"atype":1,"id":"88de601e-3d98-48e7-81d7-00000000"}]},{"source":"adserver.org","uids":[{"id":"1234567","ext":{"rtiPartner":"TDID"}}]}]}`)},
},
{
name: "signalUserExt has sessionduration and impdepth",
args: args{
signalUser: &openrtb2.User{ID: "sdkID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"sessionduration":40,"impdepth":10}`)},
maxRequest: &openrtb2.BidRequest{User: &openrtb2.User{ID: "maxID", Yob: 2000, Gender: "F", Keywords: "k52=v43"}},
},
want: &openrtb2.User{ID: "maxID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"sessionduration":40,"impdepth":10}`)},
},
{
name: "signalUserExt has invalid sessionduration and impdepth",
args: args{
signalUser: &openrtb2.User{ID: "sdkID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"sessionduration":"sessionduration","impdepth":"impdepth"}`)},
maxRequest: &openrtb2.BidRequest{User: &openrtb2.User{ID: "maxID", Yob: 2000, Gender: "F", Keywords: "k52=v43"}},
},
want: &openrtb2.User{ID: "maxID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"sessionduration":"sessionduration","impdepth":"impdepth"}`)},
},
{
name: "signalUserExt has sessionduration",
args: args{
signalUser: &openrtb2.User{ID: "sdkID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"sessionduration":40}`)},
maxRequest: &openrtb2.BidRequest{User: &openrtb2.User{ID: "maxID", Yob: 2000, Gender: "F", Keywords: "k52=v43"}},
},
want: &openrtb2.User{ID: "maxID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"sessionduration":40}`)},
},
{
name: "signalUserExt has impdepth",
args: args{
signalUser: &openrtb2.User{ID: "sdkID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"impdepth":10}`)},
maxRequest: &openrtb2.BidRequest{User: &openrtb2.User{ID: "maxID", Yob: 2000, Gender: "F", Keywords: "k52=v43"}},
},
want: &openrtb2.User{ID: "maxID", Yob: 1999, Gender: "M", Keywords: "k1=v2;k2=v2", Ext: json.RawMessage(`{"impdepth":10}`)},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ func (m *OpenWrap) applyProfileChanges(rctx models.RequestCtx, bidRequest *openr
if bidRequest.User.CustomData == "" && rctx.KADUSERCookie != nil {
bidRequest.User.CustomData = rctx.KADUSERCookie.Value
}
ctv.UpdateUserEidsWithValidValues(bidRequest.User)
UpdateUserExtWithValidValues(bidRequest.User)

for i := 0; i < len(bidRequest.WLang); i++ {
bidRequest.WLang[i] = getValidLanguage(bidRequest.WLang[i])
Expand Down
12 changes: 8 additions & 4 deletions modules/pubmatic/openwrap/endpoints/legacy/ctv/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,12 @@ const (
ORTBUserGeoUtcOffset = "user.geo.utcoffset" //ORTBUserGeoUtcOffset get api parameter user.geo.utcoffset

// User.Ext.Consent level parameters
ORTBUserExtConsent = "user.ext.consent" //ORTBUserExtConsent get api parameter user.ext.consent
ORTBUserExtEIDS = "user.ext.eids" //ORTBUserExtEIDS get api parameter user.ext.eids
ORTBUserData = "user.data" //ORTBUserData get api parameter user.data
ORTBExtEIDS = "eids" //ORTBExtEIDS parameter
ORTBUserExtConsent = "user.ext.consent" //ORTBUserExtConsent get api parameter user.ext.consent
ORTBUserExtEIDS = "user.ext.eids" //ORTBUserExtEIDS get api parameter user.ext.eids
ORTBUserExtSessionDuration = "user.ext.sessionduration" //ORTBUserExtSessionDuration get api parameter user.ext.sessionduration
ORTBUserExtImpDepth = "user.ext.impdepth" //ORTBUserExtImpDepth get api parameter user.ext.impdepth
ORTBUserData = "user.data" //ORTBUserData get api parameter user.data
ORTBExtEIDS = "eids" //ORTBExtEIDS parameter

// Regs.Ext.GDPR level parameters
ORTBRegsExtGdpr = "regs.ext.gdpr" //ORTBRegsExtGdpr get api parameter regs.ext.gdpr
Expand Down Expand Up @@ -350,6 +352,8 @@ const (
ORTBUserGeoExt = "user.geo.ext" //ORTBUserGeoExt get api parameter user.geo.ext
ORTBUserExtUIDS = "uids" //ORTBUserExtUIDs get api parameter user.ext.eids.uids
ORTBUserExtID = "id" //ORTBUserExtID get api parameter user.ext.eids.uids.id
ORTBExtSessionDuration = "sessionduration" //ORTBUserExtSessionDuration get api parameter user.ext.sessionduration
ORTBExtImpDepth = "impdepth" //ORTBUserExtImpDepth get api parameter user.ext.impdepth

// ORTB Extension Standard Keys */ //// get api parameter xtension Standard Klevel parameters
ORTBExtWrapper = "wrapper" //ORTBExtWrapper get api parameter wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"

"git.pubmatic.com/PubMatic/go-common/logger"
"github.com/golang/glog"
"github.com/prebid/openrtb/v20/adcom1"
"github.com/prebid/openrtb/v20/openrtb2"
Expand Down Expand Up @@ -4506,6 +4508,70 @@ func (o *OpenRTB) ORTBUserExtEIDS() (err error) {
return
}

// ORTBUserExtSessionDuration will read and set ortb User.Ext.sessionduration parameter
func (o *OpenRTB) ORTBUserExtSessionDuration() (err error) {
valStr, ok := o.values.GetString(ORTBUserExtSessionDuration)
if !ok || valStr == "" {
return
}
if o.ortb.User == nil {
o.ortb.User = &openrtb2.User{}
}
userExt := map[string]interface{}{}
if o.ortb.User.Ext != nil {
if err = json.Unmarshal(o.ortb.User.Ext, &userExt); err != nil {
return
}
}

val, err := strconv.ParseUint(valStr, 10, 64)
if err != nil {
logger.Warn("Invalid session duration value '%v': %v", valStr, err)
return nil
}
userExt[ORTBExtSessionDuration] = int64(val)

data, err := json.Marshal(userExt)
if err != nil {
return
}

o.ortb.User.Ext = data
return
}

// ORTBUserExtImpDepth will read and set ortb User.Ext.impdepth parameter
func (o *OpenRTB) ORTBUserExtImpDepth() (err error) {
valStr, ok := o.values.GetString(ORTBUserExtImpDepth)
if !ok || valStr == "" {
return
}
if o.ortb.User == nil {
o.ortb.User = &openrtb2.User{}
}
userExt := map[string]interface{}{}
if o.ortb.User.Ext != nil {
if err = json.Unmarshal(o.ortb.User.Ext, &userExt); err != nil {
return
}
}

val, err := strconv.ParseUint(valStr, 10, 64)
if err != nil {
logger.Warn("Invalid imp depth value '%v': %v", valStr, err)
return nil
}
userExt[ORTBExtImpDepth] = int64(val)

data, err := json.Marshal(userExt)
if err != nil {
return
}

o.ortb.User.Ext = data
return
}

// ORTBUserData will read and set ortb user.data parameter
func (o *OpenRTB) ORTBUserData() (err error) {
dataValue, ok := o.values.GetString(ORTBUserData)
Expand Down
Loading

0 comments on commit 47cef0e

Please sign in to comment.