Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions adapters/taboola/taboola.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func createTaboolaRequests(request *openrtb2.BidRequest) (taboolaRequests []*ope
}

if taboolaExt.PageType != "" {
requestExt, requestExtErr := makeRequestExt(taboolaExt.PageType)
requestExt, requestExtErr := makeRequestExt(taboolaExt.PageType, modifiedRequest.Ext)
if requestExtErr == nil {
modifiedRequest.Ext = requestExt
} else {
Expand All @@ -253,17 +253,25 @@ func createTaboolaRequests(request *openrtb2.BidRequest) (taboolaRequests []*ope
return taboolaRequests, errs
}

func makeRequestExt(pageType string) (json.RawMessage, error) {
requestExt := &RequestExt{
PageType: pageType,
func makeRequestExt(pageType string, existingExt json.RawMessage) (json.RawMessage, error) {
extMap := make(map[string]json.RawMessage)
if len(existingExt) > 0 {
if err := jsonutil.Unmarshal(existingExt, &extMap); err != nil {
return nil, fmt.Errorf("could not unmarshal request ext: %s", err)
}
}

requestExtJson, err := json.Marshal(requestExt)
pageTypeJson, err := jsonutil.Marshal(pageType)
if err != nil {
return nil, fmt.Errorf("could not marshal %s, err: %s", requestExt, err)
return nil, fmt.Errorf("could not marshal pageType: %s", err)
}
return requestExtJson, nil
extMap["pageType"] = pageTypeJson

requestExtJson, err := jsonutil.Marshal(extMap)
if err != nil {
return nil, fmt.Errorf("could not marshal request ext: %s", err)
}
return requestExtJson, nil
}

func getMediaType(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
Expand Down Expand Up @@ -303,5 +311,6 @@ func resolveMacros(bid *openrtb2.Bid) {
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)
bid.BURL = strings.Replace(bid.BURL, "${AUCTION_PRICE}", price, -1)
}
}
29 changes: 29 additions & 0 deletions adapters/taboola/taboola_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package taboola

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v4/adapters/adapterstest"
Expand All @@ -20,6 +21,34 @@ func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "taboolatest", bidder)
}

func TestMakeRequestExt(t *testing.T) {
t.Run("merges pageType into existing ext without dropping other fields", func(t *testing.T) {
existingExt := json.RawMessage(`{"prebid":{"integration":"pbjs"}}`)

result, err := makeRequestExt("article", existingExt)

assert.NoError(t, err)
assert.JSONEq(t, `{"prebid":{"integration":"pbjs"},"pageType":"article"}`, string(result))
})

t.Run("sets pageType when existing ext is empty", func(t *testing.T) {
result, err := makeRequestExt("article", nil)

assert.NoError(t, err)
assert.JSONEq(t, `{"pageType":"article"}`, string(result))
})

t.Run("returns error when existing ext is invalid JSON", func(t *testing.T) {
invalidExt := json.RawMessage(`not-a-json-object`)

result, err := makeRequestExt("article", invalidExt)

assert.Error(t, err)
assert.Contains(t, err.Error(), "could not unmarshal request ext")
assert.Nil(t, result)
})
}

func TestEmptyExternalUrl(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderTaboola, config.Adapter{
Endpoint: "http://whatever.com"}, config.Server{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"w": 300,
"h": 250,
"exp": 60,
"lurl": "https://lurl.domain.com/"
"lurl": "https://lurl.domain.com/",
"burl": "https://burl.domain.com/?wp=${AUCTION_PRICE}"
}
],
"seat": "1111"
Expand Down Expand Up @@ -145,7 +146,8 @@
"w": 300,
"h": 250,
"exp": 60,
"lurl": "https://lurl.domain.com/"
"lurl": "https://lurl.domain.com/",
"burl": "https://burl.domain.com/?wp=2.1"
},
"type": "banner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"cid": "cid",
"crid": "crid",
"lurl": "https://lurl.domain.com/",
"nurl": "nurl.com&wp=${AUCTION_PRICE}"
"nurl": "nurl.com&wp=${AUCTION_PRICE}",
"burl": "https://burl.domain.com/?wp=${AUCTION_PRICE}"
}
],
"seat": "1111"
Expand Down Expand Up @@ -116,7 +117,8 @@
"cid": "cid",
"crid": "crid",
"lurl": "https://lurl.domain.com/",
"nurl": "nurl.com&wp=2.1"
"nurl": "nurl.com&wp=2.1",
"burl": "https://burl.domain.com/?wp=2.1"
},
"type": "native"
}
Expand Down
176 changes: 176 additions & 0 deletions adapters/taboola/taboolatest/exemplary/withPageTypeAndPrebidExt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"mockBidRequest": {
"id": "request-id",
"imp": [
{
"id": "impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"publisherId": "publisher-id",
"tagid": "tag-id",
"pageType": "article"
}
}
}
],
"site": {
"domain": "http://domain.com",
"page": "http://page-domain.com"
},
"device": {
"ua": "Mozilla/5.0",
"h": 300,
"w": 300
},
"ext": {
"prebid": {
"channel": {
"name": "web",
"version": "1.0"
},
"integration": "pbjs",
"server": {
"externalurl": "https://pbs.example.com",
"gvlid": 42,
"datacenter": "us-east-1"
},
"sdk": {
"renderers": [
{
"name": "test-renderer",
"version": "1.0.0"
}
]
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://display.whatever.com/12/publisher-id",
"body": {
"id": "request-id",
"imp": [
{
"id": "impression-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"tagid": "tag-id",
"ext": {
"bidder": {
"publisherId": "publisher-id",
"tagid": "tag-id",
"pageType": "article"
}
}
}
],
"site": {
"id": "publisher-id",
"name": "publisher-id",
"domain": "http://domain.com",
"page": "http://page-domain.com",
"publisher": {
"id": "publisher-id"
}
},
"device": {
"ua": "Mozilla/5.0",
"h": 300,
"w": 300
},
"ext": {
"pageType": "article",
"prebid": {
"channel": {
"name": "web",
"version": "1.0"
},
"integration": "pbjs",
"server": {
"externalurl": "https://pbs.example.com",
"gvlid": 42,
"datacenter": "us-east-1"
},
"sdk": {
"renderers": [
{
"name": "test-renderer",
"version": "1.0.0"
}
]
}
}
}
},
"impIDs": ["impression-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "123",
"seatbid": [
{
"bid": [
{
"id": "request-id",
"impid": "impression-id",
"price": 2.1,
"adid": "1",
"adm": "<html></html>",
"adomain": ["adomain.com"],
"cid": "cid",
"crid": "crid",
"w": 300,
"h": 250,
"exp": 60
}
],
"seat": "1111"
}
],
"bidid": "123",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "request-id",
"impid": "impression-id",
"price": 2.1,
"adid": "1",
"adm": "<html></html>",
"adomain": ["adomain.com"],
"cid": "cid",
"crid": "crid",
"w": 300,
"h": 250,
"exp": 60
},
"type": "banner"
}
]
}
]
}
5 changes: 0 additions & 5 deletions adapters/taboola/utils.go

This file was deleted.

Loading