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

Adnuntius: Return DSA in bid response #3777

Merged
merged 5 commits into from
Sep 18, 2024
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
48 changes: 48 additions & 0 deletions adapters/adnuntius/adnuntius.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type siteExt struct {
Data interface{} `json:"data"`
}

type adnAdvertiser struct {
LegalName string `json:"legalName,omitempty"`
Name string `json:"name,omitempty"`
bsardo marked this conversation as resolved.
Show resolved Hide resolved
}

type Ad struct {
Bid struct {
Amount float64
Expand All @@ -56,6 +61,7 @@ type Ad struct {
LineItemId string
Html string
DestinationUrls map[string]string
Advertiser adnAdvertiser `json:"advertiser,omitempty"`
}

type AdUnit struct {
Expand Down Expand Up @@ -369,6 +375,40 @@ func getGDPR(request *openrtb2.BidRequest) (string, string, error) {
return gdpr, consent, nil
}

func generateReturnExt(ad Ad, request *openrtb2.BidRequest) (json.RawMessage, error) {
// We always force the publisher to render
var adRender int8 = 0

var requestRegsExt *openrtb_ext.ExtRegs
if request.Regs != nil && request.Regs.Ext != nil {
if err := json.Unmarshal(request.Regs.Ext, &requestRegsExt); err != nil {

return nil, fmt.Errorf("Failed to parse Ext information in Adnuntius: %v", err)
}
}

if ad.Advertiser.Name != "" && requestRegsExt != nil && requestRegsExt.DSA != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just want to confirm that Name is required to add the DSA object such that if LegalName is present but Name is not, you don't want to add the DSA object. Is that correct?

legalName := ad.Advertiser.Name
if ad.Advertiser.LegalName != "" {
legalName = ad.Advertiser.LegalName
}
ext := &openrtb_ext.ExtBid{
DSA: &openrtb_ext.ExtBidDSA{
AdRender: &adRender,
Paid: legalName,
Behalf: legalName,
},
}
returnExt, err := json.Marshal(ext)
if err != nil {
return nil, fmt.Errorf("Failed to parse Ext information in Adnuntius: %v", err)
}

return returnExt, nil
}
return nil, nil
}

func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.BidRequest) (*openrtb2.Bid, []error) {

creativeWidth, widthErr := strconv.ParseInt(ad.CreativeWidth, 10, 64)
Expand Down Expand Up @@ -410,6 +450,13 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.
}
}

extJson, err := generateReturnExt(ad, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error extracting Ext: %s", err.Error()),
}}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add test for this. Not covered
image


adDomain := []string{}
for _, url := range ad.DestinationUrls {
domainArray := strings.Split(url, "/")
Expand All @@ -429,6 +476,7 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.
Price: price * 1000,
AdM: html,
ADomain: adDomain,
Ext: extJson,
}
return &bid, nil

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"mockBidRequest": {
"id": "test-request-id",
"user": {
"id": "1kjh3429kjh295jkl"
},
"site": {
"ext":{
"data" : {
"key": ["value"]
}
}
},
"regs": {
"ext": {
"dsa": {
"dsarequired": 3,
"datatopub": 1
}
}
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"auId": "123"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://whatever.url?format=prebid&tzo=0",
"body": {
"adUnits": [
{
"auId": "123",
"targetId": "123-test-imp-id",
"dimensions": [[300,250],[300,600]]
}
],
"kv": {
"key": ["value"]
},
"metaData": {
"usi": "1kjh3429kjh295jkl"
},
"context": "unknown"
},
"impIDs":["test-imp-id"]
},
"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"
},
"adId": "adn-id-1559784094",
"creativeWidth": "980",
"creativeHeight": "240",
"creativeId": "jn9hpzvlsf8cpdmm",
"lineItemId": "q7y9qm5b0xt9htrv",
"advertiser": {
"name": "Name"
}
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "adn-id-1559784094",
"impid": "test-imp-id",
"price": 20000,
"adm": "<ADCODE>",
"adid": "adn-id-1559784094",
"adomain": [
"google.com"
],
"cid": "q7y9qm5b0xt9htrv",
"crid": "jn9hpzvlsf8cpdmm",
"w": 980,
"h": 240,
"ext": {
"dsa": {
"paid": "Name",
"behalf": "Name",
"adrender": 0
}
}
},
"type": "banner"

}
],
"currency": "NOK"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"mockBidRequest": {
"id": "test-request-id",
"user": {
"id": "1kjh3429kjh295jkl"
},
"site": {
"ext":{
"data" : {
"key": ["value"]
}
}
},
"regs": {
"ext": {
"dsa": {
"dsarequired": 3,
"datatopub": 1
}
}
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"auId": "123"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://whatever.url?format=prebid&tzo=0",
"body": {
"adUnits": [
{
"auId": "123",
"targetId": "123-test-imp-id",
"dimensions": [[300,250],[300,600]]
}
],
"kv": {
"key": ["value"]
},
"metaData": {
"usi": "1kjh3429kjh295jkl"
},
"context": "unknown"
},
"impIDs":["test-imp-id"]
},
"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"
},
"adId": "adn-id-1559784094",
"creativeWidth": "980",
"creativeHeight": "240",
"creativeId": "jn9hpzvlsf8cpdmm",
"lineItemId": "q7y9qm5b0xt9htrv",
"advertiser": {
"name": "Name",
"legalName": "LegalName"
}
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "adn-id-1559784094",
"impid": "test-imp-id",
"price": 20000,
"adm": "<ADCODE>",
"adid": "adn-id-1559784094",
"adomain": [
"google.com"
],
"cid": "q7y9qm5b0xt9htrv",
"crid": "jn9hpzvlsf8cpdmm",
"w": 980,
"h": 240,
"ext": {
"dsa": {
"paid": "LegalName",
"behalf": "LegalName",
"adrender": 0
}
}
},
"type": "banner"

}
],
"currency": "NOK"
}
]
}
Loading
Loading