Skip to content

Commit

Permalink
Smaato: Add DOOH support (#3751)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan S. authored Jul 29, 2024
1 parent 55094fe commit 466ff83
Show file tree
Hide file tree
Showing 32 changed files with 718 additions and 55 deletions.
7 changes: 4 additions & 3 deletions adapters/smaato/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
)

func extractAdmBanner(adMarkup string, curls []string) string {
var clickEvent string
if len(curls) > 0 {
var clickEvent string
var clicks strings.Builder
for _, clicktracker := range curls {
clicks.WriteString("fetch(decodeURIComponent('" + url.QueryEscape(clicktracker) + "'.replace(/\\+/g, ' ')), " +
"{cache: 'no-cache'});")
}
clickEvent = fmt.Sprintf(`onclick=%s`, clicks.String())
clickEvent = fmt.Sprintf(`onclick="%s"`, clicks.String())
return fmt.Sprintf(`<div style="cursor:pointer" %s>%s</div>`, clickEvent, adMarkup)
}

return fmt.Sprintf(`<div style="cursor:pointer" %s>%s</div>`, clickEvent, adMarkup)
return adMarkup
}
6 changes: 3 additions & 3 deletions adapters/smaato/banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ func TestExtractAdmBanner(t *testing.T) {
{
testName: "extract_banner_without_curls",
adMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
expectedAdMarkup: `<div style="cursor:pointer" ><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
expectedAdMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
curls: []string{},
},
{
testName: "extract_banner_with_nil_curls",
adMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
expectedAdMarkup: `<div style="cursor:pointer" ><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
expectedAdMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
curls: nil,
},
{
testName: "extract_banner_with_curls",
adMarkup: `<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>`,
expectedAdMarkup: `<div style="cursor:pointer" onclick=fetch(decodeURIComponent('curls.net'.replace(/\+/g, ' ')), {cache: 'no-cache'});><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
expectedAdMarkup: `<div style="cursor:pointer" onclick="fetch(decodeURIComponent('curls.net'.replace(/\+/g, ' ')), {cache: 'no-cache'});"><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>`,
curls: []string{"curls.net"},
},
}
Expand Down
18 changes: 15 additions & 3 deletions adapters/smaato/smaato.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/prebid/prebid-server/v2/util/timeutil"
)

const clientVersion = "prebid_server_1.0"
const clientVersion = "prebid_server_1.1"

type adMarkupType string

Expand Down Expand Up @@ -271,7 +271,7 @@ func getAdMarkupType(response *adapters.ResponseData) (adMarkupType, error) {
return admType, nil
} else {
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("X-Smt-Adtype header is missing!"),
Message: fmt.Sprintf("X-Smt-Adtype header is missing."),
}
}
}
Expand Down Expand Up @@ -330,6 +330,7 @@ func prepareCommonRequest(request *openrtb2.BidRequest) error {
}

setApp(request)
setDOOH(request)

return setExt(request)
}
Expand Down Expand Up @@ -434,6 +435,13 @@ func setApp(request *openrtb2.BidRequest) {
}
}

func setDOOH(request *openrtb2.BidRequest) {
if request.DOOH != nil {
doohCopy := *request.DOOH
request.DOOH = &doohCopy
}
}

func setPublisherId(request *openrtb2.BidRequest, imp *openrtb2.Imp) error {
publisherID, err := jsonparser.GetString(imp.Ext, "bidder", "publisherId")
if err != nil {
Expand All @@ -448,8 +456,12 @@ func setPublisherId(request *openrtb2.BidRequest, imp *openrtb2.Imp) error {
// App is already a copy
request.App.Publisher = &openrtb2.Publisher{ID: publisherID}
return nil
} else if request.DOOH != nil {
// DOOH is already a copy
request.DOOH.Publisher = &openrtb2.Publisher{ID: publisherID}
return nil
} else {
return &errortypes.BadInput{Message: "Missing Site/App."}
return &errortypes.BadInput{Message: "Missing Site/App/DOOH."}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -350,7 +350,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["postbid_iframe"]
Expand Down Expand Up @@ -421,7 +421,7 @@
"bids": [
{
"bid": {
"adm": "<div style=\"cursor:pointer\" ><a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a></div>",
"adm": "<a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a>",
"adomain": [
"smaato.com"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -270,7 +270,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["postbid_iframe"]
Expand Down Expand Up @@ -317,7 +317,7 @@
"bids": [
{
"bid": {
"adm": "<div style=\"cursor:pointer\" ><a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a></div>",
"adm": "<a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a>",
"adomain": [
"smaato.com"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -327,7 +327,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -398,7 +398,7 @@
"bids": [
{
"bid": {
"adm": "<div style=\"cursor:pointer\" ><a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a></div>",
"adm": "<a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a>",
"adomain": [
"smaato.com"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -260,7 +260,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -307,7 +307,7 @@
"bids": [
{
"bid": {
"adm": "<div style=\"cursor:pointer\" ><a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a></div>",
"adm": "<a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a>",
"adomain": [
"smaato.com"
],
Expand Down
2 changes: 1 addition & 1 deletion adapters/smaato/smaatotest/exemplary/native.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
}
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["postbid_iframe"]
Expand Down
4 changes: 2 additions & 2 deletions adapters/smaato/smaatotest/exemplary/simple-banner-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"keywords": "keywords"
},
"ext": {
"client": "prebid_server_1.0"
"client": "prebid_server_1.1"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -205,7 +205,7 @@
"bids": [
{
"bid": {
"adm": "<div style=\"cursor:pointer\" ><a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a></div>",
"adm": "<a rel=\"nofollow\" href=\"https://prebid.net/click\"><img src=\"https://prebid.net/images/image.png\" alt=\"\" width=\"480\" height=\"320\" /></a>",
"adomain": [
"smaato.com"
],
Expand Down
Loading

0 comments on commit 466ff83

Please sign in to comment.