diff --git a/adapters/adot/adot.go b/adapters/adot/adot.go index f41beed8d21..5f99cf84518 100644 --- a/adapters/adot/adot.go +++ b/adapters/adot/adot.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" + "strings" "github.com/mxmCherry/openrtb/v15/openrtb2" "github.com/prebid/prebid-server/adapters" @@ -85,6 +87,7 @@ func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest for _, sb := range bidResp.SeatBid { for i := range sb.Bid { if bidType, err := getMediaTypeForBid(&sb.Bid[i]); err == nil { + resolveMacros(&sb.Bid[i]) bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &sb.Bid[i], BidType: bidType, @@ -116,3 +119,13 @@ func getMediaTypeForBid(bid *openrtb2.Bid) (openrtb_ext.BidType, error) { return "", fmt.Errorf("unrecognized bid type in response from adot") } + +// resolveMacros resolves OpenRTB macros in nurl and adm +func resolveMacros(bid *openrtb2.Bid) { + if bid == nil { + return + } + price := strconv.FormatFloat(bid.Price, 'f', -1, 64) + bid.NURL = strings.Replace(bid.NURL, "${AUCTION_PRICE}", price, -1) + bid.AdM = strings.Replace(bid.AdM, "${AUCTION_PRICE}", price, -1) +} diff --git a/adapters/adot/adot_test.go b/adapters/adot/adot_test.go index fbc7def4a74..3e0944b6e03 100644 --- a/adapters/adot/adot_test.go +++ b/adapters/adot/adot_test.go @@ -25,7 +25,6 @@ func TestJsonSamples(t *testing.T) { adapterstest.RunJSONBidderTest(t, "adottest", bidder) } -//Test the media type error func TestMediaTypeError(t *testing.T) { _, err := getMediaTypeForBid(nil) @@ -37,7 +36,6 @@ func TestMediaTypeError(t *testing.T) { assert.Error(t, err) } -//Test the bid response when the bidder return a status code 204 func TestBidResponseNoContent(t *testing.T) { bidder, buildErr := Builder(openrtb_ext.BidderAdot, config.Adapter{ Endpoint: "https://dsp.adotmob.com/headerbidding/bidrequest"}) @@ -54,7 +52,6 @@ func TestBidResponseNoContent(t *testing.T) { } } -//Test the media type for a bid response func TestMediaTypeForBid(t *testing.T) { byteBanner, _ := json.Marshal(&adotBidExt{Adot: bidExt{"banner"}}) byteVideo, _ := json.Marshal(&adotBidExt{Adot: bidExt{"video"}}) @@ -75,3 +72,10 @@ func TestMediaTypeForBid(t *testing.T) { t.Errorf("the type is not the valid one. actual: %v, expected: %v", bidTypeNative, openrtb_ext.BidTypeVideo) } } + +func TestResolveMacros(t *testing.T) { + bid := &openrtb2.Bid{AdM: "adm:imp_${AUCTION_PRICE} amd:creativeview_${AUCTION_PRICE}", NURL: "nurl_${AUCTION_PRICE}", Price: 123.45} + resolveMacros(bid) + assert.Equal(t, "adm:imp_123.45 amd:creativeview_123.45", bid.AdM) + assert.Equal(t, "nurl_123.45", bid.NURL) +} diff --git a/adapters/adot/adottest/exemplary/simple-banner.json b/adapters/adot/adottest/exemplary/simple-banner.json index 1b8cb9867f6..185addfcaef 100644 --- a/adapters/adot/adottest/exemplary/simple-banner.json +++ b/adapters/adot/adottest/exemplary/simple-banner.json @@ -55,7 +55,8 @@ "id": "test-request-banner-id", "impid": "test-imp-banner-id", "price": 1.16346, - "adm": "some-test-ad", + "adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}", + "nurl": "nurl.link/win?p=${AUCTION_PRICE}", "w": 320, "h": 50, "ext": { @@ -78,7 +79,8 @@ "id": "test-request-banner-id", "impid": "test-imp-banner-id", "price": 1.16346, - "adm": "some-test-ad", + "adm": "some-test-ad imp_1.16346 creativeview_1.16346", + "nurl": "nurl.link/win?p=1.16346", "w": 320, "h": 50, "ext": { diff --git a/adapters/adot/adottest/exemplary/simple-interstitial.json b/adapters/adot/adottest/exemplary/simple-interstitial.json index 0e9b573a530..09878984e76 100644 --- a/adapters/adot/adottest/exemplary/simple-interstitial.json +++ b/adapters/adot/adottest/exemplary/simple-interstitial.json @@ -58,8 +58,9 @@ "bid": [{ "id": "test-request-inter-id", "impid": "test-imp-inter-id", - "adm": "some-test-ad", "price": 1.16346, + "adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}", + "nurl": "nurl.link/win?p=${AUCTION_PRICE}", "w": 320, "h": 480, "ext": { @@ -82,8 +83,9 @@ "bid": { "id": "test-request-inter-id", "impid": "test-imp-inter-id", - "price": 1.16346, - "adm": "some-test-ad", + "price": 1.16346, + "adm": "some-test-ad imp_1.16346 creativeview_1.16346", + "nurl": "nurl.link/win?p=1.16346", "w": 320, "h": 480, "ext": { diff --git a/adapters/adot/adottest/exemplary/simple-native.json b/adapters/adot/adottest/exemplary/simple-native.json index 5fa3c70fd73..ad7bccff12a 100644 --- a/adapters/adot/adottest/exemplary/simple-native.json +++ b/adapters/adot/adottest/exemplary/simple-native.json @@ -45,7 +45,8 @@ "id": "test-request-native-id", "impid": "test-imp-native-id", "price": 1.16346, - "adm" : "native-ad", + "adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}", + "nurl": "nurl.link/win?p=${AUCTION_PRICE}", "w": 300, "h": 250, "ext": { @@ -70,7 +71,8 @@ "id": "test-request-native-id", "impid": "test-imp-native-id", "price": 1.16346, - "adm" : "native-ad", + "adm": "some-test-ad imp_1.16346 creativeview_1.16346", + "nurl": "nurl.link/win?p=1.16346", "w": 300, "h": 250, "ext": { diff --git a/adapters/adot/adottest/exemplary/simple-video.json b/adapters/adot/adottest/exemplary/simple-video.json index a453c4b9e18..4c85031863f 100644 --- a/adapters/adot/adottest/exemplary/simple-video.json +++ b/adapters/adot/adottest/exemplary/simple-video.json @@ -77,7 +77,8 @@ "id": "test-request-video-id", "impid": "test-imp-video-id", "price": 1.16346, - "adm": "some-test-ad", + "adm": "some-test-ad imp_${AUCTION_PRICE} creativeview_${AUCTION_PRICE}", + "nurl": "nurl.link/win?p=${AUCTION_PRICE}", "w": 300, "h": 250, "ext": { @@ -102,7 +103,8 @@ "id": "test-request-video-id", "impid": "test-imp-video-id", "price": 1.16346, - "adm": "some-test-ad", + "adm": "some-test-ad imp_1.16346 creativeview_1.16346", + "nurl": "nurl.link/win?p=1.16346", "w": 300, "h": 250, "ext": {