Skip to content

Commit

Permalink
Rubicon Project server-initiated targeting (#118)
Browse files Browse the repository at this point in the history
* Rubicon Project: Pass server-defined targeting through

* Removing accidental changes to AppNexus test
  • Loading branch information
pdezwart authored and Matt Kendall committed Sep 22, 2017
1 parent 47f0345 commit a4247cb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
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 @@ -301,6 +314,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

0 comments on commit a4247cb

Please sign in to comment.