-
Notifications
You must be signed in to change notification settings - Fork 735
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
342f398
Fix Banner Size Bug
SyntaxNode 6d506be
Refactor Errors Creation
SyntaxNode 58d3538
Remove Duplicate Validation
SyntaxNode c7c8c6b
Refactor Error Delcaration
SyntaxNode 89403b3
Move Up No Valid Impressions Check
SyntaxNode 80f219f
Remove Unnecessary Variable
SyntaxNode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
||
|
File renamed without changes.
129 changes: 129 additions & 0 deletions
129
adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}] | ||
}] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.