-
Notifications
You must be signed in to change notification settings - Fork 748
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
Changes from 3 commits
0e104a0
7143f2f
0ec2adc
a469a33
1406caf
9da401f
ed5a47f
f820b5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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...) | ||
} else if err := updateUserExtWithTpIdsAndSegments(&userExtRP, tpIds, segments); err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
} | ||
} | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add test cases for this new method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, added |
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this one too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, added |
||
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 { | ||
|
There was a problem hiding this comment.
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 wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks!