Skip to content

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

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

Merged
merged 9 commits into from
Jul 1, 2021
30 changes: 30 additions & 0 deletions adapters/ix/ix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"io/ioutil"
"net/http"

"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 @@ -417,6 +419,34 @@ func (a *IxAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalReque
}
}

var bidNative *native1response.Response
if bidType == openrtb_ext.BidTypeNative {
unmarshalExtErr := json.Unmarshal([]byte(bid.AdM), &bidNative)
if unmarshalExtErr == nil && bidNative.EventTrackers != nil && len(bidNative.EventTrackers) > 0 {

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

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

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

json, _ := json.Marshal(bidNative)
bid.AdM = string(json)
}
}

bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
Expand Down