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: Support sending segments to XAPI #1752

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
73 changes: 73 additions & 0 deletions adapters/rubicon/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,79 @@ func TestOpenRTBRequestWithSpecificExtUserEids(t *testing.T) {
assert.Contains(t, userExtRPTarget["LIseg"], "999", "No segment with 999 as expected!")
}

func TestOpenRTBRequestWithTaxonomynameAttribute(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you updated the simple-video.json test to include this new logic. Is this TestOpenRTBRequestWithTaxonomynameAttribute test a duplicate, essentially?

Copy link
Contributor Author

@SerhiiNahornyi SerhiiNahornyi Mar 17, 2021

Choose a reason for hiding this comment

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

@SyntaxNode Yes, actually I don't believe even unit tests, so also updated json test, should this update from simple-video.json be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just care about the json test. The assertions for the json test framework will soon include memory protection checks as a replacement for the near-useless race condition checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not clearly understand, what should I do?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please delete the TestOpenRTBRequestWithTaxonomynameAttribute test and express it as a json file in either the "exemplary" or "supplemental" directories. This is my take on the conversion:

{
    "mockBidRequest": {
        "id": "test-request-id",
        "site": {
            "page": "mysite.com"
        },
        "imp": [{
            "id": "test-imp-id",
            "banner": {
                "format": [{
                    "w": 300,
                    "h": 250
                }, {
                    "w": 300,
                    "h": 600
                }]
            },
            "ext": {
                "bidder": {
                    "zoneId": 8394,
                    "siteId": 283282,
                    "accountId": 7891
                }
            }
        }],
        "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"
                    }]
                }
            ]
        }
    },
    "httpCalls": [{
        "expectedRequest": {
            "uri": "uri?tk_xint=pbs-test-tracker",
            "body": {
                "id": "test-request-id",
                "site": {
                    "page": "mysite.com",
                    "publisher": {
                        "ext": {
                            "rp": {
                                "account_id": 7891
                            }
                        }
                    },
                    "ext": {
                        "rp": {
                            "site_id": 283282
                        }
                    }
                },
                "imp": [{
                    "id": "test-imp-id",
                    "banner": {
                        "format": [{
                            "w": 300,
                            "h": 250
                        }, {
                            "w": 300,
                            "h": 600
                        }],
                        "ext": {
                            "rp": {
                                "size_id": 15,
                                "alt_size_ids": [10],
                                "mime": "text/html"
                            }
                        }
                    },
                    "ext": {
                        "rp": {
                            "track": {
                                "mint": "",
                                "mint_version": ""
                            },
                            "zone_id": 8394
                        }
                    }
                }],
                "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"
                                ]
                            }
                        }
                    }
                }
            }
        },
        "mockResponse": {
            "status": 200,
            "body": {
                "id": "test-request-id",
                "seatbid": [{
                    "bid": [{
                        "id": "test_bid_id",
                        "impid": "test-imp-id",
                        "price": 0.27543,
                        "adm": "some-test-ad",
                        "cid": "test_cid",
                        "crid": "test_crid",
                        "dealid": "test_dealid",
                        "ext": {
                            "prebid": {
                                "type": "banner"
                            }
                        }
                    }],
                    "seat": "adman"
                }],
                "cur": "USD"
            }
        }
    }],
    "expectedBidResponses": [{
        "currency": "USD",
        "bids": [{
            "bid": {
                "id": "test_bid_id",
                "impid": "test-imp-id",
                "price": 0.27543,
                "adm": "some-test-ad",
                "cid": "test_cid",
                "crid": "test_crid",
                "dealid": "test_dealid",
                "ext": {
                    "prebid": {
                        "type": "banner"
                    }
                }
            },
            "type": "banner"
        }]
    }]
}

SIZE_ID := getTestSizes()
bidder := new(RubiconAdapter)

request := &openrtb.BidRequest{
ID: "test-request-id",
Imp: []openrtb.Imp{{
ID: "test-imp-id",
Banner: &openrtb.Banner{
Format: []openrtb.Format{
SIZE_ID[15],
SIZE_ID[10],
},
},
Ext: json.RawMessage(`{"bidder": {
"zoneId": 8394,
"siteId": 283282,
"accountId": 7891
}}`),
}},
User: &openrtb.User{
Data: []openrtb.Data{{
Ext: json.RawMessage(`{"taxonomyname": "iab"}`),
Segment: []openrtb.Segment{{
ID: "idToCopy",
}},
}, {
Ext: json.RawMessage(`{"taxonomyname": "someValue"}`),
Segment: []openrtb.Segment{{
ID: "shouldNotBeCopied",
}},
},
{
Ext: json.RawMessage(`{"taxonomyname": "IaB"}`),
Segment: []openrtb.Segment{{
ID: "idToCopy2",
}},
}, {
Ext: json.RawMessage(`{"taxonomyname": ["wrong iab type"]}`),
Segment: []openrtb.Segment{{
ID: "shouldNotBeCopied2",
}},
},
},
},
}

reqs, _ := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{})

rubiconReq := &openrtb.BidRequest{}
if err := json.Unmarshal(reqs[0].Body, rubiconReq); err != nil {
t.Fatalf("Unexpected error while decoding request: %s", err)
}

assert.NotNil(t, rubiconReq.User.Ext, "User.Ext object should not be nil.")

var userExt rubiconUserExt
if err := json.Unmarshal(rubiconReq.User.Ext, &userExt); err != nil {
t.Fatal("Error unmarshalling request.user.ext object.")
}

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.")
}

assert.Contains(t, userExtRPTarget, "iab", "request.user.ext.rp.target value is not as expected!")
assert.Contains(t, userExtRPTarget["iab"], "idToCopy", "No segment id idToCopy as expected!")
assert.Contains(t, userExtRPTarget["iab"], "idToCopy2", "No segment id idToCopy2 as expected!")
assert.NotContains(t, userExtRPTarget["iab"], "shouldNotBeCopied", "No segment id shouldNotBeCopied as expected!")
assert.NotContains(t, userExtRPTarget["iab"], "shouldNotBeCopied2", "No segment id shouldNotBeCopied2 as expected!")
}

func TestOpenRTBRequestWithVideoImpEvenIfImpHasBannerButAllRequiredVideoFields(t *testing.T) {
SIZE_ID := getTestSizes()
bidder := new(RubiconAdapter)
Expand Down
71 changes: 68 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,33 @@
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"user": {
"data": [
{
"ext": {
"taxonomyname": "Iab"
},
"segment": [
{
"id": "segmentId1"
},
{
"id": "segmentId2"
}
]
},
{
"ext": {
"taxonomyname": "not i-a-b"
},
"segment": [
{
"id": "segmentId3"
}
]
}
]
},
"imp": [
{
"id": "test-imp-id",
Expand All @@ -30,8 +57,8 @@
"video": {
},
"accountId": 1001,
"siteId":113932,
"zoneId":535510
"siteId": 113932,
"zoneId": 535510
}
}
}
Expand All @@ -52,6 +79,44 @@
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
},
"user": {
"data": [
{
"ext": {
"taxonomyname": "Iab"
},
"segment": [
{
"id": "segmentId1"
},
{
"id": "segmentId2"
}
]
},
{
"ext": {
"taxonomyname": "not i-a-b"
},
"segment": [
{
"id": "segmentId3"
}
]
}
],
"ext": {
"digitrust": null,
"rp": {
"target": {
"iab": [
"segmentId1",
"segmentId2"
]
}
}
}
},
"app": {
"id": "1",
"ext": {
Expand Down Expand Up @@ -91,7 +156,7 @@
},
"ext": {
"rp": {
"track":{
"track": {
"mint": "",
"mint_version": ""
},
Expand Down