usersync

package
v0.275.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 16 Imported by: 90

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSyncerEndpointRequired = errors.New("at least one endpoint (iframe and/or redirect) is required")
	ErrSyncerKeyRequired      = errors.New("key is required")
)

Functions

func BuildSyncers added in v0.173.0

func BuildSyncers(hostConfig *config.Configuration, bidderInfos config.BidderInfos) (map[string]Syncer, []error)

func SyncHostCookie added in v0.265.0

func SyncHostCookie(r *http.Request, requestCookie *Cookie, host *config.HostCookie)

SyncHostCookie syncs the request cookie with the host cookie

func WriteCookie added in v0.265.0

func WriteCookie(w http.ResponseWriter, encodedCookie string, cfg *config.HostCookie, setSiteCookie bool)

WriteCookie sets the prepared cookie onto the header

Types

type Base64Decoder added in v0.265.0

type Base64Decoder struct{}

func (Base64Decoder) Decode added in v0.265.0

func (d Base64Decoder) Decode(encodedValue string) *Cookie

type Base64Encoder added in v0.265.0

type Base64Encoder struct{}

func (Base64Encoder) Encode added in v0.265.0

func (e Base64Encoder) Encode(c *Cookie) (string, error)

type BidderEvaluation added in v0.173.0

type BidderEvaluation struct {
	Bidder    string
	SyncerKey string
	Status    Status
}

BidderEvaluation specifies which bidders were considered to be synced.

type BidderFilter added in v0.173.0

type BidderFilter interface {
	// Allowed returns true if the filter determines the bidder has permission and false if either
	// the bidder does not have permission or if the filter has an invalid mode.
	Allowed(bidder string) bool
}

BidderFilter determines if a bidder has permission to perform a user sync activity.

func NewSpecificBidderFilter added in v0.173.0

func NewSpecificBidderFilter(bidders []string, mode BidderFilterMode) BidderFilter

NewSpecificBidderFilter returns a new instance of the NewSpecificBidderFilter filter.

func NewUniformBidderFilter added in v0.173.0

func NewUniformBidderFilter(mode BidderFilterMode) BidderFilter

NewUniformBidderFilter returns a new instance of the UniformBidderFilter filter.

type BidderFilterMode added in v0.173.0

type BidderFilterMode int

BidderFilterMode represents the inclusion mode of a BidderFilter.

const (
	BidderFilterModeInclude BidderFilterMode = iota
	BidderFilterModeExclude
)

type Chooser added in v0.173.0

type Chooser interface {
	// Choose considers bidders to sync, filters the bidders, and returns the result of the
	// user sync selection.
	Choose(request Request, cookie *Cookie) Result
}

Chooser determines which syncers are eligible for a given request.

func NewChooser added in v0.173.0

func NewChooser(bidderSyncerLookup map[string]Syncer) Chooser

NewChooser returns a new instance of the standard chooser implementation.

type Cookie struct {
	// contains filtered or unexported fields
}

Cookie is the cookie used in Prebid Server.

To get an instance of this from a request, use ReadCookie. To write an instance onto a response, use WriteCookie.

func NewCookie added in v0.173.0

func NewCookie() *Cookie

NewCookie returns a new empty cookie.

func ReadCookie added in v0.265.0

func ReadCookie(r *http.Request, decoder Decoder, host *config.HostCookie) *Cookie

ReadCookie reads the cookie from the request

func (*Cookie) AllowSyncs added in v0.173.0

func (cookie *Cookie) AllowSyncs() bool

AllowSyncs is true if the user lets bidders sync cookies, and false otherwise.

func (*Cookie) GetUID added in v0.173.0

func (cookie *Cookie) GetUID(key string) (uid string, isUIDFound bool, isUIDActive bool)

GetUID Gets this user's ID for the given syncer key.

func (*Cookie) GetUIDs added in v0.173.0

func (cookie *Cookie) GetUIDs() map[string]string

GetUIDs returns this user's ID for all the bidders

func (*Cookie) HasAnyLiveSyncs added in v0.173.0

func (cookie *Cookie) HasAnyLiveSyncs() bool

HasAnyLiveSyncs returns true if this cookie has at least one active sync.

func (*Cookie) HasLiveSync added in v0.173.0

func (cookie *Cookie) HasLiveSync(key string) bool

HasLiveSync returns true if we have an active UID for the given syncer key, and false otherwise.

func (*Cookie) MarshalJSON added in v0.173.0

func (cookie *Cookie) MarshalJSON() ([]byte, error)

func (*Cookie) PrepareCookieForWrite added in v0.265.0

func (cookie *Cookie) PrepareCookieForWrite(cfg *config.HostCookie, encoder Encoder, ejector Ejector) (string, error)

PrepareCookieForWrite ejects UIDs as long as the cookie is too full

func (*Cookie) SetOptOut added in v0.173.0

func (cookie *Cookie) SetOptOut(optOut bool)

SetOptOut is used to change whether or not we're allowed to sync cookies for this user.

func (*Cookie) Sync added in v0.265.0

func (cookie *Cookie) Sync(key string, uid string) error

Sync tries to set the UID for some syncer key. It returns an error if the set didn't happen.

func (*Cookie) UnmarshalJSON added in v0.173.0

func (cookie *Cookie) UnmarshalJSON(b []byte) error

func (*Cookie) Unsync added in v0.173.0

func (cookie *Cookie) Unsync(key string)

Unsync removes the user's ID for the given syncer key from this cookie.

type Cooperative added in v0.173.0

type Cooperative struct {
	Enabled        bool
	PriorityGroups [][]string
}

Cooperative specifies the settings for cooperative syncing for a given request, where bidders other than those used by the publisher are considered for syncing.

type Decoder added in v0.265.0

type Decoder interface {
	// Decode takes an encoded string and decodes it into a cookie
	Decode(v string) *Cookie
}

type Ejector added in v0.275.0

type Ejector interface {
	Choose(uids map[string]UIDEntry) (string, error)
}

type Encoder added in v0.265.0

type Encoder interface {
	// Encode a cookie into a base 64 string
	Encode(c *Cookie) (string, error)
}

type OldestEjector added in v0.275.0

type OldestEjector struct{}

func (*OldestEjector) Choose added in v0.275.0

func (o *OldestEjector) Choose(uids map[string]UIDEntry) (string, error)

Choose method for oldest ejector will return the oldest uid

type PriorityBidderEjector added in v0.275.0

type PriorityBidderEjector struct {
	PriorityGroups   [][]string
	SyncersByBidder  map[string]Syncer
	IsSyncerPriority bool
	TieEjector       Ejector
}

func (*PriorityBidderEjector) Choose added in v0.275.0

func (p *PriorityBidderEjector) Choose(uids map[string]UIDEntry) (string, error)

Choose method for priority ejector will return the oldest lowest priority element

type Privacy added in v0.173.0

type Privacy interface {
	GDPRAllowsHostCookie() bool
	GDPRAllowsBidderSync(bidder string) bool
	CCPAAllowsBidderSync(bidder string) bool
	ActivityAllowsUserSync(bidder string) bool
}

Privacy determines which privacy policies will be enforced for a user sync request.

type Request added in v0.173.0

type Request struct {
	Bidders        []string
	Cooperative    Cooperative
	Limit          int
	Privacy        Privacy
	SyncTypeFilter SyncTypeFilter
}

Request specifies a user sync request.

type Result added in v0.173.0

type Result struct {
	BiddersEvaluated []BidderEvaluation
	Status           Status
	SyncersChosen    []SyncerChoice
}

Result specifies which bidders were included in the evaluation and which syncers were chosen.

type SpecificBidderFilter added in v0.173.0

type SpecificBidderFilter struct {
	// contains filtered or unexported fields
}

SpecificBidderFilter implements the BidderFilter which applies the same mode for a list of bidders.

func (SpecificBidderFilter) Allowed added in v0.173.0

func (f SpecificBidderFilter) Allowed(bidder string) bool

Allowed returns true if the bidder is specified and the mode is include or if the bidder is not specified and the mode is exclude and returns false in the opposite cases or when the mode is invalid.

type Status added in v0.173.0

type Status int

Status specifies the result of a sync evaluation.

const (
	// StatusOK specifies user syncing is permitted.
	StatusOK Status = iota

	// StatusBlockedByUserOptOut specifies a user's cookie explicitly signals an opt-out.
	StatusBlockedByUserOptOut

	// StatusBlockedByGDPR specifies a user's GDPR TCF consent explicitly forbids host cookies
	// or specific bidder syncing.
	StatusBlockedByGDPR

	// StatusBlockedByCCPA specifies a user's CCPA consent explicitly forbids bidder syncing.
	StatusBlockedByCCPA

	// StatusAlreadySynced specifies a user's cookie has an existing non-expired sync for a specific bidder.
	StatusAlreadySynced

	// StatusUnknownBidder specifies a requested bidder is unknown to Prebid Server.
	StatusUnknownBidder

	// StatusTypeNotSupported specifies a requested sync type is not supported by a specific bidder.
	StatusTypeNotSupported

	// StatusDuplicate specifies the bidder is a duplicate or shared a syncer key with another bidder choice.
	StatusDuplicate

	// StatusBlockedByPrivacy specifies a bidder sync url is not allowed by privacy activities
	StatusBlockedByPrivacy
)

type Sync added in v0.173.0

type Sync struct {
	URL         string
	Type        SyncType
	SupportCORS bool
}

Sync represents a user sync to be performed by the user's device.

type SyncType added in v0.173.0

type SyncType string

SyncType specifies the mechanism used to perform a user sync.

const (
	// SyncTypeUnknown specifies the user sync type is invalid or not specified.
	SyncTypeUnknown SyncType = ""

	// SyncTypeIFrame specifies the user sync is to be performed within an HTML iframe
	// and to expect the server to return a valid HTML page with an embedded script.
	SyncTypeIFrame SyncType = "iframe"

	// SyncTypeRedirect specifies the user sync is to be performed within an HTML image
	// and to expect the server to return a 302 redirect.
	SyncTypeRedirect SyncType = "redirect"
)

type SyncTypeFilter added in v0.173.0

type SyncTypeFilter struct {
	IFrame   BidderFilter
	Redirect BidderFilter
}

SyncTypeFilter determines which sync types, if any, the bidder is permitted to use.

func (SyncTypeFilter) ForBidder added in v0.173.0

func (t SyncTypeFilter) ForBidder(bidder string) []SyncType

ForBidder returns a slice of sync types the bidder is permitted to use.

type Syncer added in v0.173.0

type Syncer interface {
	// Key is the name of the syncer as stored in the user's cookie. This is often, but not
	// necessarily, a one-to-one mapping with a bidder.
	Key() string

	// DefaultSyncType is the default SyncType for this syncer.
	DefaultSyncType() SyncType

	// SupportsType returns true if the syncer supports at least one of the specified sync types.
	SupportsType(syncTypes []SyncType) bool

	// GetSync returns a user sync for the user's device to perform, or an error if the none of the
	// sync types are supported or if macro substitution fails.
	GetSync(syncTypes []SyncType, userSyncMacros macros.UserSyncPrivacy) (Sync, error)
}

Syncer represents the user sync configuration for a bidder or a shared set of bidders.

func NewSyncer added in v0.173.0

func NewSyncer(hostConfig config.UserSync, syncerConfig config.Syncer, bidder string) (Syncer, error)

NewSyncer creates a new Syncer from the provided configuration, or return an error if macro substition fails or an endpoint url is invalid.

type SyncerBuildError added in v0.173.0

type SyncerBuildError struct {
	Bidder    string
	SyncerKey string
	Err       error
}

SyncerBuildError represents an error with building a syncer.

func (SyncerBuildError) Error added in v0.173.0

func (e SyncerBuildError) Error() string

Error implements the standard error interface.

type SyncerChoice added in v0.173.0

type SyncerChoice struct {
	Bidder string
	Syncer Syncer
}

SyncerChoice specifies a syncer chosen.

type UIDEntry added in v0.265.0

type UIDEntry struct {
	// UID is the ID given to a user by a particular bidder
	UID string `json:"uid"`
	// Expires is the time at which this UID should no longer apply.
	Expires time.Time `json:"expires"`
}

UIDEntry bundles the UID with an Expiration date.

type UniformBidderFilter added in v0.173.0

type UniformBidderFilter struct {
	// contains filtered or unexported fields
}

UniformBidderFilter implements the BidderFilter interface which applies the same mode for all bidders.

func (UniformBidderFilter) Allowed added in v0.173.0

func (f UniformBidderFilter) Allowed(bidder string) bool

Allowed returns true if the mode is include and false if the mode is either exclude or invalid.

Jump to

Keyboard shortcuts

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