Skip to content

Commit

Permalink
Adnuntius: Return DSA in bid response (#3777)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-lundin authored Sep 18, 2024
1 parent 640b97c commit 3c4527e
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 0 deletions.
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"`
}

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 {
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()),
}}
}

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

0 comments on commit 3c4527e

Please sign in to comment.