iab_tcf

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: MIT Imports: 6 Imported by: 0

README

iab-tcf CircleCI

Go code to parse IAB v1/v2 consent based on github.com/LiveRamp/iabconsent library.

This package is just a wrapper on their amazing work to fill our needs.

Usage

Install
go get github.com/hybridtheory/iab-tcf
Example
package main

import (
    "fmt"
    iab "github.com/hybridtheory/iab-tcf"
)

func main() {
    encoded := "COyt4MbOyt4MbMOAAAENAiCgAIAAAAAAAAAAADEAAgIAAAAAAAA.YAAAAAAAAAA"
    consent, err := iab.NewConsent(encoded)
}
CMP vendor list

In order to validate if the CMP received belongs to a valid id there's a loader integrated with the library.

package main

import (
    "fmt"
    iab "github.com/hybridtheory/iab-tcf"
    cmp "github.com/hybridtheory/iab-tcf/cmp"
)

func main() {
    cmp.NewLoader().LoadIDs()
    consent, err := iab.NewConsent(encoded)
    consent.IsCMPValid() // This will return true/false depending on the ids loaded.
}

If instead of the default vendor list https://cmplist.consensu.org/v2/cmp-list.json we want to use our own, we can use an option:

err := cmp.NewLoader(cmp.WithURL("https://example.com/cmp-list.json")).LoadIDs()

The format of the JSON must be the same.

If we want to use our own list of valid CMPs we can simply set the variable:

cmp.ValidCMPs = []int{1, 123}

Testing

We use Ginkgo and Gomega for testing purposes.

ginkgo ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeConsent

func DecodeConsent(consent string) ([]byte, error)

DecodeConsent receives a GDPR IAB consent string and decodes the CORE segment only, returning it. It also returns an error if something happened and we couldn't decode it.

func GetVersion

GetVersion extracts the version from the consent string, moving the data pointer so we don't have to reparse it.

func ParseV1

ParseV1 uses a consent reader to extract information from a TCF 1.0 version consent string.

func ParseV2

ParseV2 uses a consent reader to extract information from a TCF 2.0 version consent string.

Types

type Consent interface {
	// Version returns the version of this consent string.
	Version() int
	// CMPID returns the CMP ID of this consent string.
	CMPID() int
	// HasConsentedPurpose returns the consent value for a Purpose established on the legal basis of consent.
	// The Purposes are numerically identified and published in the Global Vendor List.
	HasConsentedPurpose(purposeID int) bool
	// GetConsentPurposeBitstring returns a string of 1 & 0 each of them representing the consent
	// given for a specific purposeID.
	// The first number is for the purposeID 1, the second number for the purposeID 2,
	// and so on.
	GetConsentPurposeBitstring() string
	// HasConsentedLegitimateInterestForPurpose returns the Purpose’s transparency requirements
	// are met for each Purpose on the legal basis of legitimate interest and the user has not
	// exercised their “Right to Object” to that Purpose.
	HasConsentedLegitimateInterestForPurpose(purposeID int) bool
	// HasUserConsented returns true if the user has given consent to the vendorID passed
	// as parameter.
	HasUserConsented(vendorID int) bool
	// HasUserLegitimateInterest returns true if the CMP has established transparency for a vendor's
	// legitimate interest disclosures. If a user exercises their “Right To Object” to a vendor’s
	// processing based on a legitimate interest, then it returns false.
	HasUserLegitimateInterest(vendorID int) bool
	// GetConsentBitstring returns a string of 1 & 0 each of them representing the consent
	// given for a specific vendorID.
	// The first number is for the vendorID 1, the second number for the vendorID 2,
	// and so on.
	GetConsentBitstring() string
	// GetInterestsBitstring returns a string of 1 & 0 each of them representing the
	// return of `HasUserLegitimateInterest` method for the vendorID in that position of the string.
	// The first number is for the vendorID 1, the second number for the vendorID 2,
	// and so on.
	GetInterestsBitstring() string
	// GetPublisherRestrictions returns a list of restrictions per publisher, if it relates.
	GetPublisherRestrictions() []*iabconsent.PubRestrictionEntry
	// IsCMPListLoaded returns if the list of valid CMPs was properly loaded or not.
	IsCMPListLoaded() bool
	// IsCMPValid validates the consent string CMP ID agains the list of valid ones downloaded from IAB.
	IsCMPValid() bool
}

Consent is an interface to retrieve the most important information from consent strings, no matter if they are v1 or v2.

func NewConsent

func NewConsent(consent string) (Consent, error)

NewConsent returns a Consent instance with all the necessary information available. It returns an error if something went wrong.

func NewConsentV1

func NewConsentV1(reader *iabconsent.ConsentReader) (Consent, error)

NewConsentV1 returns a consent interface from the reader received, with an error if something went wrong.

func NewConsentV2

func NewConsentV2(reader *iabconsent.ConsentReader) (Consent, error)

NewConsentV2 returns a consent interface from the reader received, with an error if something went wrong.

type ConsentV1

type ConsentV1 struct {
	*cmp.Consent
	ParsedConsent *iabconsent.ParsedConsent
}

ConsentV1 is an implementation of the Consent interface used to retrieve consent information given a TCF 1.0 format.

func (*ConsentV1) CMPID added in v0.3.0

func (c *ConsentV1) CMPID() int

CMPID returns the CMP ID of this consent string.

func (*ConsentV1) GetConsentBitstring

func (c *ConsentV1) GetConsentBitstring() string

GetConsentBitstring returns a string of 1 & 0 each of them representing the consent given for a specific vendorID (the first number is for the vendorID 1, and so on).

func (*ConsentV1) GetConsentPurposeBitstring

func (c *ConsentV1) GetConsentPurposeBitstring() string

GetConsentPurposeBitstring returns a string of 1 & 0 each of them representing the consent given for a specific purposeID.

func (*ConsentV1) GetInterestsBitstring

func (c *ConsentV1) GetInterestsBitstring() string

GetInterestsBitstring returns an empty string always because consent TFC 1.0 doesn't implement user legitimate interests.

func (*ConsentV1) GetPublisherRestrictions

func (c *ConsentV1) GetPublisherRestrictions() []*iabconsent.PubRestrictionEntry

GetPublisherRestrictions returns an empty list because consent TFC 1.0 doesn't implement user legitimate interests.

func (*ConsentV1) HasConsentedLegitimateInterestForPurpose

func (c *ConsentV1) HasConsentedLegitimateInterestForPurpose(purposeID int) bool

HasConsentedLegitimateInterestForPurpose returns always true because consent TFC 1.0 doesn't come with this information.

func (*ConsentV1) HasConsentedPurpose

func (c *ConsentV1) HasConsentedPurpose(purposeID int) bool

HasConsentedPurpose returns always true because consent TFC 1.0 doesn't come with this information.

func (*ConsentV1) HasUserConsented

func (c *ConsentV1) HasUserConsented(vendorID int) bool

HasUserConsented returns true if the user has given consent to the vendorID passed as parameter.

func (*ConsentV1) HasUserLegitimateInterest

func (c *ConsentV1) HasUserLegitimateInterest(vendorID int) bool

HasUserLegitimateInterest returns always true because consent TFC 1.0 doesn't come with this information.

func (*ConsentV1) IsCMPValid added in v0.3.0

func (c *ConsentV1) IsCMPValid() bool

IsCMPValid validates the consent string CMP ID agains the list of valid ones downloaded from IAB.

func (*ConsentV1) Version

func (c *ConsentV1) Version() int

Version returns the version of this consent string.

type ConsentV2

type ConsentV2 struct {
	cmp.Consent
	ParsedConsent *iabconsent.V2ParsedConsent
}

ConsentV2 is an implementation of the Consent interface used to retrieve consent information given a TCF 1.0 format.

func (*ConsentV2) CMPID added in v0.3.0

func (c *ConsentV2) CMPID() int

CMPID returns the CMP ID of this consent string.

func (*ConsentV2) GetConsentBitstring

func (c *ConsentV2) GetConsentBitstring() string

GetConsentBitstring returns a string of 1 & 0 each of them representing the consent given for a specific vendorID (the first number is for the vendorID 1, and so on).

func (*ConsentV2) GetConsentPurposeBitstring

func (c *ConsentV2) GetConsentPurposeBitstring() string

GetConsentPurposeBitstring returns a string of 1 & 0 each of them representing the consent given for a specific purposeID.

func (*ConsentV2) GetInterestsBitstring

func (c *ConsentV2) GetInterestsBitstring() string

GetInterestsBitstring returns a string of 1 & 0 each of them representing the user's interest to `Right To Object` for a specific vendorID (the first number is for the vendorID 1, and so on).

func (*ConsentV2) GetPublisherRestrictions

func (c *ConsentV2) GetPublisherRestrictions() []*iabconsent.PubRestrictionEntry

GetPublisherRestrictions returns a list of restrictions per publisher, if it relates.

func (*ConsentV2) HasConsentedLegitimateInterestForPurpose

func (c *ConsentV2) HasConsentedLegitimateInterestForPurpose(purposeID int) bool

HasConsentedLegitimateInterestForPurpose returns the Purpose’s transparency requirements are met for each Purpose on the legal basis of legitimate interest and the user has not exercised their “Right to Object” to that Purpose.

func (*ConsentV2) HasConsentedPurpose

func (c *ConsentV2) HasConsentedPurpose(purposeID int) bool

HasConsentedPurpose returns the consent value for a Purpose established on the legal basis of consent. The Purposes are numerically identified and published in the Global Vendor List.

func (*ConsentV2) HasUserConsented

func (c *ConsentV2) HasUserConsented(vendorID int) bool

HasUserConsented returns true if the user has given consent to the vendorID passed as parameter.

func (*ConsentV2) HasUserLegitimateInterest

func (c *ConsentV2) HasUserLegitimateInterest(vendorID int) bool

HasUserLegitimateInterest returns true if the CMP has established transparency for a vendor's legitimate interest disclosures. If a user exercises their “Right To Object” to a vendor’s processing based on a legitimate interest, then it returns false.

func (*ConsentV2) IsCMPValid added in v0.3.0

func (c *ConsentV2) IsCMPValid() bool

IsCMPValid validates the consent string CMP ID agains the list of valid ones downloaded from IAB.

func (*ConsentV2) Version

func (c *ConsentV2) Version() int

Version returns the version of this consent string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL