Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaato: Send imp.ext object entirely #3995

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 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.1"
const clientVersion = "prebid_server_1.2"

type adMarkupType string

Expand Down Expand Up @@ -471,14 +471,13 @@ func setImpForAdspace(imp *openrtb2.Imp) error {
return &errortypes.BadInput{Message: "Missing adspaceId parameter."}
}

impExt, err := makeImpExt(&imp.Ext)
err = removeBidderNodeFromImpExt(imp)
if err != nil {
return err
}

if imp.Banner != nil || imp.Video != nil || imp.Native != nil {
imp.TagID = adSpaceID
imp.Ext = impExt
return nil
}

Expand All @@ -490,15 +489,17 @@ func setImpForAdBreak(imps []openrtb2.Imp) error {
return &errortypes.BadInput{Message: "No impressions in bid request."}
}

adBreakID, err := jsonparser.GetString(imps[0].Ext, "bidder", "adbreakId")
firstImp := imps[0]
adBreakID, err := jsonparser.GetString(firstImp.Ext, "bidder", "adbreakId")
if err != nil {
return &errortypes.BadInput{Message: "Missing adbreakId parameter."}
}

impExt, err := makeImpExt(&imps[0].Ext)
err = removeBidderNodeFromImpExt(&firstImp)
if err != nil {
return err
}
ext := firstImp.Ext

for i := range imps {
imps[i].TagID = adBreakID
Expand All @@ -512,33 +513,33 @@ func setImpForAdBreak(imps []openrtb2.Imp) error {
imps[i].Video = &videoCopy
}

imps[0].Ext = impExt
imps[0].Ext = ext
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think you can get rid of the ext variable and instead just assign firstImp.Ext to imps[0].Ext.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


return nil
}

func makeImpExt(impExtRaw *json.RawMessage) (json.RawMessage, error) {
var impExt openrtb_ext.ExtImpExtraDataSmaato

if err := json.Unmarshal(*impExtRaw, &impExt); err != nil {
return nil, &errortypes.BadInput{Message: "Invalid imp.ext."}
func removeBidderNodeFromImpExt(imp *openrtb2.Imp) error {
if imp.Ext == nil {
return nil
}
updatedExt := jsonparser.Delete(imp.Ext, "bidder")
isEmpty := true
err := jsonparser.ObjectEach(updatedExt, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {
isEmpty = false
return nil
})
Comment on lines +527 to +530
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is an interesting approach. I imagine this is much faster than unmarshaling to a map and checking the length.


if impExtSkadnRaw := impExt.Skadn; impExtSkadnRaw != nil {
var impExtSkadn map[string]json.RawMessage

if err := json.Unmarshal(impExtSkadnRaw, &impExtSkadn); err != nil {
return nil, &errortypes.BadInput{Message: "Invalid imp.ext.skadn."}
}
if err != nil {
return err
}

if impExtJson, err := json.Marshal(impExt); string(impExtJson) != "{}" {
return impExtJson, err
if isEmpty {
imp.Ext = nil
} else {
return nil, nil
imp.Ext = updatedExt
}
return nil
}

func groupImpressionsByPod(imps []openrtb2.Imp) (map[string]([]openrtb2.Imp), []string, []error) {
pods := make(map[string][]openrtb2.Imp)
orderKeys := make([]string, 0)
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.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -350,7 +350,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["postbid_iframe"]
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.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -270,7 +270,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["postbid_iframe"]
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.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -327,7 +327,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
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.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down Expand Up @@ -260,7 +260,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
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.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["postbid_iframe"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"keywords": "keywords"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"keywords": "keywords"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"publisherId": "1100042525",
"adspaceId": "130563103"
},
"gpid": 1,
"skadn": {
"versions": ["2.0", "2.1", "2.2", "3.0", "4.0"],
"sourceapp": "880047117",
Expand Down Expand Up @@ -118,6 +119,7 @@
]
},
"ext": {
"gpid": 1,
"skadn": {
"versions": ["2.0", "2.1", "2.2", "3.0", "4.0"],
"sourceapp": "880047117",
Expand Down Expand Up @@ -167,7 +169,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
2 changes: 1 addition & 1 deletion adapters/smaato/smaatotest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
2 changes: 1 addition & 1 deletion adapters/smaato/smaatotest/exemplary/video-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"keywords": "keywords"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["postbid_iframe"]
Expand Down
2 changes: 1 addition & 1 deletion adapters/smaato/smaatotest/exemplary/video-dooh.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"keywords": "keywords"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["postbid_iframe"]
Expand Down
2 changes: 1 addition & 1 deletion adapters/smaato/smaatotest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
}
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["postbid_iframe"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"keywords": "power tools"
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
},
"ext": {
"client": "prebid_server_1.1"
"client": "prebid_server_1.2"
}
},
"impIDs":["1C86242D-9535-47D6-9576-7B1FE87F282C"]
Expand Down
Loading
Loading