From e16b74643be231d7ce1d624cf250659283deb2dc Mon Sep 17 00:00:00 2001 From: Scott Kay Date: Wed, 5 May 2021 11:03:44 -0400 Subject: [PATCH] PubMatic: Fix Banner Size Assignment When No AdSlot Provided (#1825) --- adapters/pubmatic/pubmatic.go | 40 ++---- .../{simple-banner.json => banner.json} | 0 .../pubmatictest/supplemental/noAdSlot.json | 129 ++++++++++++++++++ 3 files changed, 144 insertions(+), 25 deletions(-) rename adapters/pubmatic/pubmatictest/exemplary/{simple-banner.json => banner.json} (100%) create mode 100644 adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go index afc9263af4e..2e361fa56f7 100644 --- a/adapters/pubmatic/pubmatic.go +++ b/adapters/pubmatic/pubmatic.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "io/ioutil" "net/http" @@ -158,8 +157,8 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder } pbReq.Imp[i].TagID = strings.TrimSpace(adSlot[0]) - pbReq.Imp[i].Banner.H = openrtb2.Int64Ptr(int64(height)) pbReq.Imp[i].Banner.W = openrtb2.Int64Ptr(int64(width)) + pbReq.Imp[i].Banner.H = openrtb2.Int64Ptr(int64(height)) if len(params.Keywords) != 0 { kvstr := prepareImpressionExt(params.Keywords) @@ -317,12 +316,11 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder func (a *PubmaticAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { errs := make([]error, 0, len(request.Imp)) - var err error wrapExt := "" pubID := "" for i := 0; i < len(request.Imp); i++ { - err = parseImpressionObject(&request.Imp[i], &wrapExt, &pubID) + err := parseImpressionObject(&request.Imp[i], &wrapExt, &pubID) // If the parsing is failed, remove imp and add the error. if err != nil { errs = append(errs, err) @@ -331,6 +329,11 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ad } } + // If all the requests are invalid, Call to adaptor is skipped + if len(request.Imp) == 0 { + return nil, errs + } + if wrapExt != "" { rawExt := fmt.Sprintf("{\"wrapper\": %s}", wrapExt) request.Ext = json.RawMessage(rawExt) @@ -358,13 +361,6 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ad request.App = &appCopy } - thisURI := a.URI - - // If all the requests are invalid, Call to adaptor is skipped - if len(request.Imp) == 0 { - return nil, errs - } - reqJSON, err := json.Marshal(request) if err != nil { errs = append(errs, err) @@ -376,7 +372,7 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ad headers.Add("Accept", "application/json") return []*adapters.RequestData{{ Method: "POST", - Uri: thisURI, + Uri: a.URI, Body: reqJSON, Headers: headers, }}, errs @@ -402,26 +398,26 @@ func validateAdSlot(adslot string, imp *openrtb2.Imp) error { adSize := strings.Split(strings.ToLower(adSlot[1]), "x") if len(adSize) != 2 { - return errors.New(fmt.Sprintf("Invalid size provided in adSlot %v", adSlotStr)) + return fmt.Errorf("Invalid size provided in adSlot %v", adSlotStr) } width, err := strconv.Atoi(strings.TrimSpace(adSize[0])) if err != nil { - return errors.New(fmt.Sprintf("Invalid width provided in adSlot %v", adSlotStr)) + return fmt.Errorf("Invalid width provided in adSlot %v", adSlotStr) } heightStr := strings.Split(adSize[1], ":") height, err := strconv.Atoi(strings.TrimSpace(heightStr[0])) if err != nil { - return errors.New(fmt.Sprintf("Invalid height provided in adSlot %v", adSlotStr)) + return fmt.Errorf("Invalid height provided in adSlot %v", adSlotStr) } //In case of video, size could be derived from the player size if imp.Banner != nil { - imp.Banner = assignBannerHeightAndWidth(imp.Banner, int64(height), int64(width)) + imp.Banner = assignBannerWidthAndHeight(imp.Banner, int64(width), int64(height)) } } else { - return errors.New(fmt.Sprintf("Invalid adSlot %v", adSlotStr)) + return fmt.Errorf("Invalid adSlot %v", adSlotStr) } return nil @@ -432,19 +428,13 @@ func assignBannerSize(banner *openrtb2.Banner) (*openrtb2.Banner, error) { return banner, nil } - if len(banner.Format) == 0 { - return nil, errors.New(fmt.Sprintf("No sizes provided for Banner %v", banner.Format)) - } - - return assignBannerHeightAndWidth(banner, banner.Format[0].H, banner.Format[0].H), nil + return assignBannerWidthAndHeight(banner, banner.Format[0].W, banner.Format[0].H), nil } -func assignBannerHeightAndWidth(banner *openrtb2.Banner, h, w int64) *openrtb2.Banner { +func assignBannerWidthAndHeight(banner *openrtb2.Banner, w, h int64) *openrtb2.Banner { bannerCopy := *banner - bannerCopy.W = openrtb2.Int64Ptr(w) bannerCopy.H = openrtb2.Int64Ptr(h) - return &bannerCopy } diff --git a/adapters/pubmatic/pubmatictest/exemplary/simple-banner.json b/adapters/pubmatic/pubmatictest/exemplary/banner.json similarity index 100% rename from adapters/pubmatic/pubmatictest/exemplary/simple-banner.json rename to adapters/pubmatic/pubmatictest/exemplary/banner.json diff --git a/adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json b/adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json new file mode 100644 index 00000000000..c66a71895ea --- /dev/null +++ b/adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json @@ -0,0 +1,129 @@ +{ + "mockBidRequest": { + "id": "test-request-id", + "imp": [{ + "id": "test-imp-id", + "banner": { + "format": [{ + "w": 300, + "h": 250 + }] + }, + "ext": { + "bidder": { + "publisherId": "999", + "keywords": [{ + "key": "pmZoneID", + "value": ["Zone1", "Zone2"] + }, + { + "key": "preference", + "value": ["sports", "movies"] + } + ], + "wrapper": { + "version": 1, + "profile": 5123 + } + } + } + }], + "device": { + "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + }, + "site": { + "id": "siteID", + "publisher": { + "id": "1234" + } + } + }, + + "httpCalls": [{ + "expectedRequest": { + "uri": "https://hbopenbid.pubmatic.com/translator?source=prebid-server", + "body": { + "id": "test-request-id", + "imp": [{ + "id": "test-imp-id", + "banner": { + "format": [{ + "w": 300, + "h": 250 + }], + "w": 300, + "h": 250 + }, + "ext": { + "pmZoneID": "Zone1,Zone2", + "preference": "sports,movies" + } + }], + "device": { + "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" + }, + "site": { + "id": "siteID", + "publisher": { + "id": "999" + } + }, + "ext": { + "wrapper": { + "profile": 5123, + "version": 1 + } + } + } + }, + "mockResponse": { + "status": 200, + "body": { + "id": "test-request-id", + "seatbid": [{ + "seat": "958", + "bid": [{ + "id": "7706636740145184841", + "impid": "test-imp-id", + "price": 0.500000, + "adid": "29681110", + "adm": "some-test-ad", + "adomain": ["pubmatic.com"], + "crid": "29681110", + "w": 300, + "h": 250, + "dealid": "test deal", + "ext": { + "dspid": 6, + "deal_channel": 1 + } + }] + }], + "bidid": "5778926625248726496", + "cur": "USD" + } + } + }], + "expectedBidResponses": [{ + "currency": "USD", + "bids": [{ + "bid": { + "id": "7706636740145184841", + "impid": "test-imp-id", + "price": 0.5, + "adid": "29681110", + "adm": "some-test-ad", + "adomain": ["pubmatic.com"], + "crid": "29681110", + "w": 300, + "h": 250, + "dealid": "test deal", + "ext": { + "dspid": 6, + "deal_channel": 1 + } + }, + "type": "banner" + }] + }] +} \ No newline at end of file