This project includes Go APIs for working with the IAB's GDPR Transparency & Consent Framework.
package main
import (
"log"
"github.com/prebid/go-gdpr/consentconstants"
"github.com/prebid/go-gdpr/vendorconsent"
)
func DemoConsentStringParsing() {
encodedString := "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw"
data, _ := base64.RawURLEncoding.DecodeString(encodedString)
consent, err := vendorconsent.Parse(data)
if err != nil {
log.Printf("Data was not a valid consent string: %v", err)
return
}
log.Printf("There are %d vendors in this consent string.", consent.MaxVendorID())
log.Printf("This consent string refers to version %d of the Global Vendor List.", consent.VendorListVersion())
log.Printf("Vendor %d has the user's consent? %t", 3, consent.VendorConsent(3))
}
package main
import (
"io/ioutil"
"log"
"net/http"
"github.com/prebid/go-gdpr/consentconstants"
"github.com/prebid/go-gdpr/vendorlist"
)
func DemoVendorListParsing() {
resp, _ := http.Get("https://vendorlist.consensu.org/vendorlist.json")
data, _ := ioutil.ReadAll(resp.Body)
vendors := vendorlist.ParseLazily(data)
log.Printf("The Vendor List Version is %d.", vendors.Version())
vendor := vendors.Vendor(3)
if vendor == nil {
log.Print("Vendor 3 did not exist in the list.")
} else {
log.Printf("Vendor 3 claimed a legitimate interest for ad selection, delivery, and reporting? %t", vendor.LegitimateInterest(consentconstants.AdSelectionDeliveryReporting))
log.Printf("Did Vendor 3 claim to store or retrieve info? %t", vendor.Purpose(consentconstants.InfoStorageAccess))
}
}
Pull Requests are always welcome for:
- Regression tests which demonstrate bugs
- Bugfixes which make regression tests pass
- Documentation improvements
- Improved error messages
- Support for parsing other fields of the Vendor Consent String. The only ones implemented now are ones which we needed.
- Support for other IAB-related GDPR standards, such as the Publisher Purposes Consent String
- Benchmarks
- Optimizations which don't break the unit tests and prove to be faster through the benchmarks.
Other pull requests may also be accepted, but larger features should probably be discussed in an Issue first.