Skip to content

Commit

Permalink
Rubicon: Support sending segments to XAPI (#1752)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Nahornyi <snahornyi@rubiconproject.com>
  • Loading branch information
SerhiiNahornyi and Serhii Nahornyi authored Mar 19, 2021
1 parent a04d5e1 commit c675c18
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 3 deletions.
46 changes: 46 additions & 0 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ type rubiconExtUserTpID struct {
UID string `json:"uid"`
}

type rubiconUserDataExt struct {
TaxonomyName string `json:"taxonomyname"`
}

type rubiconUserExt struct {
Consent string `json:"consent,omitempty"`
DigiTrust *openrtb_ext.ExtUserDigiTrust `json:"digitrust"`
Expand Down Expand Up @@ -752,6 +756,11 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
userCopy := *request.User
userExtRP := rubiconUserExt{RP: rubiconUserExtRP{Target: rubiconExt.Visitor}}

if err := updateUserExtWithIabAttribute(&userExtRP, userCopy.Data); err != nil {
errs = append(errs, err)
continue
}

if request.User.Ext != nil {
var userExt *openrtb_ext.ExtUser
if err = json.Unmarshal(userCopy.Ext, &userExt); err != nil {
Expand Down Expand Up @@ -886,6 +895,43 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adap
return requestData, errs
}

func updateUserExtWithIabAttribute(userExtRP *rubiconUserExt, data []openrtb.Data) error {
var segmentIdsToCopy = make([]string, 0)

for _, dataRecord := range data {
if dataRecord.Ext != nil {
var dataExtObject rubiconUserDataExt
err := json.Unmarshal(dataRecord.Ext, &dataExtObject)
if err != nil {
continue
}
if strings.EqualFold(dataExtObject.TaxonomyName, "iab") {
for _, segment := range dataRecord.Segment {
segmentIdsToCopy = append(segmentIdsToCopy, segment.ID)
}
}
}
}

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["iab"] = segmentIdsToCopy

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

return nil
}

func getTpIdsAndSegments(eids []openrtb_ext.ExtUserEid) (mappedRubiconUidsParam, []error) {
rubiconUidsParam := mappedRubiconUidsParam{
tpIds: make([]rubiconExtUserTpID, 0),
Expand Down
109 changes: 106 additions & 3 deletions adapters/rubicon/rubicontest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,52 @@
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"user": {
"data": [
{
"ext": {
"taxonomyname": "iab"
},
"segment": [
{
"id": "idToCopy"
}
]
},
{
"ext": {
"taxonomyname": "someValue"
},
"segment": [
{
"id": "shouldNotBeCopied"
}
]
},
{
"ext": {
"taxonomyname": "IaB"
},
"segment": [
{
"id": "idToCopy2"
}
]
},
{
"ext": {
"taxonomyname": [
"wrong iab type"
]
},
"segment": [
{
"id": "shouldNotBeCopied2"
}
]
}
]
},
"imp": [
{
"id": "test-imp-id",
Expand All @@ -30,8 +76,8 @@
"video": {
},
"accountId": 1001,
"siteId":113932,
"zoneId":535510
"siteId": 113932,
"zoneId": 535510
}
}
}
Expand All @@ -52,6 +98,63 @@
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
},
"user": {
"data": [
{
"ext": {
"taxonomyname": "iab"
},
"segment": [
{
"id": "idToCopy"
}
]
},
{
"ext": {
"taxonomyname": "someValue"
},
"segment": [
{
"id": "shouldNotBeCopied"
}
]
},
{
"ext": {
"taxonomyname": "IaB"
},
"segment": [
{
"id": "idToCopy2"
}
]
},
{
"ext": {
"taxonomyname": [
"wrong iab type"
]
},
"segment": [
{
"id": "shouldNotBeCopied2"
}
]
}
],
"ext": {
"digitrust": null,
"rp": {
"target": {
"iab": [
"idToCopy",
"idToCopy2"
]
}
}
}
},
"app": {
"id": "1",
"ext": {
Expand Down Expand Up @@ -91,7 +194,7 @@
},
"ext": {
"rp": {
"track":{
"track": {
"mint": "",
"mint_version": ""
},
Expand Down

0 comments on commit c675c18

Please sign in to comment.