Skip to content

Commit

Permalink
GPP passthrough for cookiesync (#2575)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhjort authored Feb 13, 2023
1 parent 4109b90 commit 543f288
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 6 deletions.
6 changes: 4 additions & 2 deletions config/bidderinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Syncer struct {
// In most cases, bidders will specify a URL with a `{{.RedirectURL}}` macro for the call back to
// Prebid Server and a UserMacro which the bidder server will replace with the user's id. Example:
//
// url: "https://sync.bidderserver.com/usersync?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&redirect={{.RedirectURL}}"
// url: "https://sync.bidderserver.com/usersync?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&redirect={{.RedirectURL}}"
// userMacro: "$UID"
//
// Prebid Server is configured with a default RedirectURL template matching the /setuid call. This
Expand All @@ -152,6 +152,8 @@ type SyncerEndpoint struct {
// {{.GDPR}} - This will be replaced with the "gdpr" property sent to /cookie_sync.
// {{.Consent}} - This will be replaced with the "consent" property sent to /cookie_sync.
// {{.USPrivacy}} - This will be replaced with the "us_privacy" property sent to /cookie_sync.
// {{.GPP}} - This will be replaced with the "gpp" property sent to /cookie_sync.
// {{.GPPSID}} - This will be replaced with the "gpp_sid" property sent to /cookie_sync.
URL string `yaml:"url" mapstructure:"url"`

// RedirectURL is an endpoint on the host server the user will be redirected to when a user sync
Expand All @@ -165,7 +167,7 @@ type SyncerEndpoint struct {
// {{.UserMacro}} - This will be replaced with the bidder server's user id macro.
//
// The endpoint on the host server is usually Prebid Server's /setuid endpoint. The default value is:
// `{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&f={{.SyncType}}&uid={{.UserMacro}}`
// `{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&f={{.SyncType}}&uid={{.UserMacro}}`
RedirectURL string `yaml:"redirectUrl" mapstructure:"redirect_url"`

// ExternalURL is available as a macro to the RedirectURL template. If not specified, either the syncer configuration
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {

// some adapters append the user id to the end of the redirect url instead of using
// macro substitution. it is important for the uid to be the last query parameter.
v.SetDefault("user_sync.redirect_url", "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&f={{.SyncType}}&uid={{.UserMacro}}")
v.SetDefault("user_sync.redirect_url", "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&f={{.SyncType}}&uid={{.UserMacro}}")

v.SetDefault("max_request_size", 1024*256)
v.SetDefault("analytics.file.filename", "")
Expand Down
7 changes: 7 additions & 0 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/prebid/prebid-server/privacy"
"github.com/prebid/prebid-server/privacy/ccpa"
gdprPrivacy "github.com/prebid/prebid-server/privacy/gdpr"
gppPrivacy "github.com/prebid/prebid-server/privacy/gpp"
"github.com/prebid/prebid-server/stored_requests"
"github.com/prebid/prebid-server/usersync"
)
Expand Down Expand Up @@ -154,6 +155,10 @@ func (c *cookieSyncEndpoint) parseRequest(r *http.Request) (usersync.Request, pr
CCPA: ccpa.Policy{
Consent: request.USPrivacy,
},
GPP: gppPrivacy.Policy{
Consent: request.GPP,
RawSID: request.GPPSid,
},
}

ccpaParsedPolicy := ccpa.ParsedPolicy{}
Expand Down Expand Up @@ -398,6 +403,8 @@ type cookieSyncRequest struct {
GDPRConsent string `json:"gdpr_consent"`
USPrivacy string `json:"us_privacy"`
Limit int `json:"limit"`
GPP string `json:"gpp"`
GPPSid string `json:"gpp_sid"`
CooperativeSync *bool `json:"coopSync"`
FilterSettings *cookieSyncRequestFilterSettings `json:"filterSettings"`
Account string `json:"account"`
Expand Down
7 changes: 7 additions & 0 deletions endpoints/cookie_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/prebid/prebid-server/privacy"
"github.com/prebid/prebid-server/privacy/ccpa"
gdprPrivacy "github.com/prebid/prebid-server/privacy/gdpr"
gppPrivacy "github.com/prebid/prebid-server/privacy/gpp"
"github.com/prebid/prebid-server/usersync"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -324,6 +325,8 @@ func TestCookieSyncParseRequest(t *testing.T) {
`"gdpr":1,` +
`"gdpr_consent":"anyGDPRConsent",` +
`"us_privacy":"1NYN",` +
`"gpp":"anyGPPString",` +
`"gpp_sid":"2",` +
`"limit":42,` +
`"coopSync":true,` +
`"filterSettings":{"iframe":{"bidders":"*","filter":"include"}, "image":{"bidders":["b"],"filter":"exclude"}}` +
Expand All @@ -344,6 +347,10 @@ func TestCookieSyncParseRequest(t *testing.T) {
CCPA: ccpa.Policy{
Consent: "1NYN",
},
GPP: gppPrivacy.Policy{
Consent: "anyGPPString",
RawSID: "2",
},
},
expectedRequest: usersync.Request{
Bidders: []string{"a", "b"},
Expand Down
2 changes: 2 additions & 0 deletions macros/macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type UserSyncTemplateParams struct {
GDPR string
GDPRConsent string
USPrivacy string
GPP string
GPPSID string
}

// ResolveMacros resolves macros in the given template with the provided params
Expand Down
8 changes: 8 additions & 0 deletions privacy/gpp/gpp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gpp

// Policy represents the GPP privacy string container.
// Currently just a placeholder until more expansive support is made.
type Policy struct {
Consent string
RawSID string // This is the CSV format ("2,6") that the IAB recommends for passing the SID(s) on a query string.
}
2 changes: 2 additions & 0 deletions privacy/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package privacy
import (
"github.com/prebid/prebid-server/privacy/ccpa"
"github.com/prebid/prebid-server/privacy/gdpr"
"github.com/prebid/prebid-server/privacy/gpp"
"github.com/prebid/prebid-server/privacy/lmt"
)

Expand All @@ -11,4 +12,5 @@ type Policies struct {
CCPA ccpa.Policy
GDPR gdpr.Policy
LMT lmt.Policy
GPP gpp.Policy
}
2 changes: 2 additions & 0 deletions usersync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ func (s standardSyncer) GetSync(syncTypes []SyncType, privacyPolicies privacy.Po
GDPR: privacyPolicies.GDPR.Signal,
GDPRConsent: privacyPolicies.GDPR.Consent,
USPrivacy: privacyPolicies.CCPA.Consent,
GPP: privacyPolicies.GPP.Consent,
GPPSID: privacyPolicies.GPP.RawSID,
})
if err != nil {
return Sync{}, err
Expand Down
6 changes: 3 additions & 3 deletions usersync/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestBuildTemplate(t *testing.T) {
key = "anyKey"
syncTypeValue = "x"
hostConfig = config.UserSync{ExternalURL: "http://host.com", RedirectURL: "{{.ExternalURL}}/host"}
macroValues = macros.UserSyncTemplateParams{GDPR: "A", GDPRConsent: "B", USPrivacy: "C"}
macroValues = macros.UserSyncTemplateParams{GDPR: "A", GDPRConsent: "B", USPrivacy: "C", GPP: "D", GPPSID: "1"}
)

testCases := []struct {
Expand All @@ -199,11 +199,11 @@ func TestBuildTemplate(t *testing.T) {
description: "All Composed Macros",
givenSyncerEndpoint: config.SyncerEndpoint{
URL: "https://bidder.com/sync?redirect={{.RedirectURL}}",
RedirectURL: "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&f={{.SyncType}}&gdpr={{.GDPR}}&uid={{.UserMacro}}",
RedirectURL: "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&f={{.SyncType}}&gdpr={{.GDPR}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&uid={{.UserMacro}}",
ExternalURL: "http://syncer.com",
UserMacro: "$UID$",
},
expectedRendered: "https://bidder.com/sync?redirect=http%3A%2F%2Fsyncer.com%2Fsetuid%3Fbidder%3DanyKey%26f%3Dx%26gdpr%3DA%26uid%3D%24UID%24",
expectedRendered: "https://bidder.com/sync?redirect=http%3A%2F%2Fsyncer.com%2Fsetuid%3Fbidder%3DanyKey%26f%3Dx%26gdpr%3DA%26gpp%3DD%26gpp_sid%3D1%26uid%3D%24UID%24",
},
{
description: "Redirect URL + External URL From Host",
Expand Down

0 comments on commit 543f288

Please sign in to comment.