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: Pass server-generated targeting through #117

Closed
wants to merge 3 commits into from
Closed
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
29 changes: 29 additions & 0 deletions adapters/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ type rubiconBannerExt struct {
RP rubiconBannerExtRP `json:"rp"`
}

type rubiconTargetingExt struct {
RP rubiconTargetingExtRP `json:"rp"`
}

type rubiconTargetingExtRP struct {
Targeting []rubiconTargetingObj `json:"targeting"`
}

type rubiconTargetingObj struct {
Key string `json:"key"`
Values []string `json:"values"`
}

type rubiSize struct {
w uint16
h uint16
Expand Down Expand Up @@ -210,6 +223,22 @@ func (a *RubiconAdapter) callOne(ctx context.Context, req *pbs.PBSRequest, reqJS
Height: bid.H,
DealId: bid.DealID,
}

// Pull out any server-side determined targeting
var rpExtTrg rubiconTargetingExt

if err := json.Unmarshal([]byte(bid.Ext), &rpExtTrg); err == nil {
// Converting string => array(string) to string => string
targeting := make(map[string]string)

// Only pick off the first for now
for _, target := range rpExtTrg.RP.Targeting {
targeting[target.Key] = target.Values[0]
}

result.bid.AdServerTargeting = targeting
}

return
}

Expand Down
36 changes: 26 additions & 10 deletions adapters/rubicon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"

Expand All @@ -25,10 +26,11 @@ type rubiAppendTrackerUrlTestScenario struct {
}

type rubiTagInfo struct {
code string
zoneID int
bid float64
content string
code string
zoneID int
bid float64
content string
adServerTargeting map[string]string
}

type rubiBidInfo struct {
Expand Down Expand Up @@ -123,11 +125,15 @@ func DummyRubiconServer(w http.ResponseWriter, r *http.Request) {
return
}

targeting := "{\"rp\":{\"targeting\":[{\"key\":\"key1\",\"values\":[\"value1\"]},{\"key\":\"key2\",\"values\":[\"value2\"]}]}}"
rawTargeting := openrtb.RawJSON(targeting)

resp.SeatBid[0].Bid[0] = openrtb.Bid{
ID: "random-id",
ImpID: imp.ID,
Price: rubidata.tags[ix].bid,
AdM: rubidata.tags[ix].content,
Ext: rawTargeting,
}

if breq.Site == nil {
Expand Down Expand Up @@ -206,15 +212,22 @@ func TestRubiconBasicResponse(t *testing.T) {
deviceUA: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30",
buyerUID: "need-an-actual-fb-id",
}

targeting := make(map[string]string, 2)
targeting["key1"] = "value1"
targeting["key2"] = "value2"

rubidata.tags[0] = rubiTagInfo{
code: "first-tag",
zoneID: 8394,
bid: 1.67,
code: "first-tag",
zoneID: 8394,
bid: 1.67,
adServerTargeting: targeting,
}
rubidata.tags[1] = rubiTagInfo{
code: "second-tag",
zoneID: 8395,
bid: 3.22,
code: "second-tag",
zoneID: 8395,
bid: 3.22,
adServerTargeting: targeting,
}

conf := *DefaultHTTPAdapterConfig
Expand Down Expand Up @@ -300,6 +313,9 @@ func TestRubiconBasicResponse(t *testing.T) {
if bid.Adm != tag.content {
t.Errorf("Incorrect bid markup '%s' expected '%s'", bid.Adm, tag.content)
}
if !reflect.DeepEqual(bid.AdServerTargeting, tag.adServerTargeting) {
t.Errorf("Incorrect targeting '%+v' expected '%+v'", bid.AdServerTargeting, tag.adServerTargeting)
}
}
}
if !matched {
Expand Down