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

IX: merge eventtrackers with imptrackers for native bid responses #1900

Merged
merged 9 commits into from
Jul 1, 2021
57 changes: 56 additions & 1 deletion adapters/ix/ix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"fmt"
"io/ioutil"
"net/http"
"sort"

"github.com/mxmCherry/openrtb/v15/native1"
native1response "github.com/mxmCherry/openrtb/v15/native1/response"
"github.com/mxmCherry/openrtb/v15/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
Expand Down Expand Up @@ -400,7 +403,7 @@ func (a *IxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalReque
for _, bid := range seatBid.Bid {
bidType, ok := impMediaType[bid.ImpID]
if !ok {
errs = append(errs, fmt.Errorf("Unmatched impression id: %s.", bid.ImpID))
errs = append(errs, fmt.Errorf("unmatched impression id: %s", bid.ImpID))
}

var bidExtVideo *openrtb_ext.ExtBidPrebidVideo
Expand All @@ -417,6 +420,28 @@ func (a *IxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalReque
}
}

var bidNative1_1 *Native11Wrapper
manigandham marked this conversation as resolved.
Show resolved Hide resolved
if bidType == openrtb_ext.BidTypeNative {
manigandham marked this conversation as resolved.
Show resolved Hide resolved
unmarshalExtErr := json.Unmarshal([]byte(bid.AdM), &bidNative1_1)
manigandham marked this conversation as resolved.
Show resolved Hide resolved
if unmarshalExtErr == nil && len(bidNative1_1.Native.EventTrackers) > 0 {
mergeNativeImpTrackers(&bidNative1_1.Native)
if json, marshalErr := json.Marshal(bidNative1_1); marshalErr == nil {
bid.AdM = string(json)
}
manigandham marked this conversation as resolved.
Show resolved Hide resolved
}
}

var bidNative1_2 *native1response.Response
if bidType == openrtb_ext.BidTypeNative {
unmarshalExtErr := json.Unmarshal([]byte(bid.AdM), &bidNative1_2)
manigandham marked this conversation as resolved.
Show resolved Hide resolved
if unmarshalExtErr == nil && len(bidNative1_2.EventTrackers) > 0 {
mergeNativeImpTrackers(bidNative1_2)
if json, marshalErr := json.Marshal(bidNative1_2); marshalErr == nil {
bid.AdM = string(json)
}
}
}

bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
Expand Down Expand Up @@ -444,3 +469,33 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
}
return bidder, nil
}

// native 1.2 to 1.1 tracker compatibility handling

type Native11Wrapper struct {
Native native1response.Response `json:"native,omitempty"`
}

func mergeNativeImpTrackers(bidNative *native1response.Response) {

// create unique list of imp pixels urls from `imptrackers` and `eventtrackers`
uniqueImpPixels := map[string]struct{}{}
for _, v := range bidNative.ImpTrackers {
uniqueImpPixels[v] = struct{}{}
}

for _, v := range bidNative.EventTrackers {
if v.Event == native1.EventTypeImpression && v.Method == native1.EventTrackingMethodImage {
uniqueImpPixels[v.URL] = struct{}{}
}
}

// rewrite `imptrackers` with new deduped list of imp pixels
bidNative.ImpTrackers = make([]string, 0)
for k := range uniqueImpPixels {
bidNative.ImpTrackers = append(bidNative.ImpTrackers, k)
}

// sort so tests pass correctly
sort.Strings(bidNative.ImpTrackers)
manigandham marked this conversation as resolved.
Show resolved Hide resolved
}
104 changes: 104 additions & 0 deletions adapters/ix/ixtest/exemplary/native-eventtrackers-compat-12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request": "{}",
"ver": "1.1"
},
"ext": {
"bidder": {
"siteId": "569749"
}
}
}
]
},
"httpcalls": [
{
"expectedRequest": {
"uri": "http://host/endpoint",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request": "{}",
"ver": "1.1"
},
"ext": {
"bidder": {
"siteId": "569749"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "958",
"bid": [
{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "{\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"text\":\"Learn about this awesome thing\"}},{\"id\":124,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/thumbnail1.png\"}},{\"id\":128,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/largethumb1.png\"}},{\"id\":126,\"required\":1,\"data\":{\"value\":\"My Brand\"}},{\"id\":127,\"required\":1,\"data\":{\"value\":\"Learn all about this awesome story of someone using my product.\"}}],\"link\":{\"url\":\"http: //i.am.a/URL\"},\"eventtrackers\":[{\"url\":\"https://example.com/imp-2.gif\",\"event\":1,\"method\":1},{\"url\":\"https://example.com/imp-3.gif\",\"event\":1,\"method\":1}],\"imptrackers\":[\"https://example.com/imp-1.gif\",\"https://example.com/imp-2.gif\"]}",
"adomain": [
"https://advertiser.example.com"
],
"cid": "958",
"crid": "29681110",
"cat": [
"IAB3-1"
],
"ext": {
"ix": {}
}
}
]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "{\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"text\":\"Learn about this awesome thing\"}},{\"id\":124,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/thumbnail1.png\"}},{\"id\":128,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/largethumb1.png\"}},{\"id\":126,\"required\":1,\"data\":{\"value\":\"My Brand\"}},{\"id\":127,\"required\":1,\"data\":{\"value\":\"Learn all about this awesome story of someone using my product.\"}}],\"link\":{\"url\":\"http: //i.am.a/URL\"},\"imptrackers\":[\"https://example.com/imp-1.gif\",\"https://example.com/imp-2.gif\",\"https://example.com/imp-3.gif\"],\"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"https://example.com/imp-2.gif\"},{\"event\":1,\"method\":1,\"url\":\"https://example.com/imp-3.gif\"}]}",
"adomain": [
"https://advertiser.example.com"
],
"cid": "958",
"crid": "29681110",
"cat": [
"IAB3-1"
],
"ext": {
"ix": {}
}
},
"type": "native"
}
]
}
]
}
2 changes: 1 addition & 1 deletion adapters/ix/ixtest/supplemental/bad-imp-id.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
],
"expectedMakeBidsErrors": [
{
"value": "Unmatched impression id: bad-imp-id.",
"value": "unmatched impression id: bad-imp-id",
"comparison": "literal"
}
]
Expand Down
104 changes: 104 additions & 0 deletions adapters/ix/ixtest/supplemental/native-eventtrackers-empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request": "{}",
"ver": "1.1"
},
"ext": {
"bidder": {
"siteId": "569749"
}
}
}
]
},
"httpcalls": [
{
"expectedRequest": {
"uri": "http://host/endpoint",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request": "{}",
"ver": "1.1"
},
"ext": {
"bidder": {
"siteId": "569749"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "958",
"bid": [
{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "{\"native\":{\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"text\":\"Learn about this awesome thing\"}},{\"id\":124,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/thumbnail1.png\"}},{\"id\":128,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/largethumb1.png\"}},{\"id\":126,\"required\":1,\"data\":{\"value\":\"My Brand\"}},{\"id\":127,\"required\":1,\"data\":{\"value\":\"Learn all about this awesome story of someone using my product.\"}}],\"link\":{\"url\":\"http: //i.am.a/URL\"},\"imptrackers\":[\"https://example.com/imp-1.gif\",\"https://example.com/imp-2.gif\"],\"eventtrackers\":[]}}",
"adomain": [
"https://advertiser.example.com"
],
"cid": "958",
"crid": "29681110",
"cat": [
"IAB3-1"
],
"ext": {
"ix": {}
}
}
]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "{\"native\":{\"assets\":[{\"id\":123,\"required\":1,\"title\":{\"text\":\"Learn about this awesome thing\"}},{\"id\":124,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/thumbnail1.png\"}},{\"id\":128,\"required\":1,\"img\":{\"url\":\"http://www.myads.com/largethumb1.png\"}},{\"id\":126,\"required\":1,\"data\":{\"value\":\"My Brand\"}},{\"id\":127,\"required\":1,\"data\":{\"value\":\"Learn all about this awesome story of someone using my product.\"}}],\"link\":{\"url\":\"http: //i.am.a/URL\"},\"imptrackers\":[\"https://example.com/imp-1.gif\",\"https://example.com/imp-2.gif\"],\"eventtrackers\":[]}}",
"adomain": [
"https://advertiser.example.com"
],
"cid": "958",
"crid": "29681110",
"cat": [
"IAB3-1"
],
"ext": {
"ix": {}
}
},
"type": "native"
}
]
}
]
}
Loading