Skip to content
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

PubMatic: Fix Banner Size Assignment When No AdSlot Provided #1825

Merged
merged 6 commits into from
May 5, 2021
Merged
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
40 changes: 15 additions & 25 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reorganized statement and ordering to keep with the standard width height order.


if len(params.Keywords) != 0 {
kvstr := prepareImpressionExt(params.Keywords)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this check up in code to avoid other work which would otherwise be wasted.

return nil, errs
}

if wrapExt != "" {
rawExt := fmt.Sprintf("{\"wrapper\": %s}", wrapExt)
request.Ext = json.RawMessage(rawExt)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. This check is now performed by PBS-Core.


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
}

Expand Down
129 changes: 129 additions & 0 deletions adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json
Original file line number Diff line number Diff line change
@@ -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"
}]
}]
}