github.com/prebid/prebid-server/v2@v2.18.0/exchange/gdpr.go (about) 1 package exchange 2 3 import ( 4 gpplib "github.com/prebid/go-gpp" 5 gppConstants "github.com/prebid/go-gpp/constants" 6 "github.com/prebid/prebid-server/v2/gdpr" 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 gppPolicy "github.com/prebid/prebid-server/v2/privacy/gpp" 9 ) 10 11 // getGDPR will pull the gdpr flag from an openrtb request 12 func getGDPR(req *openrtb_ext.RequestWrapper) (gdpr.Signal, error) { 13 if req.Regs != nil && len(req.Regs.GPPSID) > 0 { 14 if gppPolicy.IsSIDInList(req.Regs.GPPSID, gppConstants.SectionTCFEU2) { 15 return gdpr.SignalYes, nil 16 } 17 return gdpr.SignalNo, nil 18 } 19 re, err := req.GetRegExt() 20 if re == nil || re.GetGDPR() == nil || err != nil { 21 return gdpr.SignalAmbiguous, err 22 } 23 return gdpr.Signal(*re.GetGDPR()), nil 24 } 25 26 // getConsent will pull the consent string from an openrtb request 27 func getConsent(req *openrtb_ext.RequestWrapper, gpp gpplib.GppContainer) (consent string, err error) { 28 if i := gppPolicy.IndexOfSID(gpp, gppConstants.SectionTCFEU2); i >= 0 { 29 consent = gpp.Sections[i].GetValue() 30 return 31 } 32 ue, err := req.GetUserExt() 33 if ue == nil || ue.GetConsent() == nil || err != nil { 34 return 35 } 36 return *ue.GetConsent(), nil 37 } 38 39 // enforceGDPR determines if GDPR should be enforced based on the request signal and whether the channel is enabled 40 func enforceGDPR(signal gdpr.Signal, defaultValue gdpr.Signal, channelEnabled bool) bool { 41 gdprApplies := signal == gdpr.SignalYes || (signal == gdpr.SignalAmbiguous && defaultValue == gdpr.SignalYes) 42 return gdprApplies && channelEnabled 43 }