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

Add mapping of user.ext.eids[] for LiveIntent in Rubicon bidder #1089

Merged
merged 8 commits into from
Dec 11, 2019
105 changes: 91 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,11 @@ 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...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably wanna add a continue after this line as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!

} else if err := updateUserExtWithTpIdsAndSegments(&userExtRP, tpIds, segments); err != nil {
errs = append(errs, err)
continue
}
}
}
Expand Down Expand Up @@ -746,6 +747,82 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
return requestData, errs
}

func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) ([]rubiconExtUserTpID, []string, []error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add test cases for this new method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added TestOpenRTBRequestWithSpecificExtUserEids(...) test.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, added TestOpenRTBRequestWithSpecificExtUserEids(...) test.

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