From 30ef8581806f5957c4417f05cd305e709d53a92e Mon Sep 17 00:00:00 2001 From: Jurij Sinickij Date: Mon, 24 Aug 2020 23:49:06 +0300 Subject: [PATCH] Adform adapter: additional targeting params added (#1424) --- adapters/adform/adform.go | 21 +++++++++++++++++++++ adapters/adform/adform_test.go | 30 ++++++++++++++++++++++-------- adapters/adform/params_test.go | 8 ++++++++ openrtb_ext/imp_adform.go | 11 +++++++---- static/bidder-params/adform.json | 14 ++++++++++++++ 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/adapters/adform/adform.go b/adapters/adform/adform.go index 69f1c12f073..5881f4ab86e 100644 --- a/adapters/adform/adform.go +++ b/adapters/adform/adform.go @@ -43,6 +43,7 @@ type adformRequest struct { digitrust *adformDigitrust currency string eids string + url string } type adformDigitrust struct { @@ -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 @@ -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() @@ -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())) } @@ -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 { @@ -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) @@ -520,6 +540,7 @@ func openRtbToAdformRequest(request *openrtb.BidRequest) (*adformRequest, []erro digitrust: digitrust, currency: requestCurrency, eids: eids, + url: url, }, errors } diff --git a/adapters/adform/adform_test.go b/adapters/adform/adform_test.go index 2fca7d1722d..f227776207d 100644 --- a/adapters/adform/adform_test.go +++ b/adapters/adform/adform_test.go @@ -35,6 +35,9 @@ type aTagInfo struct { keyValues string keyWords string code string + cdims string + url string + minp float64 price float64 content string @@ -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", @@ -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 { @@ -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 } diff --git a/adapters/adform/params_test.go b/adapters/adform/params_test.go index ae0a02b6a97..b392463f426 100644 --- a/adapters/adform/params_test.go +++ b/adapters/adform/params_test.go @@ -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{ @@ -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}`, } diff --git a/openrtb_ext/imp_adform.go b/openrtb_ext/imp_adform.go index 3e7c1a7261e..3206ece7c9b 100644 --- a/openrtb_ext/imp_adform.go +++ b/openrtb_ext/imp_adform.go @@ -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"` } diff --git a/static/bidder-params/adform.json b/static/bidder-params/adform.json index 67f09623ee4..f0b8c7a6be0 100644 --- a/static/bidder-params/adform.json +++ b/static/bidder-params/adform.json @@ -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"]