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

Rubicon liveramp param #1466

Merged
merged 2 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ type rubiconExtUserTpID struct {
}

type rubiconUserExt struct {
Consent string `json:"consent,omitempty"`
DigiTrust *openrtb_ext.ExtUserDigiTrust `json:"digitrust"`
Eids []openrtb_ext.ExtUserEid `json:"eids,omitempty"`
TpID []rubiconExtUserTpID `json:"tpid,omitempty"`
RP rubiconUserExtRP `json:"rp"`
Consent string `json:"consent,omitempty"`
DigiTrust *openrtb_ext.ExtUserDigiTrust `json:"digitrust"`
Eids []openrtb_ext.ExtUserEid `json:"eids,omitempty"`
TpID []rubiconExtUserTpID `json:"tpid,omitempty"`
RP rubiconUserExtRP `json:"rp"`
LiverampIdl string `json:"liveramp_idl,omitempty"`
}

type rubiconSiteExtRP struct {
Expand Down Expand Up @@ -247,6 +248,12 @@ type rubiconUserExtEidUidExt struct {
RtiPartner string `json:"rtiPartner,omitempty"`
}

type mappedRubiconUidsParam struct {
tpIds []rubiconExtUserTpID
Copy link
Contributor

Choose a reason for hiding this comment

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

Does tp = third party? If so, please consider naming the thirdPartyIDs for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SyntaxNode
This name is already self-completed. It is used in Rubicon Bidder and (for my knowledge) does not mean thirdParty.
Thanks for proposal

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright.

segments []string
liverampIdl string
}

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

// set user.ext.tpid
if len(userExt.Eids) > 0 {
if tpIds, segments, errors := getTpIdsAndSegments(userExt.Eids); len(errors) > 0 {
mappedRubiconUidsParam, errors := getTpIdsAndSegments(userExt.Eids)
if len(errors) > 0 {
errs = append(errs, errors...)
continue
} else if err := updateUserExtWithTpIdsAndSegments(&userExtRP, tpIds, segments); err != nil {
}

if err := updateUserExtWithTpIdsAndSegments(&userExtRP, mappedRubiconUidsParam); err != nil {
errs = append(errs, err)
continue
}

userExtRP.LiverampIdl = mappedRubiconUidsParam.liverampIdl
}
}

Expand Down Expand Up @@ -793,9 +805,11 @@ 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)
func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) (mappedRubiconUidsParam, []error) {
rubiconUidsParam := mappedRubiconUidsParam{
tpIds: make([]rubiconExtUserTpID, 0),
segments: make([]string, 0),
}
errs := make([]error, 0)

for _, eid := range eids {
Expand All @@ -815,7 +829,7 @@ func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) ([]rubiconExtUserTpID, [
}

if eidUidExt.RtiPartner == "TDID" {
tpIds = append(tpIds, rubiconExtUserTpID{Source: "tdid", UID: uid.ID})
rubiconUidsParam.tpIds = append(rubiconUidsParam.tpIds, rubiconExtUserTpID{Source: "tdid", UID: uid.ID})
}
}
}
Expand All @@ -824,7 +838,7 @@ func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) ([]rubiconExtUserTpID, [
if len(uids) > 0 {
uidId := uids[0].ID
if uidId != "" {
tpIds = append(tpIds, rubiconExtUserTpID{Source: "liveintent.com", UID: uidId})
rubiconUidsParam.tpIds = append(rubiconUidsParam.tpIds, rubiconExtUserTpID{Source: "liveintent.com", UID: uidId})
}

if eid.Ext != nil {
Expand All @@ -835,20 +849,28 @@ func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) ([]rubiconExtUserTpID, [
})
continue
}
segments = eidExt.Segments
rubiconUidsParam.segments = eidExt.Segments
}
}
case "liveramp.com":
uids := eid.Uids
if len(uids) > 0 {
uidId := uids[0].ID
if uidId != "" && rubiconUidsParam.liverampIdl == "" {
rubiconUidsParam.liverampIdl = uidId
}
}
}
}

return tpIds, segments, errs
return rubiconUidsParam, errs
}

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

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

if userExtRP.RP.Target != nil {
Expand All @@ -857,7 +879,7 @@ func updateUserExtWithTpIdsAndSegments(userExtRP *rubiconUserExt, tpIds []rubico
}
}

userExtRPTarget["LIseg"] = segments
userExtRPTarget["LIseg"] = rubiconUidsParam.segments

if target, err := json.Marshal(&userExtRPTarget); err != nil {
return &errortypes.BadInput{Message: err.Error()}
Expand Down
14 changes: 13 additions & 1 deletion adapters/rubicon/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,15 @@ func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) {
"ext": {
"segments": ["999","888"]
}
},
{
"source": "liveramp.com",
"uids": [{
"id": "LIVERAMPID"
}],
"ext": {
"segments": ["111","222"]
}
}
]}`),
},
Expand All @@ -1239,7 +1248,7 @@ func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) {
}

assert.NotNil(t, userExt.Eids)
assert.Equal(t, 3, len(userExt.Eids), "Eids values are not as expected!")
assert.Equal(t, 4, len(userExt.Eids), "Eids values are not as expected!")

assert.NotNil(t, userExt.TpID)
assert.Equal(t, 2, len(userExt.TpID), "TpID values are not as expected!")
Expand All @@ -1250,6 +1259,9 @@ func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) {
// liveintent.com
assert.Equal(t, "liveintent.com", userExt.TpID[1].Source, "TpID source value is not as expected!")

// liveramp.com
assert.Equal(t, "LIVERAMPID", userExt.LiverampIdl, "Liveramp_idl value is not as expected!")

userExtRPTarget := make(map[string]interface{})
if err := json.Unmarshal(userExt.RP.Target, &userExtRPTarget); err != nil {
t.Fatal("Error unmarshalling request.user.ext.rp.target object.")
Expand Down