-
Notifications
You must be signed in to change notification settings - Fork 748
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
Adnuntius: Add Price Type #3084
Changes from 3 commits
d0f130d
88ee484
a7ce04f
e847ee1
429a99c
9096e25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,12 @@ type Ad struct { | |
Amount float64 | ||
Currency string | ||
} | ||
NetBid struct { | ||
Amount float64 | ||
} | ||
GrossBid struct { | ||
Amount float64 | ||
} | ||
DealID string `json:"dealId,omitempty"` | ||
AdId string | ||
CreativeWidth string | ||
|
@@ -328,7 +334,7 @@ func getGDPR(request *openrtb2.BidRequest) (string, string, error) { | |
return gdpr, consent, nil | ||
} | ||
|
||
func generateAdResponse(ad Ad, impId string, html string, request *openrtb2.BidRequest) (*openrtb2.Bid, []error) { | ||
func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.BidRequest) (*openrtb2.Bid, []error) { | ||
|
||
creativeWidth, widthErr := strconv.ParseInt(ad.CreativeWidth, 10, 64) | ||
if widthErr != nil { | ||
|
@@ -344,6 +350,18 @@ func generateAdResponse(ad Ad, impId string, html string, request *openrtb2.BidR | |
}} | ||
} | ||
|
||
price := ad.Bid.Amount | ||
priceType, _, _, _ := jsonparser.Get(imp.Ext, "bidder", "priceType") | ||
|
||
if string(priceType) != "" { | ||
if strings.ToLower(string(priceType)) == "net" { | ||
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. Please prefer to use 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. Thanks, this is changed. |
||
price = ad.NetBid.Amount | ||
} | ||
if strings.ToLower(string(priceType)) == "gross" { | ||
price = ad.GrossBid.Amount | ||
} | ||
} | ||
|
||
adDomain := []string{} | ||
for _, url := range ad.DestinationUrls { | ||
domainArray := strings.Split(url, "/") | ||
|
@@ -353,14 +371,14 @@ func generateAdResponse(ad Ad, impId string, html string, request *openrtb2.BidR | |
|
||
bid := openrtb2.Bid{ | ||
ID: ad.AdId, | ||
ImpID: impId, | ||
ImpID: imp.ID, | ||
W: creativeWidth, | ||
H: creativeHeight, | ||
AdID: ad.AdId, | ||
DealID: ad.DealID, | ||
CID: ad.LineItemId, | ||
CrID: ad.CreativeId, | ||
Price: ad.Bid.Amount * 1000, | ||
Price: price * 1000, | ||
AdM: html, | ||
ADomain: adDomain, | ||
} | ||
|
@@ -377,7 +395,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest) | |
adunitMap[adnRespAdunit.TargetId] = adnRespAdunit | ||
} | ||
|
||
for i, imp := range request.Imp { | ||
for _, imp := range request.Imp { | ||
|
||
auId, _, _, err := jsonparser.Get(imp.Ext, "bidder", "auId") | ||
if err != nil { | ||
|
@@ -394,7 +412,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest) | |
ad := adunit.Ads[0] | ||
currency = ad.Bid.Currency | ||
|
||
adBid, err := generateAdResponse(ad, request.Imp[i].ID, adunit.Html, request) | ||
adBid, err := generateAdResponse(ad, imp, adunit.Html, request) | ||
if err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Error at ad generation"), | ||
|
@@ -407,7 +425,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest) | |
}) | ||
|
||
for _, deal := range adunit.Deals { | ||
dealBid, err := generateAdResponse(deal, request.Imp[i].ID, deal.Html, request) | ||
dealBid, err := generateAdResponse(deal, imp, deal.Html, request) | ||
if err != nil { | ||
return nil, []error{&errortypes.BadInput{ | ||
Message: fmt.Sprintf("Error at ad generation"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"user": { | ||
"id": "1kjh3429kjh295jkl" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"auId": "123", | ||
"priceType": "gross" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://whatever.url?format=json&tzo=0", | ||
"body": { | ||
"adUnits": [ | ||
{ | ||
"auId": "123", | ||
"targetId": "123-test-imp-id", | ||
"dimensions": [[300,250],[300,600]] | ||
} | ||
], | ||
"metaData": { | ||
"usi": "1kjh3429kjh295jkl" | ||
}, | ||
"context": "unknown" | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"adUnits": [ | ||
{ | ||
"auId": "0000000000000123", | ||
"targetId": "123-test-imp-id", | ||
"html": "<ADCODE>", | ||
"responseId": "adn-rsp-900646517", | ||
"ads": [ | ||
{ | ||
"destinationUrls": { | ||
"url": "http://www.google.com" | ||
}, | ||
"bid": { "amount": 20.0, "currency": "NOK" }, | ||
"grossBid": {"amount": 0.1, "currency": "NOK"}, | ||
"netBid": {"amount": 0.075, "currency": "NOK"}, | ||
"adId": "adn-id-1559784094", | ||
"creativeWidth": "980", | ||
"creativeHeight": "240", | ||
"creativeId": "jn9hpzvlsf8cpdmm", | ||
"lineItemId": "q7y9qm5b0xt9htrv" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "adn-id-1559784094", | ||
"impid": "test-imp-id", | ||
"price": 100, | ||
"adm": "<ADCODE>", | ||
"adid": "adn-id-1559784094", | ||
"adomain": [ | ||
"google.com" | ||
], | ||
"cid": "q7y9qm5b0xt9htrv", | ||
"crid": "jn9hpzvlsf8cpdmm", | ||
"w": 980, | ||
"h": 240 | ||
}, | ||
"type": "banner" | ||
} | ||
], | ||
"currency": "NOK" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"user": { | ||
"id": "1kjh3429kjh295jkl" | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"bidder": { | ||
"auId": "123", | ||
"priceType": "net" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "http://whatever.url?format=json&tzo=0", | ||
"body": { | ||
"adUnits": [ | ||
{ | ||
"auId": "123", | ||
"targetId": "123-test-imp-id", | ||
"dimensions": [[300,250],[300,600]] | ||
} | ||
], | ||
"metaData": { | ||
"usi": "1kjh3429kjh295jkl" | ||
}, | ||
"context": "unknown" | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"adUnits": [ | ||
{ | ||
"auId": "0000000000000123", | ||
"targetId": "123-test-imp-id", | ||
"html": "<ADCODE>", | ||
"responseId": "adn-rsp-900646517", | ||
"ads": [ | ||
{ | ||
"destinationUrls": { | ||
"url": "http://www.google.com" | ||
}, | ||
"bid": { "amount": 20.0, "currency": "NOK" }, | ||
"grossBid": {"amount": 0.1, "currency": "NOK"}, | ||
"netBid": {"amount": 0.075, "currency": "NOK"}, | ||
"adId": "adn-id-1559784094", | ||
"creativeWidth": "980", | ||
"creativeHeight": "240", | ||
"creativeId": "jn9hpzvlsf8cpdmm", | ||
"lineItemId": "q7y9qm5b0xt9htrv" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "adn-id-1559784094", | ||
"impid": "test-imp-id", | ||
"price": 75, | ||
"adm": "<ADCODE>", | ||
"adid": "adn-id-1559784094", | ||
"adomain": [ | ||
"google.com" | ||
], | ||
"cid": "q7y9qm5b0xt9htrv", | ||
"crid": "jn9hpzvlsf8cpdmm", | ||
"w": 980, | ||
"h": 240 | ||
}, | ||
"type": "banner" | ||
} | ||
], | ||
"currency": "NOK" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ type ImpExtAdnunitus struct { | |
Network string `json:"network"` | ||
NoCookies bool `json:"noCookies"` | ||
MaxDeals int `json:"maxDeals"` | ||
PriceType string `json:"priceType,omitempty"` | ||
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. should also update @mikael-lundin bidder params is also missing entry for 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. update params tests to add valid and invalid tests for |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,21 @@ | |
"type": "string", | ||
"description": "Placement ID" | ||
}, | ||
"maxDeals": { | ||
"type": "integer", | ||
"description": "Specify how many deals that you want to return from the auction." | ||
}, | ||
"network": { | ||
"type": "string", | ||
"description": "Network if required" | ||
}, | ||
"noCookies": { | ||
"type": "boolean", | ||
"description": "Disable cookies being set by the ad server." | ||
}, | ||
"priceType": { | ||
"type": "string", | ||
"description": "Allows you to specify Net or Gross bids." | ||
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. should update 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. My bad .:/ |
||
} | ||
}, | ||
|
||
|
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.
Please do not ignore errors.
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.
I changed the way I fetched the value. because the way I did it above, it wouldn't allow for the key to be omitted it seemed. Hope my new way of doing it is good.