Skip to content

Commit 394bbad

Browse files
authored
IX: merge eventtrackers with imptrackers for native bid responses (#1900)
1 parent b996cf9 commit 394bbad

File tree

6 files changed

+473
-2
lines changed

6 files changed

+473
-2
lines changed

adapters/ix/ix.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"fmt"
88
"io/ioutil"
99
"net/http"
10+
"sort"
1011

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

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

423+
var bidNative1v1 *Native11Wrapper
424+
if bidType == openrtb_ext.BidTypeNative {
425+
err := json.Unmarshal([]byte(bid.AdM), &bidNative1v1)
426+
if err == nil && len(bidNative1v1.Native.EventTrackers) > 0 {
427+
mergeNativeImpTrackers(&bidNative1v1.Native)
428+
if json, err := json.Marshal(bidNative1v1); err == nil {
429+
bid.AdM = string(json)
430+
}
431+
}
432+
}
433+
434+
var bidNative1v2 *native1response.Response
435+
if bidType == openrtb_ext.BidTypeNative {
436+
err := json.Unmarshal([]byte(bid.AdM), &bidNative1v2)
437+
if err == nil && len(bidNative1v2.EventTrackers) > 0 {
438+
mergeNativeImpTrackers(bidNative1v2)
439+
if json, err := json.Marshal(bidNative1v2); err == nil {
440+
bid.AdM = string(json)
441+
}
442+
}
443+
}
444+
420445
bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
421446
Bid: &bid,
422447
BidType: bidType,
@@ -444,3 +469,33 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
444469
}
445470
return bidder, nil
446471
}
472+
473+
// native 1.2 to 1.1 tracker compatibility handling
474+
475+
type Native11Wrapper struct {
476+
Native native1response.Response `json:"native,omitempty"`
477+
}
478+
479+
func mergeNativeImpTrackers(bidNative *native1response.Response) {
480+
481+
// create unique list of imp pixels urls from `imptrackers` and `eventtrackers`
482+
uniqueImpPixels := map[string]struct{}{}
483+
for _, v := range bidNative.ImpTrackers {
484+
uniqueImpPixels[v] = struct{}{}
485+
}
486+
487+
for _, v := range bidNative.EventTrackers {
488+
if v.Event == native1.EventTypeImpression && v.Method == native1.EventTrackingMethodImage {
489+
uniqueImpPixels[v.URL] = struct{}{}
490+
}
491+
}
492+
493+
// rewrite `imptrackers` with new deduped list of imp pixels
494+
bidNative.ImpTrackers = make([]string, 0)
495+
for k := range uniqueImpPixels {
496+
bidNative.ImpTrackers = append(bidNative.ImpTrackers, k)
497+
}
498+
499+
// sort so tests pass correctly
500+
sort.Strings(bidNative.ImpTrackers)
501+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"imp": [
5+
{
6+
"id": "test-imp-id",
7+
"native": {
8+
"request": "{}",
9+
"ver": "1.1"
10+
},
11+
"ext": {
12+
"bidder": {
13+
"siteId": "569749"
14+
}
15+
}
16+
}
17+
]
18+
},
19+
"httpcalls": [
20+
{
21+
"expectedRequest": {
22+
"uri": "http://host/endpoint",
23+
"body": {
24+
"id": "test-request-id",
25+
"imp": [
26+
{
27+
"id": "test-imp-id",
28+
"native": {
29+
"request": "{}",
30+
"ver": "1.1"
31+
},
32+
"ext": {
33+
"bidder": {
34+
"siteId": "569749"
35+
}
36+
}
37+
}
38+
]
39+
}
40+
},
41+
"mockResponse": {
42+
"status": 200,
43+
"body": {
44+
"id": "test-request-id",
45+
"seatbid": [
46+
{
47+
"seat": "958",
48+
"bid": [
49+
{
50+
"id": "7706636740145184841",
51+
"impid": "test-imp-id",
52+
"price": 0.5,
53+
"adid": "29681110",
54+
"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\"]}",
55+
"adomain": [
56+
"https://advertiser.example.com"
57+
],
58+
"cid": "958",
59+
"crid": "29681110",
60+
"cat": [
61+
"IAB3-1"
62+
],
63+
"ext": {
64+
"ix": {}
65+
}
66+
}
67+
]
68+
}
69+
],
70+
"bidid": "5778926625248726496",
71+
"cur": "USD"
72+
}
73+
}
74+
}
75+
],
76+
"expectedBidResponses": [
77+
{
78+
"currency": "USD",
79+
"bids": [
80+
{
81+
"bid": {
82+
"id": "7706636740145184841",
83+
"impid": "test-imp-id",
84+
"price": 0.5,
85+
"adid": "29681110",
86+
"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\"}]}",
87+
"adomain": [
88+
"https://advertiser.example.com"
89+
],
90+
"cid": "958",
91+
"crid": "29681110",
92+
"cat": [
93+
"IAB3-1"
94+
],
95+
"ext": {
96+
"ix": {}
97+
}
98+
},
99+
"type": "native"
100+
}
101+
]
102+
}
103+
]
104+
}

adapters/ix/ixtest/supplemental/bad-imp-id.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
],
112112
"expectedMakeBidsErrors": [
113113
{
114-
"value": "Unmatched impression id: bad-imp-id.",
114+
"value": "unmatched impression id: bad-imp-id",
115115
"comparison": "literal"
116116
}
117117
]
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"imp": [
5+
{
6+
"id": "test-imp-id",
7+
"native": {
8+
"request": "{}",
9+
"ver": "1.1"
10+
},
11+
"ext": {
12+
"bidder": {
13+
"siteId": "569749"
14+
}
15+
}
16+
}
17+
]
18+
},
19+
"httpcalls": [
20+
{
21+
"expectedRequest": {
22+
"uri": "http://host/endpoint",
23+
"body": {
24+
"id": "test-request-id",
25+
"imp": [
26+
{
27+
"id": "test-imp-id",
28+
"native": {
29+
"request": "{}",
30+
"ver": "1.1"
31+
},
32+
"ext": {
33+
"bidder": {
34+
"siteId": "569749"
35+
}
36+
}
37+
}
38+
]
39+
}
40+
},
41+
"mockResponse": {
42+
"status": 200,
43+
"body": {
44+
"id": "test-request-id",
45+
"seatbid": [
46+
{
47+
"seat": "958",
48+
"bid": [
49+
{
50+
"id": "7706636740145184841",
51+
"impid": "test-imp-id",
52+
"price": 0.5,
53+
"adid": "29681110",
54+
"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\":[]}}",
55+
"adomain": [
56+
"https://advertiser.example.com"
57+
],
58+
"cid": "958",
59+
"crid": "29681110",
60+
"cat": [
61+
"IAB3-1"
62+
],
63+
"ext": {
64+
"ix": {}
65+
}
66+
}
67+
]
68+
}
69+
],
70+
"bidid": "5778926625248726496",
71+
"cur": "USD"
72+
}
73+
}
74+
}
75+
],
76+
"expectedBidResponses": [
77+
{
78+
"currency": "USD",
79+
"bids": [
80+
{
81+
"bid": {
82+
"id": "7706636740145184841",
83+
"impid": "test-imp-id",
84+
"price": 0.5,
85+
"adid": "29681110",
86+
"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\":[]}}",
87+
"adomain": [
88+
"https://advertiser.example.com"
89+
],
90+
"cid": "958",
91+
"crid": "29681110",
92+
"cat": [
93+
"IAB3-1"
94+
],
95+
"ext": {
96+
"ix": {}
97+
}
98+
},
99+
"type": "native"
100+
}
101+
]
102+
}
103+
]
104+
}

0 commit comments

Comments
 (0)