diff --git a/adapters/taboola/params_test.go b/adapters/taboola/params_test.go index 0ac740a8..25b6a75d 100644 --- a/adapters/taboola/params_test.go +++ b/adapters/taboola/params_test.go @@ -34,6 +34,8 @@ func TestInvalidParams(t *testing.T) { var validParams = []string{ `{"publisherId" : "1", "tagid": "tag-id-for-example"}`, + `{"publisherId" : "1", "tagid": "tag-id-for-example","position":1}`, + `{"publisherId" : "1", "tagid": "tag-id-for-example","pageType":"pageType"}`, `{"publisherId" : "1", "tagid": "tag-id-for-example", "bcat": ["excluded-category"], "badv": ["excluded-advertiser"], "bidfloor": 1.2, "publisherDomain": "http://domain.com"}`, } @@ -48,4 +50,8 @@ var invalidParams = []string{ `{"publisherId" : "1", "tagid": "tag-id-for-example", "publisherDomain":1}`, `{"publisherId" : "1", "bcat": ["excluded-category"], "badv": ["excluded-advertiser"], "bidfloor": 1.2, "publisherDomain": "http://domain.com"}`, `{"tagid": "tag-id-for-example", "bcat": ["excluded-category"], "badv": ["excluded-advertiser"], "bidfloor": 1.2, "publisherDomain": "http://domain.com"}`, + `{"publisherId" : "1", "tagid": "tag-id-for-example","position":null}`, + `{"publisherId" : "1", "tagid": "tag-id-for-example","position":"1"}`, + `{"publisherId" : "1", "tagid": "tag-id-for-example","pageType":1}`, + `{"publisherId" : "1", "tagid": "tag-id-for-example","pageType":null}`, } diff --git a/adapters/taboola/taboola.go b/adapters/taboola/taboola.go index 1c0cd484..881e6120 100644 --- a/adapters/taboola/taboola.go +++ b/adapters/taboola/taboola.go @@ -3,8 +3,7 @@ package taboola import ( "encoding/json" "fmt" - "github.com/prebid/openrtb/v17/native1" - nativeResponse "github.com/prebid/openrtb/v17/native1/response" + "github.com/prebid/openrtb/v17/adcom1" "github.com/prebid/openrtb/v17/openrtb2" "github.com/prebid/prebid-server/adapters" "github.com/prebid/prebid-server/config" @@ -103,20 +102,6 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R errs = append(errs, err) continue } - if bidType == openrtb_ext.BidTypeNative { - var nativePayload nativeResponse.Response - if err := json.Unmarshal(json.RawMessage(seatBid.Bid[i].AdM), &nativePayload); err != nil { - errs = append(errs, err) - continue - } - overrideEventTrackers(&nativePayload) - nativePayloadJson, err := json.Marshal(nativePayload) - if err != nil { - errs = append(errs, err) - continue - } - seatBid.Bid[i].AdM = string(nativePayloadJson) - } b := &adapters.TypedBid{ Bid: &seatBid.Bid[i], BidType: bidType, @@ -201,10 +186,17 @@ func createTaboolaRequests(request *openrtb2.BidRequest) (taboolaRequests []*ope } if modifiedRequest.Imp[i].Banner != nil { + if taboolaExt.Position != nil { + bannerCopy := *imp.Banner + bannerCopy.Pos = adcom1.PlacementPosition(*taboolaExt.Position).Ptr() + imp.Banner = &bannerCopy + modifiedRequest.Imp[i] = imp + } bannerImp = append(bannerImp, modifiedRequest.Imp[i]) } else if modifiedRequest.Imp[i].Native != nil { nativeImp = append(nativeImp, modifiedRequest.Imp[i]) } + } publisher := &openrtb2.Publisher{ @@ -236,12 +228,35 @@ func createTaboolaRequests(request *openrtb2.BidRequest) (taboolaRequests []*ope modifiedRequest.BAdv = taboolaExt.BAdv } + if taboolaExt.PageType != "" { + requestExt, requestExtErr := makeRequestExt(taboolaExt.PageType) + if requestExtErr == nil { + modifiedRequest.Ext = requestExt + } else { + errs = append(errs, requestExtErr) + } + } + taboolaRequests = append(taboolaRequests, overrideBidRequestImp(&modifiedRequest, nativeImp)) taboolaRequests = append(taboolaRequests, overrideBidRequestImp(&modifiedRequest, bannerImp)) return taboolaRequests, errs } +func makeRequestExt(pageType string) (json.RawMessage, error) { + requestExt := &RequestExt{ + PageType: pageType, + } + + requestExtJson, err := json.Marshal(requestExt) + if err != nil { + fmt.Errorf("could not marshal %s", requestExt) + return nil, err + } + return requestExtJson, nil + +} + func getMediaType(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) { for _, imp := range imps { if imp.ID == impID { @@ -273,19 +288,3 @@ func overrideBidRequestImp(originBidRequest *openrtb2.BidRequest, imp []openrtb2 bidRequestResult.Imp = imp return &bidRequestResult } - -func overrideEventTrackers(nativePayload *nativeResponse.Response) { - // convert eventrackers to the deprecated imptrackers and jstracker because it's not supported in native 1.1v - for _, eventTracker := range nativePayload.EventTrackers { - if eventTracker.Event != native1.EventTypeImpression { - continue - } - switch eventTracker.Method { - case native1.EventTrackingMethodImage: - nativePayload.ImpTrackers = append(nativePayload.ImpTrackers, eventTracker.URL) - case native1.EventTrackingMethodJS: - nativePayload.JSTracker = fmt.Sprintf("", eventTracker.URL) - } - } - nativePayload.EventTrackers = nil -} diff --git a/adapters/taboola/taboolatest/exemplary/multiFormatImpressionsRequest.json b/adapters/taboola/taboolatest/exemplary/multiFormatImpressionsRequest.json index f717d77f..7ba02f4e 100644 --- a/adapters/taboola/taboolatest/exemplary/multiFormatImpressionsRequest.json +++ b/adapters/taboola/taboolatest/exemplary/multiFormatImpressionsRequest.json @@ -283,7 +283,7 @@ "impid": "native-impression-id", "price": 2.1, "adid": "1", - "adm": "{\"link\":{\"url\":\"\"}}", + "adm": "{}", "adomain": [ "adomain.com" ], diff --git a/adapters/taboola/taboolatest/exemplary/native.json b/adapters/taboola/taboolatest/exemplary/native.json index 6aa7a13b..0d2c0417 100644 --- a/adapters/taboola/taboolatest/exemplary/native.json +++ b/adapters/taboola/taboolatest/exemplary/native.json @@ -106,7 +106,7 @@ "impid": "impression-id", "price": 2.1, "adid": "1", - "adm": "{\"ver\":\"1.2\",\"assets\":[{\"id\":7,\"required\":1,\"img\":{\"url\":\"http://image.taboola.com\",\"w\":600,\"h\":315}},{\"id\":0,\"required\":1,\"title\":{\"text\":\"Title For Example\"}},{\"id\":5,\"data\":{\"value\":\"Test sponsor\"}}],\"link\":{\"url\":\"http://clickUrl.com\"},\"imptrackers\":[\"http://tracker.com\"],\"jstracker\":\"\\u003cscript src=\\\"http://tracker-2.com\\\"\\u003e\\u003c/script\\u003e\"}", + "adm": "{\"ver\":\"1.2\",\"assets\":[{\"id\":7,\"required\":1,\"img\":{\"url\":\"http://image.taboola.com\",\"w\":600,\"h\":315}},{\"id\":0,\"required\":1,\"title\":{\"text\":\"Title For Example\"}},{\"id\":5,\"data\":{\"value\":\"Test sponsor\"}}],\"link\":{\"url\":\"http://clickUrl.com\"},\"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"http://tracker.com\"},{\"event\":1,\"method\":2,\"url\":\"http://tracker-2.com\"}]}", "adomain": [ "adomain.com" diff --git a/adapters/taboola/taboolatest/exemplary/withPageType.json b/adapters/taboola/taboolatest/exemplary/withPageType.json new file mode 100644 index 00000000..c1e303d5 --- /dev/null +++ b/adapters/taboola/taboolatest/exemplary/withPageType.json @@ -0,0 +1,157 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "impression-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + }, + { + "w": 160, + "h": 600 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "publisher-id", + "tagid": "tag-id", + "pageType": "homepage" + } + } + } + ], + "site": { + "domain": "http://domain.com", + "page": "http://page-domain.com", + "ref": "http://page-domain.com" + }, + "device": { + "ua": "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.62 Mobile Safari/537.36", + "h": 300, + "w": 300 + } + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://display.whatever.com/hosturl.com/publisher-id", + "body": { + "id": "request-id", + "imp": [ + { + "id": "impression-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + }, + { + "w": 160, + "h": 600 + } + ] + }, + "tagid" : "tag-id", + "ext": { + "bidder": { + "publisherId": "publisher-id", + "tagid": "tag-id", + "pageType": "homepage" + } + } + } + ], + "site": { + "id": "publisher-id", + "name": "publisher-id", + "domain": "http://domain.com", + "page": "http://page-domain.com", + "ref": "http://page-domain.com", + "publisher": { + "id": "publisher-id" + } + }, + "device": { + "ua": "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.62 Mobile Safari/537.36", + "h": 300, + "w": 300 + }, + "ext": { + "pageType": "homepage" + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "123", + "seatbid": [ + { + "bid": [ + { + "id": "request-id", + "impid": "impression-id", + "price": 2.1, + "adid": "1", + "adm": "", + "adomain": [ + "adomain.com" + ], + "cid": "cid", + "crid": "crid", + "w": 300, + "h": 250, + "exp": 60, + "lurl": "https://lurl.domain.com/" + } + ], + "seat": "1111" + } + ], + "bidid": "123", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "request-id", + "impid": "impression-id", + "price": 2.1, + "adid": "1", + "adm": "", + "adomain": [ + "adomain.com" + ], + "cid": "cid", + "crid": "crid", + "w": 300, + "h": 250, + "exp": 60, + "lurl": "https://lurl.domain.com/" + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/taboola/taboolatest/exemplary/withPosition.json b/adapters/taboola/taboolatest/exemplary/withPosition.json new file mode 100644 index 00000000..4f62dfa4 --- /dev/null +++ b/adapters/taboola/taboolatest/exemplary/withPosition.json @@ -0,0 +1,155 @@ +{ + "mockBidRequest": { + "id": "request-id", + "imp": [ + { + "id": "impression-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + }, + { + "w": 160, + "h": 600 + } + ] + }, + "ext": { + "bidder": { + "publisherId": "publisher-id", + "tagid": "tag-id", + "position": 1 + } + } + } + ], + "site": { + "domain": "http://domain.com", + "page": "http://page-domain.com", + "ref": "http://page-domain.com" + }, + "device": { + "ua": "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.62 Mobile Safari/537.36", + "h": 300, + "w": 300 + } + }, + "httpCalls": [ + { + "expectedRequest": { + "uri": "http://display.whatever.com/hosturl.com/publisher-id", + "body": { + "id": "request-id", + "imp": [ + { + "id": "impression-id", + "banner": { + "format": [ + { + "w": 300, + "h": 250 + }, + { + "w": 300, + "h": 600 + }, + { + "w": 160, + "h": 600 + } + ], + "pos": 1 + }, + "tagid" : "tag-id", + "ext": { + "bidder": { + "publisherId": "publisher-id", + "tagid": "tag-id", + "position": 1 + } + } + } + ], + "site": { + "id": "publisher-id", + "name": "publisher-id", + "domain": "http://domain.com", + "page": "http://page-domain.com", + "ref": "http://page-domain.com", + "publisher": { + "id": "publisher-id" + } + }, + "device": { + "ua": "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.62 Mobile Safari/537.36", + "h": 300, + "w": 300 + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "123", + "seatbid": [ + { + "bid": [ + { + "id": "request-id", + "impid": "impression-id", + "price": 2.1, + "adid": "1", + "adm": "", + "adomain": [ + "adomain.com" + ], + "cid": "cid", + "crid": "crid", + "w": 300, + "h": 250, + "exp": 60, + "lurl": "https://lurl.domain.com/" + } + ], + "seat": "1111" + } + ], + "bidid": "123", + "cur": "USD" + } + } + } + ], + "expectedBidResponses": [ + { + "currency": "USD", + "bids": [ + { + "bid": { + "id": "request-id", + "impid": "impression-id", + "price": 2.1, + "adid": "1", + "adm": "", + "adomain": [ + "adomain.com" + ], + "cid": "cid", + "crid": "crid", + "w": 300, + "h": 250, + "exp": 60, + "lurl": "https://lurl.domain.com/" + }, + "type": "banner" + } + ] + } + ] +} diff --git a/adapters/taboola/utils.go b/adapters/taboola/utils.go new file mode 100644 index 00000000..2703ec69 --- /dev/null +++ b/adapters/taboola/utils.go @@ -0,0 +1,5 @@ +package taboola + +type RequestExt struct { + PageType string `json:"pageType,omitempty"` +} diff --git a/openrtb_ext/imp_taboola.go b/openrtb_ext/imp_taboola.go index f20b4903..40057a0a 100644 --- a/openrtb_ext/imp_taboola.go +++ b/openrtb_ext/imp_taboola.go @@ -7,4 +7,6 @@ type ImpExtTaboola struct { TagId string `json:"tagid"` BCat []string `json:"bcat"` BAdv []string `json:"badv"` + PageType string `json:"pageType"` + Position *int `json:"position"` } diff --git a/static/bidder-params/taboola.json b/static/bidder-params/taboola.json index 2d924493..84bdf149 100644 --- a/static/bidder-params/taboola.json +++ b/static/bidder-params/taboola.json @@ -28,6 +28,12 @@ "items": { "type": "string" } + }, + "pageType": { + "type": "string" + }, + "position": { + "type": "integer" } }, "required": ["tagid","publisherId"]