Skip to content

Commit

Permalink
Rubicon liveramp param (#1466)
Browse files Browse the repository at this point in the history
Add liveramp mapping to user.ext

should translate the "liveramp.com" id from the "user.ext.eids" array to "user.ext.liveramp_idl" as follows:

```
{
  "user": {
    "ext": {
      "eids": [{
        "source": 'liveramp.com',
        "uids": [{
          "id": "T7JiRRvsRAmh88"
        }]
      }]
    }
  }
}
```

 to XAPI:
```
{
  "user": {
    "ext": {
      "liveramp_idl": "T7JiRRvsRAmh88"
    }
  }
}
```
  • Loading branch information
DGarbar authored Sep 1, 2020
1 parent d8dc27f commit 412e0fc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
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
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

0 comments on commit 412e0fc

Please sign in to comment.