Skip to content

Commit

Permalink
Revert "ImproveDigital: Remove placementKey & addtlconsent parsing (p…
Browse files Browse the repository at this point in the history
…rebid#3728)"

This reverts commit 081c6e0.
  • Loading branch information
krdzo authored Oct 30, 2024
1 parent 754a216 commit 19a69fe
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 12 deletions.
83 changes: 80 additions & 3 deletions adapters/improvedigital/improvedigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
)

const (
isRewardedInventory = "is_rewarded_inventory"
stateRewardedInventoryEnable = "1"
publisherEndpointParam = "{PublisherId}"
isRewardedInventory = "is_rewarded_inventory"
stateRewardedInventoryEnable = "1"
consentProvidersSettingsInputKey = "ConsentedProvidersSettings"
consentProvidersSettingsOutKey = "consented_providers_settings"
consentedProvidersKey = "consented_providers"
publisherEndpointParam = "{PublisherId}"
)

type ImprovedigitalAdapter struct {
Expand Down Expand Up @@ -72,6 +75,17 @@ func (a *ImprovedigitalAdapter) makeRequest(request openrtb2.BidRequest, imp ope

request.Imp = []openrtb2.Imp{imp}

userExtAddtlConsent, err := a.getAdditionalConsentProvidersUserExt(request)
if err != nil {
return nil, err
}

if len(userExtAddtlConsent) > 0 {
userCopy := *request.User
userCopy.Ext = userExtAddtlConsent
request.User = &userCopy
}

reqJSON, err := json.Marshal(request)
if err != nil {
return nil, err
Expand Down Expand Up @@ -241,6 +255,69 @@ func isMultiFormatImp(imp openrtb2.Imp) bool {
return formatCount > 1
}

// This method responsible to clone request and convert additional consent providers string to array when additional consent provider found
func (a *ImprovedigitalAdapter) getAdditionalConsentProvidersUserExt(request openrtb2.BidRequest) ([]byte, error) {
var cpStr string

// If user/user.ext not defined, no need to parse additional consent
if request.User == nil || request.User.Ext == nil {
return nil, nil
}

// Start validating additional consent
// Check key exist user.ext.ConsentedProvidersSettings
var userExtMap = make(map[string]json.RawMessage)
if err := json.Unmarshal(request.User.Ext, &userExtMap); err != nil {
return nil, err
}

cpsMapValue, cpsJSONFound := userExtMap[consentProvidersSettingsInputKey]
if !cpsJSONFound {
return nil, nil
}

// Check key exist user.ext.ConsentedProvidersSettings.consented_providers
var cpMap = make(map[string]json.RawMessage)
if err := json.Unmarshal(cpsMapValue, &cpMap); err != nil {
return nil, err
}

cpMapValue, cpJSONFound := cpMap[consentedProvidersKey]
if !cpJSONFound {
return nil, nil
}
// End validating additional consent

// Trim enclosing quotes after casting json.RawMessage to string
consentStr := strings.Trim((string)(cpMapValue), "\"")
// Split by ~ and take only the second string (if exists) as the consented providers spec
var consentStrParts = strings.Split(consentStr, "~")
if len(consentStrParts) < 2 {
return nil, nil
}
cpStr = strings.TrimSpace(consentStrParts[1])
if len(cpStr) == 0 {
return nil, nil
}

// Prepare consent providers string
cpStr = fmt.Sprintf("[%s]", strings.Replace(cpStr, ".", ",", -1))
cpMap[consentedProvidersKey] = json.RawMessage(cpStr)

cpJSON, err := json.Marshal(cpMap)
if err != nil {
return nil, err
}
userExtMap[consentProvidersSettingsOutKey] = cpJSON

extJson, err := json.Marshal(userExtMap)
if err != nil {
return nil, err
}

return extJson, nil
}

func getImpExtWithRewardedInventory(imp openrtb2.Imp) ([]byte, error) {
var ext = make(map[string]json.RawMessage)
if err := json.Unmarshal(imp.Ext, &ext); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"mockBidRequest": {
"id": "addtl-consent-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
}],
"user": {
"ext":{"consent":"ABC","ConsentedProvidersSettings":{"consented_providers":"1~10.20.90~2"}}
}
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/pbs",
"body": {
"id": "addtl-consent-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
}],
"user": {
"ext": {"consent": "ABC","ConsentedProvidersSettings":{"consented_providers":"1~10.20.90~2"},"consented_providers_settings": {"consented_providers": [10,20,90]}
}
}
},
"impIDs": ["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "addtl-consent-request-id",
"seatbid": [{
"seat": "improvedigital",
"bid": [{
"id": "randomid",
"impid": "test-imp-id",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300
}]
}],
"cur": "USD"
}
}
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250
},
"type": "banner"
}]
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"mockBidRequest": {
"id": "addtl-consent-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
}],
"user": {
"ext":{"consent":"ABC","ConsentedProvidersSettings":{"consented_providers":"1~10.20.90"}}
}
},

"httpCalls": [{
"expectedRequest": {
"uri": "http://localhost/pbs",
"body": {
"id": "addtl-consent-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [{
"id": "test-imp-id",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {
"placementId": 13245
}
}
}],
"user": {
"ext": {"consent": "ABC","ConsentedProvidersSettings":{"consented_providers":"1~10.20.90"},"consented_providers_settings": {"consented_providers": [10,20,90]}
}
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "addtl-consent-request-id",
"seatbid": [{
"seat": "improvedigital",
"bid": [{
"id": "randomid",
"impid": "test-imp-id",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300
}]
}],
"cur": "USD"
}
}
}],

"expectedBidResponses": [{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250
},
"type": "banner"
}]
}]
}
3 changes: 2 additions & 1 deletion adapters/improvedigital/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestInvalidParams(t *testing.T) {
var validParams = []string{
`{"placementId":13245}`,
`{"placementId":13245, "size": {"w":16, "h":9}}`,
`{"publisherId":13245, "placementKey": "slotA"}`,
`{"placementId":13245, "keyValues":{"target1":["foo"],"target2":["bar", "baz"]}}`,
}

Expand All @@ -55,5 +56,5 @@ var invalidParams = []string{
`{"placementId": "1"}`,
`{"size": true}`,
`{"placementId": true, "size":"1234567"}`,
`{"publisherId":13245, "placementKey": "slotA"}`,
`{"placementId":13245, "publisherId":13245, "placementKey": "slotA"}`,
}
21 changes: 13 additions & 8 deletions static/bidder-params/improvedigital.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"placementId": {
"type": "integer",
"minimum": 1,
"description": "The placement ID from Improve Digital"
"description": "An ID which identifies this placement of the impression"
},
"publisherId": {
"type": "integer",
"minimum": 1,
"description": "The publisher ID from Improve Digital"
"description": "An ID which identifies publisher. Required when using a placementKey"
},
"placementKey": {
"type": "string",
"description": "An uniq name which identifies this placement of the impression. Must be used with publisherId"
},
"keyValues": {
"type": "object",
Expand All @@ -28,12 +32,13 @@
"type": "integer"
}
},
"required": [
"w",
"h"
],
"required": ["w", "h"],
"description": "Placement size"
}
},
"required": ["placementId"]
}
"oneOf": [{
"required": ["placementId"]
}, {
"required": ["publisherId", "placementKey"]
}]
}

0 comments on commit 19a69fe

Please sign in to comment.