bidrequest

package
v0.0.0-...-277150b Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBidRequestNil        = errors.New("bid request is nil")
	ErrCategoryIsNotMatched = errors.New("category is not matched")
)

Functions

This section is empty.

Types

type AdFormats

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

func (*AdFormats) Add

func (a *AdFormats) Add(format *types.Format) bool

func (*AdFormats) Bitset

func (a *AdFormats) Bitset() *searchtypes.NumberBitset[uint]

func (*AdFormats) List

func (a *AdFormats) List() []*types.Format

func (*AdFormats) Reset

func (a *AdFormats) Reset()

func (*AdFormats) TypeMask

func (a *AdFormats) TypeMask() types.FormatTypeBitset

type BidRequest

type BidRequest struct {
	IDVal    string    `json:"id,omitempty"`       // Auction ID
	ExtID    string    `json:"bidid,omitempty"`    // External Auction ID
	Timemark time.Time `json:"timemark,omitempty"` // Timestamp of the request

	Ctx   context.Context `json:"-"`               // Context for request handling
	Debug bool            `json:"debug,omitempty"` // Debug mode flag

	// Source of the request
	AccessPointLnk adtype.AccessPoint `json:"-"` // Access point information

	AucType    types.AuctionType      `json:"auction_type,omitempty"` // Type of auction
	RequestCtx *fasthttp.RequestCtx   `json:"-"`                      // HTTP request context
	Request    any                    `json:"-"`                      // Original request from RTB or another protocol
	Person     personification.Person `json:"-"`                      // Personification data
	Imps       []*adtype.Impression   `json:"imps,omitempty"`         // List of impressions

	AppTarget  *admodels.Application `json:"app_target,omitempty"` // Target application
	Device     *udetect.Device       `json:"device,omitempty"`     // Device information
	App        *udetect.App          `json:"app,omitempty"`        // App information
	Site       *udetect.Site         `json:"site,omitempty"`       // Site information
	User       *adtype.User          `json:"user,omitempty"`       // User information
	StateFlags BidRequestFlags       `json:"flags"`                // State flags for the request
	Ext        map[string]any        `json:"ext,omitempty"`        // Additional extensions
	Tracer     any                   `json:"-"`                    // Tracing information
	// contains filtered or unexported fields
}

BidRequest represents a bid request in the ad system. It contains all necessary information for processing an ad bid.

func (*BidRequest) AccessPoint

func (r *BidRequest) AccessPoint() adtype.AccessPoint

AccessPoint returns the access point associated with the BidRequest.

func (*BidRequest) Age

func (r *BidRequest) Age() uint

Age of the user

func (*BidRequest) AppID

func (r *BidRequest) AppID() uint64

AppID returns the ID of the target application. Returns 0 if the app target is unavailable.

func (*BidRequest) AppInfo

func (r *BidRequest) AppInfo() *udetect.App

AppInfo returns the application information associated with the BidRequest.

func (*BidRequest) AuctionID

func (r *BidRequest) AuctionID() string

AuctionID returns the auction ID of the BidRequest.

func (*BidRequest) AuctionType

func (r *BidRequest) AuctionType() types.AuctionType

AuctionType returns the type of auction for the BidRequest.

func (*BidRequest) BrowserInfo

func (r *BidRequest) BrowserInfo() *udetect.Browser

BrowserInfo returns the browser information associated with the BidRequest.

func (*BidRequest) CarrierInfo

func (r *BidRequest) CarrierInfo() *udetect.Carrier

CarrierInfo returns the carrier information associated with the user's geography.

func (*BidRequest) Categories

func (r *BidRequest) Categories() []uint64

Categories returns a slice of category IDs associated with the BidRequest. Currently, it returns the cached categoryArray. (Note: The implementation is incomplete and commented out for future development.)

func (*BidRequest) Clone

func (r *BidRequest) Clone() *BidRequest

Clone creates and returns a shallow copy of the BidRequest.

func (*BidRequest) Context

func (r *BidRequest) Context() context.Context

Context returns the context associated with the BidRequest.

func (*BidRequest) CurrentGeoTime

func (r *BidRequest) CurrentGeoTime() time.Time

CurrentGeoTime returns the current time adjusted to the geographical location of the user.

func (*BidRequest) DeviceInfo

func (r *BidRequest) DeviceInfo() *udetect.Device

DeviceInfo returns the device information associated with the BidRequest. It initializes default values if device, browser, or OS information is missing.

func (*BidRequest) Domain

func (r *BidRequest) Domain() []string

Domain returns a list of domains associated with the site or app. It prepares the domain list by aggregating from Site and App information.

func (*BidRequest) DomainName

func (r *BidRequest) DomainName() string

DomainName returns the primary domain name of the site or the bundle name of the app.

func (*BidRequest) Done

func (r *BidRequest) Done() <-chan struct{}

Done returns a channel that is closed when the context of the BidRequest is done.

func (*BidRequest) ExtTargetIDs

func (r *BidRequest) ExtTargetIDs() []string

ExtTargetIDs returns a slice of unique external target IDs from all impressions.

func (*BidRequest) ExternalAuctionID

func (r *BidRequest) ExternalAuctionID() string

ExternalAuctionID returns the external auction ID of the BidRequest.

func (*BidRequest) ExternalID

func (r *BidRequest) ExternalID() string

ExternalID returns the external ID of the BidRequest.

func (*BidRequest) Formats

func (r *BidRequest) Formats() types.BidFormater

Formats returns the list of formats associated with the BidRequest. If the formats slice is empty, it aggregates formats from all impressions.

func (*BidRequest) GeoID

func (r *BidRequest) GeoID() uint64

GeoID returns the geographical ID associated with the BidRequest.

func (*BidRequest) GeoInfo

func (r *BidRequest) GeoInfo() *udetect.Geo

GeoInfo returns the geographical information associated with the BidRequest.

func (*BidRequest) Get

func (r *BidRequest) Get(key string) any

Get retrieves a value from the BidRequest's extension map by key. Returns nil if the key does not exist.

func (*BidRequest) HTTPRequest

func (r *BidRequest) HTTPRequest() *fasthttp.RequestCtx

HTTPRequest returns the underlying HTTP request context.

func (*BidRequest) ID

func (r *BidRequest) ID() string

ID returns the unique ID of the BidRequest.

func (*BidRequest) ImpressionByID

func (r *BidRequest) ImpressionByID(id string) *adtype.Impression

ImpressionByID returns a pointer to the Impression with the specified ID. Returns nil if no matching impression is found.

func (*BidRequest) ImpressionUpdate

func (r *BidRequest) ImpressionUpdate(fn func(imp *adtype.Impression) bool)

ImpressionUpdate applies a provided function to each impression in the BidRequest. If the function returns true, the impression is updated.

func (*BidRequest) Impressions

func (r *BidRequest) Impressions() []*adtype.Impression

Impressions returns a slice of impressions associated with the BidRequest.

func (*BidRequest) IsAdBlock

func (r *BidRequest) IsAdBlock() bool

IsAdBlock checks if the user has an ad blocker enabled.

func (*BidRequest) IsDebug

func (r *BidRequest) IsDebug() bool

IsDebug checks if the BidRequest is in debug mode.

func (*BidRequest) IsIPv6

func (r *BidRequest) IsIPv6() bool

IsIPv6 checks if the user's IP address is IPv6.

func (*BidRequest) IsNil

func (r *BidRequest) IsNil() bool

IsNil reports whether the BidRequest pointer is nil. Safe to call on a nil receiver.

func (*BidRequest) IsPrivateBrowsing

func (r *BidRequest) IsPrivateBrowsing() bool

IsPrivateBrowsing checks if the user is in private browsing mode.

func (*BidRequest) IsProxy

func (r *BidRequest) IsProxy() bool

IsProxy checks if the user is using a proxy.

func (*BidRequest) IsRobot

func (r *BidRequest) IsRobot() bool

IsRobot checks if the user is a robot.

func (*BidRequest) IsSecure

func (r *BidRequest) IsSecure() bool

IsSecure checks if the request is made over a secure connection.

func (*BidRequest) Keywords

func (r *BidRequest) Keywords() []string

Keywords returns a slice of keywords associated with the user. Returns nil if user information is unavailable.

func (*BidRequest) LanguageID

func (r *BidRequest) LanguageID() uint64

LanguageID returns the language ID based on the primary language of the browser.

func (*BidRequest) MinECPM

func (r *BidRequest) MinECPM() (minBid billing.Money)

MinECPM calculates and returns the minimum ECPM (Effective Cost Per Mille) acceptable for the BidRequest. It iterates through all impressions and selects the highest bid floor.

func (*BidRequest) OSInfo

func (r *BidRequest) OSInfo() *udetect.OS

OSInfo returns the operating system information associated with the BidRequest.

func (*BidRequest) PrepareRequest

func (r *BidRequest) PrepareRequest(defaultCategoryID uint64, categoryMapper CategoryMatcher) error

PrepareRequest prepares the bid request by extracting categories and tags from the user and site information.

func (*BidRequest) PrepareWithFormats

func (r *BidRequest) PrepareWithFormats(formats types.FormatsAccessor) adtype.BidRequester

PrepareWithFormats prepares the BidRequest by initializing formats for each impression using the provided FormatsAccessor. It resets any existing formats and aggregates formats from all impressions into the BidRequest's formats.

func (*BidRequest) ProjectID

func (r *BidRequest) ProjectID() uint64

ProjectID returns the Project ID associated with the BidRequest. Currently returns 0 as a placeholder.

func (*BidRequest) Release

func (r *BidRequest) Release()

Release releases any resources associated with the BidRequest. If the original request implements the releaser interface, it calls the Release method.

func (*BidRequest) ServiceDomain

func (r *BidRequest) ServiceDomain() string

ServiceDomain returns the domain of the service handling the request.

func (*BidRequest) Set

func (r *BidRequest) Set(key string, val any)

Set sets a key-value pair in the BidRequest's extension map.

func (*BidRequest) SetContext

func (r *BidRequest) SetContext(ctx context.Context)

SetContext sets the context for the BidRequest.

func (*BidRequest) SetSourceFilter

func (r *BidRequest) SetSourceFilter(ids ...uint64)

SetSourceFilter sets the source filter IDs for the BidRequest. It replaces any existing source IDs with the provided ones.

func (*BidRequest) Sex

func (r *BidRequest) Sex() uint

Sex returns the user's sex as an unsigned integer. Returns 0 if user information is unavailable.

func (*BidRequest) SiteInfo

func (r *BidRequest) SiteInfo() *udetect.Site

SiteInfo returns the site information associated with the BidRequest. If the site is unavailable, it returns the default site information. Returns nil if neither site nor app information is available.

func (*BidRequest) Size

func (r *BidRequest) Size() (w, h int)

Size returns the width and height of the browser's visible area

func (*BidRequest) SourceFilterCheck

func (r *BidRequest) SourceFilterCheck(id uint64) bool

SourceFilterCheck checks if a given source ID is allowed by the current filter. Returns true if no filter is set or if the ID is present in the filter.

func (*BidRequest) String

func (r *BidRequest) String() (res string)

String implements the fmt.Stringer interface for BidRequest. It returns a pretty-printed JSON representation of the BidRequest. If marshalling fails, it returns an error message in JSON format.

func (*BidRequest) Tags

func (r *BidRequest) Tags() []string

Tags returns a list of tags associated with the BidRequest. It aggregates keywords from the user and site information.

func (*BidRequest) TargetID

func (r *BidRequest) TargetID() uint64

TargetID returns the target ID if there is exactly one impression with a target. Otherwise, returns 0.

func (*BidRequest) TargetIDs

func (r *BidRequest) TargetIDs() []uint64

TargetIDs returns a slice of unique target IDs from all impressions.

func (*BidRequest) TargetPointers

func (r *BidRequest) TargetPointers() []types.TargetPointer

TargetPointers returns a slice of TargetPointer interfaces for each impression in the BidRequest.

func (*BidRequest) Time

func (r *BidRequest) Time() time.Time

Time returns the timestamp of the BidRequest.

func (*BidRequest) TrafficSourceID

func (r *BidRequest) TrafficSourceID() uint64

TrafficSourceID returns the ID of the traffic source associated with the BidRequest. Returns 0 if the traffic source information is unavailable. (Direct by default)

func (*BidRequest) Unset

func (r *BidRequest) Unset(keys ...string)

Unset removes one or more keys from the BidRequest's extension map.

func (*BidRequest) UserInfo

func (r *BidRequest) UserInfo() *adtype.User

UserInfo returns the user information associated with the BidRequest. It initializes default values if user or geographical information is missing.

func (*BidRequest) Validate

func (r *BidRequest) Validate() error

Validate performs validation on the BidRequest. Currently, it always returns nil, but can be extended to include validation logic.

func (*BidRequest) WithFormats

func (r *BidRequest) WithFormats(formats types.FormatsAccessor) adtype.BidRequester

WithFormats sets the formats accessor for the BidRequest and returns the updated BidRequest.

type BidRequestFlags

type BidRequestFlags uint8

BidRequestFlags defines flags for bid requests.

const (
	// BidRequestFlagAdBlock indicates if adblock is enabled
	BidRequestFlagAdBlock BidRequestFlags = 1 << iota
	// BidRequestFlagPrivateBrowsing indicates if private browsing is enabled
	BidRequestFlagPrivateBrowsing
	// BidRequestFlagSecure indicates if the request is secure
	BidRequestFlagSecure
	// BidRequestFlagBot indicates if the request is from a bot
	BidRequestFlagBot
	// BidRequestFlagProxy indicates if the request is from a proxy
	BidRequestFlagProxy
)

type BidTargetWrapper

type BidTargetWrapper struct {
	BidReq *BidRequest
	Imp    *adtype.Impression
}

BidTargetWrapper wraps a BidRequest and an adtype.Impression together to implement types.TargetPointer. Methods that are impression-specific (Size, TargetID, IsInterstitial) are resolved from Imp; all others delegate to BidReq.

func (*BidTargetWrapper) Age

func (b *BidTargetWrapper) Age() uint

Age returns the estimated age of the user in years.

func (*BidTargetWrapper) AppID

func (b *BidTargetWrapper) AppID() uint64

AppID returns the target application ID.

func (*BidTargetWrapper) AppInfo

func (b *BidTargetWrapper) AppInfo() *types.AppInfo

AppInfo returns metadata about the target application.

func (*BidTargetWrapper) AuctionType

func (b *BidTargetWrapper) AuctionType() types.AuctionType

AuctionType implements types.TargetPointer.

func (*BidTargetWrapper) BrowserInfo

func (b *BidTargetWrapper) BrowserInfo() *types.BrowserInfo

BrowserInfo returns the detected browser metadata.

func (*BidTargetWrapper) CarrierInfo

func (b *BidTargetWrapper) CarrierInfo() *types.CarrierInfo

CarrierInfo returns the mobile carrier metadata.

func (*BidTargetWrapper) Categories

func (b *BidTargetWrapper) Categories() []uint64

Categories returns the IAB content category IDs of the request.

func (*BidTargetWrapper) CountryCode

func (b *BidTargetWrapper) CountryCode() string

CountryCode implements types.TargetPointer.

func (*BidTargetWrapper) CurrentGeoTime

func (b *BidTargetWrapper) CurrentGeoTime() time.Time

CurrentGeoTime returns the current wall-clock time adjusted to the user's geo timezone.

func (*BidTargetWrapper) DeviceInfo

func (b *BidTargetWrapper) DeviceInfo() *types.DeviceInfo

DeviceInfo returns the full device metadata.

func (*BidTargetWrapper) Domain

func (b *BidTargetWrapper) Domain() []string

Domain returns the list of domains associated with the request.

func (*BidTargetWrapper) DomainName

func (b *BidTargetWrapper) DomainName() string

DomainName returns the primary domain or app bundle name.

func (*BidTargetWrapper) ExtarnalTargetID

func (b *BidTargetWrapper) ExtarnalTargetID() string

ExtarnalTargetID implements types.TargetPointer.

func (*BidTargetWrapper) Formats

func (b *BidTargetWrapper) Formats() types.BidFormater

Formats returns the ad formats available in the bid request.

func (*BidTargetWrapper) GeoID

func (b *BidTargetWrapper) GeoID() uint64

GeoID returns the geographic region ID of the user.

func (*BidTargetWrapper) GeoInfo

func (b *BidTargetWrapper) GeoInfo() *types.GeoInfo

GeoInfo returns the full geographic metadata of the user.

func (*BidTargetWrapper) IsAdBlock

func (b *BidTargetWrapper) IsAdBlock() bool

IsAdBlock returns true if an ad-blocker was detected on the client.

func (*BidTargetWrapper) IsDebug

func (b *BidTargetWrapper) IsDebug() bool

IsDebug returns true if the request is in debug mode.

func (*BidTargetWrapper) IsIPv6

func (b *BidTargetWrapper) IsIPv6() bool

IsIPv6 returns true if the client is connected over IPv6.

func (*BidTargetWrapper) IsInterstitial

func (b *BidTargetWrapper) IsInterstitial() bool

IsInterstitial returns true if the impression slot is interstitial (full-screen). The value is read from Imp, not from BidReq.

func (*BidTargetWrapper) IsPrivateBrowsing

func (b *BidTargetWrapper) IsPrivateBrowsing() bool

IsPrivateBrowsing returns true if the request originates from a private / incognito session.

func (*BidTargetWrapper) IsProxy

func (b *BidTargetWrapper) IsProxy() bool

IsProxy returns true if a proxy or VPN was detected.

func (*BidTargetWrapper) IsRobot

func (b *BidTargetWrapper) IsRobot() bool

IsRobot returns true if the client was identified as a bot or crawler.

func (*BidTargetWrapper) IsSecure

func (b *BidTargetWrapper) IsSecure() bool

IsSecure returns true if the request was made over HTTPS.

func (*BidTargetWrapper) LanguageCode

func (b *BidTargetWrapper) LanguageCode() string

LanguageCode implements types.TargetPointer.

func (*BidTargetWrapper) LanguageID

func (b *BidTargetWrapper) LanguageID() uint64

LanguageID returns the browser language ID.

func (*BidTargetWrapper) MinECPM

func (b *BidTargetWrapper) MinECPM() billing.Money

MinECPM returns the minimum effective CPM floor for this request.

func (*BidTargetWrapper) OSInfo

func (b *BidTargetWrapper) OSInfo() *types.OSInfo

OSInfo returns the detected operating system metadata.

func (*BidTargetWrapper) Sex

func (b *BidTargetWrapper) Sex() uint

Sex returns the inferred sex of the user.

func (*BidTargetWrapper) SiteInfo

func (b *BidTargetWrapper) SiteInfo() *types.SiteInfo

SiteInfo returns the site metadata associated with the request.

func (*BidTargetWrapper) Size

func (b *BidTargetWrapper) Size() (w, h int)

Size returns the width and height of the impression slot. The value is read from Imp, not from BidReq.

func (*BidTargetWrapper) Tags

func (b *BidTargetWrapper) Tags() []string

Tags returns the targeting tag list associated with the request.

func (*BidTargetWrapper) TargetID

func (b *BidTargetWrapper) TargetID() uint64

TargetID returns the ID of the specific ad zone / placement target. Returns 0 if the wrapper, impression, or target is nil. The value is read from Imp.Target, not from BidReq.

func (*BidTargetWrapper) Time

func (b *BidTargetWrapper) Time() time.Time

Time returns the wall-clock time at which the bid request started.

func (*BidTargetWrapper) TrafficSourceID

func (b *BidTargetWrapper) TrafficSourceID() uint64

TrafficSourceID returns the ID of the traffic source that delivered the request.

type CategoryMatcher

type CategoryMatcher interface {
	MatchCategoryID(key string) uint64
	MatchCategoryIDFromKeyword(keyword string) uint64
}

type ServerCounter

type ServerCounter interface {
	Value() uint64
}

Jump to

Keyboard shortcuts

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