Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Add mapping of user.ext.eids[] for LiveIntent in Rubicon bidder (preb…
Browse files Browse the repository at this point in the history
  • Loading branch information
rpanchyk authored and SyntaxNode committed Dec 11, 2019
1 parent d2845de commit 4baba86
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 341 deletions.
106 changes: 92 additions & 14 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ var rubiSizeMap = map[rubiSize]int{
{w: 640, h: 320}: 156,
}

// defines the contract for bidrequest.user.ext.eids[i].ext
type rubiconUserExtEidExt struct {
Segments []string `json:"segments,omitempty"`
}

// defines the contract for bidrequest.user.ext.eids[i].uids[j].ext
type rubiconUserExtEidUidExt struct {
RtiPartner string `json:"rtiPartner,omitempty"`
}

//MAS algorithm
func findPrimary(alt []int) (int, []int) {
min, pos, primary := 0, 0, 0
Expand Down Expand Up @@ -648,20 +658,12 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap

// set user.ext.tpid
if len(userExt.Eids) > 0 {
tpIds := make([]rubiconExtUserTpID, 0)
for _, eid := range userExt.Eids {
if eid.Source == "adserver.org" {
uids := eid.Uids
if len(uids) > 0 {
uid := uids[0]
if uid.Ext != nil && uid.Ext.RtiPartner == "TDID" {
tpIds = append(tpIds, rubiconExtUserTpID{Source: "tdid", UID: uid.ID})
}
}
}
}
if len(tpIds) > 0 {
userExtRP.TpID = tpIds
if tpIds, segments, errors := getTpIdsAndSegments(userExt.Eids); len(errors) > 0 {
errs = append(errs, errors...)
continue
} else if err := updateUserExtWithTpIdsAndSegments(&userExtRP, tpIds, segments); err != nil {
errs = append(errs, err)
continue
}
}
}
Expand Down Expand Up @@ -746,6 +748,82 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
return requestData, errs
}

func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) ([]rubiconExtUserTpID, []string, []error) {
tpIds := make([]rubiconExtUserTpID, 0)
segments := make([]string, 0)
errs := make([]error, 0)

for _, eid := range eids {
switch eid.Source {
case "adserver.org":
uids := eid.Uids
if len(uids) > 0 {
uid := uids[0]

if uid.Ext != nil {
var eidUidExt rubiconUserExtEidUidExt
if err := json.Unmarshal(uid.Ext, &eidUidExt); err != nil {
errs = append(errs, &errortypes.BadInput{
Message: err.Error(),
})
continue
}

if eidUidExt.RtiPartner == "TDID" {
tpIds = append(tpIds, rubiconExtUserTpID{Source: "tdid", UID: uid.ID})
}
}
}
case "liveintent.com":
uids := eid.Uids
if len(uids) > 0 {
uidId := uids[0].ID
if uidId != "" {
tpIds = append(tpIds, rubiconExtUserTpID{Source: "liveintent.com", UID: uidId})
}

if eid.Ext != nil {
var eidExt rubiconUserExtEidExt
if err := json.Unmarshal(eid.Ext, &eidExt); err != nil {
errs = append(errs, &errortypes.BadInput{
Message: err.Error(),
})
continue
}
segments = eidExt.Segments
}
}
}
}

return tpIds, segments, errs
}

func updateUserExtWithTpIdsAndSegments(userExtRP *rubiconUserExt, tpIds []rubiconExtUserTpID, segments []string) error {
if len(tpIds) > 0 {
userExtRP.TpID = tpIds

if segments != nil {
userExtRPTarget := make(map[string]interface{})

if userExtRP.RP.Target != nil {
if err := json.Unmarshal(userExtRP.RP.Target, &userExtRPTarget); err != nil {
return &errortypes.BadInput{Message: err.Error()}
}
}

userExtRPTarget["LIseg"] = segments

if target, err := json.Marshal(&userExtRPTarget); err != nil {
return &errortypes.BadInput{Message: err.Error()}
} else {
userExtRP.RP.Target = target
}
}
}
return nil
}

func isVideo(imp openrtb.Imp) bool {
video := imp.Video
if video != nil {
Expand Down
Loading

0 comments on commit 4baba86

Please sign in to comment.