Skip to content

Commit

Permalink
Adform adapter: additional targeting params added (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
braizhas authored Aug 24, 2020
1 parent d663380 commit 30ef858
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
21 changes: 21 additions & 0 deletions adapters/adform/adform.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type adformRequest struct {
digitrust *adformDigitrust
currency string
eids string
url string
}

type adformDigitrust struct {
Expand All @@ -61,6 +62,9 @@ type adformAdUnit struct {
PriceType string `json:"priceType,omitempty"`
KeyValues string `json:"mkv,omitempty"`
KeyWords string `json:"mkw,omitempty"`
CDims string `json:"cdims,omitempty"`
MinPrice float64 `json:"minp,omitempty"`
Url string `json:"url,omitempty"`

bidId string
adUnitCode string
Expand Down Expand Up @@ -284,6 +288,10 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {
parameters.Add("eids", r.eids)
}

if r.url != "" {
parameters.Add("url", r.url)
}

URL := *a.URL
URL.RawQuery = parameters.Encode()

Expand All @@ -302,6 +310,12 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {
if adUnit.KeyWords != "" {
buffer.WriteString(fmt.Sprintf("&mkw=%s", adUnit.KeyWords))
}
if adUnit.CDims != "" {
buffer.WriteString(fmt.Sprintf("&cdims=%s", adUnit.CDims))
}
if adUnit.MinPrice > 0 {
buffer.WriteString(fmt.Sprintf("&minp=%.2f", adUnit.MinPrice))
}
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(buffer.Bytes()))
}

Expand Down Expand Up @@ -407,6 +421,8 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
adUnits := make([]*adformAdUnit, 0, len(request.Imp))
errors := make([]error, 0, len(request.Imp))
secure := false
url := ""

for _, imp := range request.Imp {
params, _, _, err := jsonparser.Get(imp.Ext, "bidder")
if err != nil {
Expand Down Expand Up @@ -441,6 +457,10 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
secure = true
}

if url == "" {
url = adformAdUnit.Url
}

adformAdUnit.bidId = imp.ID
adformAdUnit.adUnitCode = imp.ID
adUnits = append(adUnits, &adformAdUnit)
Expand Down Expand Up @@ -520,6 +540,7 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro
digitrust: digitrust,
currency: requestCurrency,
eids: eids,
url: url,
}, errors
}

Expand Down
30 changes: 22 additions & 8 deletions adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type aTagInfo struct {
keyValues string
keyWords string
code string
cdims string
url string
minp float64

price float64
content string
Expand Down Expand Up @@ -320,9 +323,9 @@ func createTestData(secure bool) aBidInfo {
tid: "transaction-id",
buyerUID: "user-id",
tags: []aTagInfo{
{mid: 32344, keyValues: "color:red,age:30-40", keyWords: "red,blue", priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
{mid: 32345, priceType: "net", code: "code2"}, // no bid for ad unit
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2"},
{mid: 32344, keyValues: "color:red,age:30-40", keyWords: "red,blue", cdims: "300x300,400x200", priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
{mid: 32345, priceType: "net", code: "code2", minp: 23.1, cdims: "300x200"}, // no bid for ad unit
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2", url: "https://adform.com?a=b"},
},
secure: secure,
currency: "EUR",
Expand Down Expand Up @@ -519,11 +522,22 @@ func getUserExt() []byte {
}

func formatAdUnitJson(tag aTagInfo) string {
return fmt.Sprintf("{ \"mid\": %d%s%s%s}",
return fmt.Sprintf("{ \"mid\": %d%s%s%s%s%s%s}",
tag.mid,
formatAdUnitParam("priceType", tag.priceType),
formatAdUnitParam("mkv", tag.keyValues),
formatAdUnitParam("mkw", tag.keyWords))
formatAdUnitParam("mkw", tag.keyWords),
formatAdUnitParam("cdims", tag.cdims),
formatAdUnitParam("url", tag.url),
formatDemicalAdUnitParam("minp", tag.minp))
}

func formatDemicalAdUnitParam(fieldName string, fieldValue float64) string {
if fieldValue > 0 {
return fmt.Sprintf(", \"%s\": %.2f", fieldName, fieldValue)
}

return ""
}

func formatAdUnitParam(fieldName string, fieldValue string) string {
Expand All @@ -547,10 +561,10 @@ func assertAdformServerRequest(testData aBidInfo, r *http.Request, isOpenRtb boo
var midsWithCurrency = ""
var queryString = ""
if isOpenRtb {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVSJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
queryString = "CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&eids=eyJ0ZXN0LmNvbSI6eyJvdGhlcl91c2VyX2lkIjpbMF0sInNvbWVfdXNlcl9pZCI6WzFdfSwidGVzdDIub3JnIjp7Im90aGVyX3VzZXJfaWQiOlsyXX19&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&" + midsWithCurrency
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVSJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZSZjZGltcz0zMDB4MzAwLDQwMHgyMDA&bWlkPTMyMzQ1JnJjdXI9RVVSJmNkaW1zPTMwMHgyMDAmbWlucD0yMy4xMA&bWlkPTMyMzQ2JnJjdXI9RVVS"
queryString = "CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&eids=eyJ0ZXN0LmNvbSI6eyJvdGhlcl91c2VyX2lkIjpbMF0sInNvbWVfdXNlcl9pZCI6WzFdfSwidGVzdDIub3JnIjp7Im90aGVyX3VzZXJfaWQiOlsyXX19&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&url=https%3A%2F%2Fadform.com%3Fa%3Db&" + midsWithCurrency
} else {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZSZjZGltcz0zMDB4MzAwLDQwMHgyMDA&bWlkPTMyMzQ1JnJjdXI9VVNEJmNkaW1zPTMwMHgyMDAmbWlucD0yMy4xMA&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
queryString = "CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&" + midsWithCurrency
}

Expand Down
8 changes: 8 additions & 0 deletions adapters/adform/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var validParams = []string{
`{"mid":"123","mkv":"color:"}`,
`{"mid":"123","mkw":"green,male"}`,
`{"mid":"123","mkv":" ","mkw":" "}`,
`{"mid":"123","cdims":"500x300,400x200","mkw":" "}`,
`{"mid":"123","cdims":"500x300","mkv":" ","mkw":" "}`,
`{"mid":"123","minp":2.1}`,
`{"mid":"123","url":"https://adform.com/page"}`,
}

var invalidParams = []string{
Expand All @@ -66,4 +70,8 @@ var invalidParams = []string{
`{"mid":"123","mkv":"color:blue,l&ngth:350"}`,
`{"mid":"123","mkv":"color::blue"}`,
`{"mid":"123","mkw":"fem&le"}`,
`{"mid":"123","minp":"2.1"}`,
`{"mid":"123","cdims":"500x300:400:200","mkw":" "}`,
`{"mid":"123","cdims":"500x300,400:200","mkv":" ","mkw":" "}`,
`{"mid":"123","url":10}`,
}
11 changes: 7 additions & 4 deletions openrtb_ext/imp_adform.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package openrtb_ext

type ExtImpAdform struct {
MasterTagId string `json:"mid"`
PriceType string `json:"priceType,omitempty"`
KeyValues string `json:"mkv,omitempty"`
KeyWords string `json:"mkw,omitempty"`
MasterTagId string `json:"mid"`
PriceType string `json:"priceType,omitempty"`
KeyValues string `json:"mkv,omitempty"`
KeyWords string `json:"mkw,omitempty"`
CDims string `json:"cdims,omitempty"`
MinPrice float64 `json:"minp,omitempty"`
Url string `json:"url,omitempty"`
}
14 changes: 14 additions & 0 deletions static/bidder-params/adform.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
"type": "string",
"description": "Comma-separated keywords. Forbidden symbols: &.",
"pattern": "^[^&]*$"
},
"cdims": {
"type": "string",
"description": "Comma-separated creative dimentions.",
"pattern": "(^\\d+x\\d+)(,\\d+x\\d+)*$"
},
"minp": {
"type": "number",
"description": "The minimum CPM price.",
"minimum": 0
},
"url": {
"type": "string",
"description": "Custom URL for targeting."
}
},
"required": ["mid"]
Expand Down

0 comments on commit 30ef858

Please sign in to comment.