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

AdView: support multi imps request & formattype tag for bid response #3355

Merged
merged 44 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dc07339
adview adapter v1.0
wildcat0601 Aug 30, 2021
2121b66
fix for review #1982.
wildcat0601 Aug 31, 2021
b8a4d78
fix format test json.
wildcat0601 Aug 31, 2021
4b60aa1
recover ext in request to adview bid.
wildcat0601 Aug 31, 2021
93fb6c7
remove invalid mediatype test
wildcat0601 Aug 31, 2021
1dce3fa
remove tabs from codes
wildcat0601 Sep 1, 2021
a482d51
tab issue fix.
wildcat0601 Sep 1, 2021
cab079d
fix gofmt
AdviewOpen Sep 1, 2021
c426908
1.fixed error log process.
wildcat0601 Sep 2, 2021
048c8ef
Merge branch 'master' of https://github.com/adview/prebid-server
wildcat0601 Sep 2, 2021
de429fa
Merge branch 'prebid:master' into master
AdviewOpen Oct 25, 2021
77747c7
for adapter currency fix.
wildcat0601 Oct 26, 2021
ef9ab39
(1)remove unused codes
wildcat0601 Oct 29, 2021
9c9c479
(1)add currency convert of request process.
wildcat0601 Nov 4, 2021
ef39579
Merge branch 'prebid:master' into master
AdviewOpen Nov 8, 2021
26e317d
add currency test case.
wildcat0601 Nov 9, 2021
9a26bcc
just removed case.
wildcat0601 Nov 9, 2021
8228da0
Merge branch 'prebid:master' into master
AdviewOpen Nov 19, 2021
e985bcc
add currency test script for new currency convert commit.
wildcat0601 Nov 19, 2021
d016752
Merge branch 'prebid:master' into master
AdviewOpen Apr 26, 2023
adb5217
add gzip & modifyingVastXmlAllowed mode in yaml config.
wilder0601 Apr 26, 2023
990ff0c
Merge branch 'prebid:master' into master
AdviewOpen Jul 21, 2023
47e3856
Merge branch 'prebid:master' into master
AdviewOpen Aug 4, 2023
1927653
Merge branch 'prebid:master' into master
AdviewOpen Dec 11, 2023
8301a2f
Merge branch 'prebid:master' into master
AdviewOpen Dec 14, 2023
56ab374
1.support multi imps from request.
wilder0601 Dec 14, 2023
ec7ddf0
fixes.
wilder0601 Dec 14, 2023
fb078a1
revert to older version codes.
wilder0601 Dec 14, 2023
62e2de8
fix2
wilder0601 Dec 14, 2023
8cccf08
fix3
wilder0601 Dec 14, 2023
333db3c
fix4
wilder0601 Dec 14, 2023
1d4e882
fix 5
wilder0601 Dec 14, 2023
6401e82
1)support multi imps from request.
wilder0601 Dec 15, 2023
b6988f1
Merge branch 'prebid:master' into master
AdviewOpen Jan 15, 2024
f2697d8
Fixed #3355 review:
wilder0601 Jan 15, 2024
41dc731
Merge branch 'prebid:master' into master
AdviewOpen Jan 22, 2024
3f8f06a
Adding default case and returning error in getBidType().
wilder0601 Jan 22, 2024
188fcfc
Merge branch 'prebid:master' into master
AdviewOpen Jan 25, 2024
ed5fec3
change getMediaTypeForBid(), use mtype to get bid type in response.
wilder0601 Jan 25, 2024
1d0d0f9
Merge branch 'prebid:master' into master
AdviewOpen Jan 29, 2024
d68ca53
1.add mtype in error case output.
wilder0601 Jan 29, 2024
21372b8
gofmt it.
wilder0601 Jan 29, 2024
2711af5
Merge branch 'prebid:master' into master
AdviewOpen Jan 31, 2024
57af4f6
remove audio type cause not support now.
wilder0601 Jan 31, 2024
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
144 changes: 81 additions & 63 deletions adapters/adview/adview.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type adapter struct {
endpoint *template.Template
}

type adviewBidExt struct {
BidType int `json:"formattype,omitempty"`
}

// Builder builds a new instance of the adview adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
endpointTemplate, err := template.New("endpointTemplate").Parse(config.Endpoint)
Expand All @@ -33,63 +37,78 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var bidderExt adapters.ExtImpBidder
imp := &request.Imp[0]
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("invalid imp.ext, %s", err.Error()),
}}
}
//use adview
var advImpExt openrtb_ext.ExtImpAdView
if err := json.Unmarshal(bidderExt.Bidder, &advImpExt); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("invalid bidderExt.Bidder, %s", err.Error()),
}}
}

imp.TagID = advImpExt.MasterTagID //tagid means posid
//for adview bid request
if imp.Banner != nil {
if len(imp.Banner.Format) != 0 {
bannerCopy := *imp.Banner
bannerCopy.H = &imp.Banner.Format[0].H
bannerCopy.W = &imp.Banner.Format[0].W
imp.Banner = &bannerCopy
var requests []*adapters.RequestData
var errors []error

//must copy the original request.
requestCopy := *request
for _, imp := range request.Imp {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
errors = append(errors, &errortypes.BadInput{
Message: fmt.Sprintf("invalid imp.ext, %s", err.Error()),
})
continue
}
//use adview
var advImpExt openrtb_ext.ExtImpAdView
if err := json.Unmarshal(bidderExt.Bidder, &advImpExt); err != nil {
errors = append(errors, &errortypes.BadInput{
Message: fmt.Sprintf("invalid bidderExt.Bidder, %s", err.Error()),
})
continue
}
}

// Check if imp comes with bid floor amount defined in a foreign currency
if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
// Convert to US dollars
convertedValue, err := requestInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err != nil {
return nil, []error{err}
imp.TagID = advImpExt.MasterTagID //tagid means posid
//for adview bid request
if imp.Banner != nil {
if len(imp.Banner.Format) != 0 {
bannerCopy := *imp.Banner
bannerCopy.H = &imp.Banner.Format[0].H
bannerCopy.W = &imp.Banner.Format[0].W
imp.Banner = &bannerCopy
}
}
// Update after conversion. All imp elements inside request.Imp are shallow copies
// therefore, their non-pointer values are not shared memory and are safe to modify.
imp.BidFloorCur = "USD"
imp.BidFloor = convertedValue
}

// Set the CUR of bid to USD after converting all floors
request.Cur = []string{"USD"}
// Check if imp comes with bid floor amount defined in a foreign currency
if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
// Convert to US dollars
convertedValue, err := requestInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err != nil {
errors = append(errors, err)
continue
}
// Update after conversion. All imp elements inside request.Imp are shallow copies
// therefore, their non-pointer values are not shared memory and are safe to modify.
imp.BidFloorCur = "USD"
imp.BidFloor = convertedValue
}

url, err := a.buildEndpointURL(&advImpExt)
if err != nil {
return nil, []error{err}
}
// Set the CUR of bid to USD after converting all floors
requestCopy.Cur = []string{"USD"}
requestCopy.Imp = []openrtb2.Imp{imp}

reqJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}
url, err := a.buildEndpointURL(&advImpExt)
if err != nil {
errors = append(errors, err)
continue
}

reqJSON, err := json.Marshal(requestCopy) //request
if err != nil {
errors = append(errors, err)
continue
}

return []*adapters.RequestData{{
Method: http.MethodPost,
Body: reqJSON,
Uri: url,
}}, nil
requestData := &adapters.RequestData{
Method: http.MethodPost,
Uri: url,
Body: reqJSON,
}
requests = append(requests, requestData)
}
return requests, errors
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down Expand Up @@ -117,12 +136,13 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
bidResponse.Currency = "USD" //we just support USD for resp
//we just support USD for resp
bidResponse.Currency = "USD"

var errors []error
for _, seatBid := range response.SeatBid {
for i, bid := range seatBid.Bid {
bidType, err := getMediaTypeForImp(bid.ImpID, request.Imp)
bidType, err := getMediaTypeForBid(bid)
if err != nil {
errors = append(errors, err)
continue
Expand All @@ -143,17 +163,15 @@ func (a *adapter) buildEndpointURL(params *openrtb_ext.ExtImpAdView) (string, er
return macros.ResolveMacros(a.endpoint, endpointParams)
}

func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
mediaType := openrtb_ext.BidTypeBanner
for _, imp := range imps {
if imp.ID == impID {
if imp.Video != nil {
mediaType = openrtb_ext.BidTypeVideo
} else if imp.Native != nil {
mediaType = openrtb_ext.BidTypeNative
}
return mediaType, nil
}
func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
default:
return "", fmt.Errorf("Unable to fetch mediaType in impID: %s, mType: %d", bid.ImpID, bid.MType)
}
return mediaType, nil
}
12 changes: 10 additions & 2 deletions adapters/adview/adviewtest/exemplary/banner-app-format.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@
],
"crid": "20",
"w": 320,
"h": 50
"h": 50,
"mtype": 1,
"ext": {
"formattype": 0
}
}
],
"type": "banner",
Expand Down Expand Up @@ -148,7 +152,11 @@
],
"crid": "20",
"w": 320,
"h": 50
"h": 50,
"mtype": 1,
"ext": {
"formattype": 0
}
},
"type": "banner"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"mockBidRequest": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"ifa":"00000000-0000-0000-0000-000000000000",
"language": "en",
"dnt": 0
},
"tmax": 1000,
"user": {
"buyeruid": "awesome-user"
},
"app": {
"publisher": {
"id": "123456789"
},
"cat": [
"IAB22-1"
],
"bundle": "com.app.awesome",
"name": "Awesome App",
"domain": "awesomeapp.com",
"id": "123456789"
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"w": 320,
"h": 50
},
"ext": {
"bidder": {
"placementId": "posid00001",
"accountId": "accountid01"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://bid.adview.com/agent/thirdAdxService/accountid01",
"body": {
"id": "some-request-id",
"cur": ["USD"],
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"ifa":"00000000-0000-0000-0000-000000000000",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "some-impression-id",
"banner": {
"w": 320,
"h": 50
},
"tagid": "posid00001",
"ext": {
"bidder": {
"placementId": "posid00001",
"accountId": "accountid01"
}
}
}
],
"app": {
"id": "123456789",
"name": "Awesome App",
"bundle": "com.app.awesome",
"domain": "awesomeapp.com",
"cat": [
"IAB22-1"
],
"publisher": {
"id": "123456789"
}
},
"user": {
"buyeruid": "awesome-user"
},
"tmax": 1000
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "awesome-resp-id",
"seatbid": [
{
"bid": [
{
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50,
"mtype": 1
}
],
"type": "banner",
"seat": "adview"
}
],
"cur": "USD",
"ext": {
"responsetimemillis": {
"adview": 154
},
"tmaxrequest": 1000
}
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
"impid": "some-impression-id",
"price": 3.5,
"adm": "awesome-markup",
"adomain": [
"awesome.com"
],
"crid": "20",
"w": 320,
"h": 50,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
12 changes: 10 additions & 2 deletions adapters/adview/adviewtest/exemplary/banner-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@
],
"crid": "20",
"w": 320,
"h": 50
"h": 50,
"mtype": 1,
"ext": {
"formattype": 0
}
}
],
"type": "banner",
Expand Down Expand Up @@ -138,7 +142,11 @@
],
"crid": "20",
"w": 320,
"h": 50
"h": 50,
"mtype": 1,
"ext": {
"formattype": 0
}
},
"type": "banner"
}
Expand Down
Loading
Loading