Skip to content

Commit

Permalink
Smaato: OpenRTB video support
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrosinski committed Aug 27, 2020
1 parent 200d0b5 commit ead6890
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 7 deletions.
37 changes: 31 additions & 6 deletions adapters/smaato/smaato.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type adMarkupType string
const (
smtAdTypeImg adMarkupType = "Img"
smtAdTypeRichmedia adMarkupType = "Richmedia"
smtAdTypeVideo adMarkupType = "Video"
)

// SmaatoAdapter describes a Smaato prebid server adapter.
Expand Down Expand Up @@ -63,7 +64,7 @@ func (a *SmaatoAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapt
}

// Use bidRequestExt of first imp to retrieve params which are valid for all imps, e.g. publisherId
publisherId, err := jsonparser.GetString(request.Imp[0].Ext, "bidder", "publisherId")
publisherID, err := jsonparser.GetString(request.Imp[0].Ext, "bidder", "publisherId")
if err != nil {
errs = append(errs, err)
return nil, errs
Expand All @@ -80,7 +81,7 @@ func (a *SmaatoAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapt
}
if request.Site != nil {
siteCopy := *request.Site
siteCopy.Publisher = &openrtb.Publisher{ID: publisherId}
siteCopy.Publisher = &openrtb.Publisher{ID: publisherID}

if request.Site.Ext != nil {
var siteExt siteExt
Expand Down Expand Up @@ -179,15 +180,27 @@ func (a *SmaatoAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRe
bid := sb.Bid[i]

var markupError error
bid.AdM, markupError = renderAdMarkup(getAdMarkupType(response, bid.AdM), bid.AdM)
markupType := getAdMarkupType(response, bid.AdM)
bid.AdM, markupError = renderAdMarkup(markupType, bid.AdM)
if markupError != nil {
fmt.Println(markupError)
continue // no bid when broken ad markup
}

var bidType openrtb_ext.BidType
switch markupType {
case smtAdTypeImg:
bidType = openrtb_ext.BidTypeBanner
case smtAdTypeRichmedia:
bidType = openrtb_ext.BidTypeBanner
case smtAdTypeVideo:
bidType = openrtb_ext.BidTypeVideo
default:
continue // no bid when broken ad markup
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: openrtb_ext.BidTypeBanner,
BidType: bidType,
})
}
}
Expand All @@ -202,6 +215,8 @@ func renderAdMarkup(adMarkupType adMarkupType, adMarkup string) (string, error)
adm, markupError = extractAdmImage(adMarkup)
case smtAdTypeRichmedia:
adm, markupError = extractAdmRichMedia(adMarkup)
case smtAdTypeVideo:
adm, markupError = adMarkup, nil
default:
return "", fmt.Errorf("Unknown markup type %s", adMarkupType)
}
Expand All @@ -218,6 +233,9 @@ func getAdMarkupType(response *adapters.ResponseData, adMarkup string) adMarkupT
if strings.HasPrefix(adMarkup, `{"richmedia":`) {
return smtAdTypeRichmedia
}
if strings.HasPrefix(adMarkup, `<?xml`) {
return smtAdTypeVideo
}
return ""
}

Expand Down Expand Up @@ -255,7 +273,14 @@ func parseImpressionObject(imp *openrtb.Imp) error {
imp.Ext = nil
return nil
}
return fmt.Errorf("invalid MediaType. SMAATO only supports Banner. Ignoring ImpID=%s", imp.ID)

if imp.Video != nil {
imp.TagID = adSpaceID
imp.Ext = nil
return nil
}

return fmt.Errorf("invalid MediaType. SMAATO only supports Banner and Video. Ignoring ImpID=%s", imp.ID)
}

func extractUserExtAttributes(userExt userExt, userCopy *openrtb.User) {
Expand Down
187 changes: 187 additions & 0 deletions adapters/smaato/smaatotest/exemplary/video.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"mockBidRequest": {
"id": "447a0a1d-389d-4730-a418-3777e95de7bd",
"imp": [
{
"id": "postbid_iframe",
"video": {
"mimes": [
"video/mp4",
"video/quicktime",
"video/3gpp",
"video/x-m4v"
],
"minduration": 5,
"maxduration": 30,
"protocols": [
7
],
"w": 1024,
"h": 768,
"startdelay": 0,
"linearity": 1,
"skip": 1,
"skipmin": 5,
"api": [
7
],
"ext": {
"rewarded": 0
}
},
"ext": {
"bidder": {
"publisherId": "1100042525",
"adspaceId": "130563103"
}
}
}
],
"site": {
"publisher": {
"id": "1100042525"
},
"ext": {
"data": {},
"amp": 0
}
},
"device": {
"ua": "test-user-agent"
},
"user": {
"ext": {
"data": {}
}
},
"ext": {
"prebid": {
"auctiontimestamp": 1598262728811,
"targeting": {
"includewinners": true,
"includebidderkeys": false
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
]
},
"uri": "https://prebid/bidder",
"body": {
"id": "447a0a1d-389d-4730-a418-3777e95de7bd",
"imp": [
{
"id": "postbid_iframe",
"tagid": "130563103",
"video": {
"w": 1024,
"h": 768,
"ext": {
"rewarded": 0
},
"mimes": [
"video/mp4",
"video/quicktime",
"video/3gpp",
"video/x-m4v"
],
"minduration": 5,
"startdelay": 0,
"linearity": 1,
"maxduration": 30,
"skip": 1,
"protocols": [
7
],
"skipmin": 5,
"api": [
7
]
}
}
],
"user": {
"ext": {
}
},
"device": {
"ua": "test-user-agent"
},
"site": {
"publisher": {
"id": "1100042525"
}
},
"ext": {
"client": "prebid_server_0.1"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "5ebea288-f13a-4754-be6d-4ade66c68877",
"seatbid": [
{
"seat": "CM6523",
"bid": [
{
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><VAST version=\"2.0\"></VAST>",
"adomain": [
"smaato.com"
],
"bidderName": "smaato",
"cid": "CM6523",
"crid": "CR69381",
"id": "6906aae8-7f74-4edd-9a4f-f49379a3cadd",
"impid": "1C86242D-9535-47D6-9576-7B1FE87F282C",
"iurl": "https://iurl",
"nurl": "https://nurl",
"price": 0.01,
"w": 1024,
"h": 768
}
]
}
],
"bidid": "04db8629-179d-4bcd-acce-e54722969006",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><VAST version=\"2.0\"></VAST>",
"adomain": [
"smaato.com"
],
"cid": "CM6523",
"crid": "CR69381",
"id": "6906aae8-7f74-4edd-9a4f-f49379a3cadd",
"impid": "1C86242D-9535-47D6-9576-7B1FE87F282C",
"iurl": "https://iurl",
"nurl": "https://nurl",
"price": 0.01,
"w": 1024,
"h": 768
},
"type": "video"
}
]
}
]
}
4 changes: 3 additions & 1 deletion static/bidder-info/smaato.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ capabilities:
app:
mediaTypes:
- banner
- video
site:
mediaTypes:
- banner
- banner
- video

0 comments on commit ead6890

Please sign in to comment.