Skip to content

Commit

Permalink
Rubicon: Initial ORTB 2.6 support (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
CTMBNara authored Apr 10, 2023
1 parent 0087620 commit 4cb42fc
Show file tree
Hide file tree
Showing 4 changed files with 591 additions and 32 deletions.
141 changes: 110 additions & 31 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type rubiconExtImpBidder struct {
Prebid *openrtb_ext.ExtImpPrebid `json:"prebid"`
Bidder openrtb_ext.ExtImpRubicon `json:"bidder"`
Gpid string `json:"gpid"`
Skadn json.RawMessage `json:"skadn,omitempty"`
Data json.RawMessage `json:"data"`
Context rubiconContext `json:"context"`
}
Expand Down Expand Up @@ -77,8 +78,9 @@ type rubiconImpExtRPTrack struct {
}

type rubiconImpExt struct {
RP rubiconImpExtRP `json:"rp,omitempty"`
GPID string `json:"gpid,omitempty"`
RP rubiconImpExtRP `json:"rp,omitempty"`
GPID string `json:"gpid,omitempty"`
Skadn json.RawMessage `json:"skadn,omitempty"`
}

type rubiconImpExtRP struct {
Expand All @@ -96,11 +98,11 @@ type rubiconDataExt struct {
}

type rubiconUserExt struct {
Consent string `json:"consent,omitempty"`
Eids []openrtb2.EID `json:"eids,omitempty"`
RP rubiconUserExtRP `json:"rp"`
LiverampIdl string `json:"liveramp_idl,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Consent string `json:"consent,omitempty"`
}

type rubiconSiteExtRP struct {
Expand Down Expand Up @@ -231,6 +233,19 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
}

func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestCopy := request
if request.User != nil {
userCopy := *request.User
requestCopy.User = &userCopy
}

err := openrtb_ext.ConvertUpTo26(&openrtb_ext.RequestWrapper{BidRequest: requestCopy})
if err != nil {
return nil, []error{err}
}

request = requestCopy

numRequests := len(request.Imp)
requestData := make([]*adapters.RequestData, 0, numRequests)
headers := http.Header{}
Expand Down Expand Up @@ -268,7 +283,8 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
Target: target,
Track: rubiconImpExtRPTrack{Mint: "", MintVersion: ""},
},
GPID: bidderExt.Gpid,
GPID: bidderExt.Gpid,
Skadn: bidderExt.Skadn,
}

imp.Ext, err = json.Marshal(&impExt)
Expand Down Expand Up @@ -305,36 +321,30 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
userExtRP := rubiconUserExt{RP: rubiconUserExtRP{Target: target}}
userBuyerUID := userCopy.BuyerUID

if request.User.Ext != nil {
var userExt *openrtb_ext.ExtUser
if err = json.Unmarshal(userCopy.Ext, &userExt); err != nil {
errs = append(errs, &errortypes.BadInput{
Message: err.Error(),
})
continue
if len(userCopy.EIDs) > 0 {
userExtRP.Eids = userCopy.EIDs

if userBuyerUID == "" {
userBuyerUID = extractUserBuyerUID(userExtRP.Eids)
}
userExtRP.Consent = userExt.Consent
userExtRP.Eids = userExt.Eids

// set user.ext.tpid
if len(userExt.Eids) > 0 {
if userBuyerUID == "" {
userBuyerUID = extractUserBuyerUID(userExt.Eids)
}
mappedRubiconUidsParam, errors := getSegments(userExtRP.Eids)
if len(errors) > 0 {
errs = append(errs, errors...)
continue
}

mappedRubiconUidsParam, errors := getSegments(userExt.Eids)
if len(errors) > 0 {
errs = append(errs, errors...)
continue
}
if err := updateUserExtWithSegments(&userExtRP, mappedRubiconUidsParam); err != nil {
errs = append(errs, err)
continue
}

if err := updateUserExtWithSegments(&userExtRP, mappedRubiconUidsParam); err != nil {
errs = append(errs, err)
continue
}
userExtRP.LiverampIdl = mappedRubiconUidsParam.liverampIdl
}

userExtRP.LiverampIdl = mappedRubiconUidsParam.liverampIdl
}
if userCopy.Consent != "" {
userExtRP.Consent = userCopy.Consent
userCopy.Consent = ""
}

userCopy.Ext, err = json.Marshal(&userExtRP)
Expand All @@ -346,6 +356,7 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
userCopy.Yob = 0
userCopy.Gender = ""
userCopy.BuyerUID = userBuyerUID
userCopy.EIDs = nil

rubiconRequest.User = &userCopy
}
Expand Down Expand Up @@ -373,10 +384,11 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
videoSizeId = resolvedSizeId
}

// if imp.ext.is_rewarded_inventory = 1, set imp.video.ext.videotype = "rewarded"
// if imp.rwdd = 1, set imp.video.ext.videotype = "rewarded"
var videoType = ""
if bidderExt.Prebid != nil && bidderExt.Prebid.IsRewardedInventory != nil && *bidderExt.Prebid.IsRewardedInventory == 1 {
if imp.Rwdd == 1 {
videoType = "rewarded"
imp.Rwdd = 0
}
videoExt := rubiconVideoExt{Skip: rubiconExt.Video.Skip, SkipDelay: rubiconExt.Video.SkipDelay, VideoType: videoType, RP: rubiconVideoExtRP{SizeID: videoSizeId}}
videoCopy.Ext, err = json.Marshal(&videoExt)
Expand Down Expand Up @@ -452,6 +464,73 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
rubiconRequest.App = &appCopy
}

if request.Source != nil || rubiconExt.PChain != "" {
var sourceCopy openrtb2.Source
if request.Source != nil {
sourceCopy = *request.Source
} else {
sourceCopy = openrtb2.Source{}
}

if sourceCopy.SChain != nil {
var sourceCopyExt openrtb_ext.ExtSource
if sourceCopy.Ext != nil {
if err = json.Unmarshal(sourceCopy.Ext, &sourceCopyExt); err != nil {
errs = append(errs, &errortypes.BadInput{Message: err.Error()})
continue
}
} else {
sourceCopyExt = openrtb_ext.ExtSource{}
}

sourceCopyExt.SChain = sourceCopy.SChain
sourceCopy.SChain = nil

sourceCopy.Ext, err = json.Marshal(&sourceCopyExt)
if err != nil {
errs = append(errs, err)
continue
}
}

if rubiconExt.PChain != "" {
sourceCopy.PChain = rubiconExt.PChain
}

rubiconRequest.Source = &sourceCopy
}

if request.Regs != nil && (request.Regs.GDPR != nil || request.Regs.USPrivacy != "") {
regsCopy := *request.Regs

var regsCopyExt openrtb_ext.ExtRegs
if regsCopy.Ext != nil {
if err = json.Unmarshal(regsCopy.Ext, &regsCopyExt); err != nil {
errs = append(errs, &errortypes.BadInput{Message: err.Error()})
continue
}
} else {
regsCopyExt = openrtb_ext.ExtRegs{}
}

if regsCopy.GDPR != nil {
regsCopyExt.GDPR = regsCopy.GDPR
}
if regsCopy.USPrivacy != "" {
regsCopyExt.USPrivacy = regsCopy.USPrivacy
}

regsCopy.Ext, err = json.Marshal(&regsCopyExt)
if err != nil {
errs = append(errs, err)
continue
}
regsCopy.GDPR = nil
regsCopy.USPrivacy = ""

rubiconRequest.Regs = &regsCopy
}

reqBadv := request.BAdv
if reqBadv != nil {
if len(reqBadv) > badvLimitSize {
Expand Down
Loading

0 comments on commit 4cb42fc

Please sign in to comment.