rtbrules

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aplicable

type Aplicable int8
const (
	Exclude Aplicable = -1
	Any     Aplicable = 0
	Include Aplicable = 1
)

func (Aplicable) MarshalJSON

func (a Aplicable) MarshalJSON() ([]byte, error)

func (Aplicable) String

func (a Aplicable) String() string

func (Aplicable) UnmarshalJSON

func (a Aplicable) UnmarshalJSON(b []byte) error

func (*Aplicable) UnmarshalText

func (a *Aplicable) UnmarshalText(text []byte) error

type Condition

type Condition struct {
	Formats      []string  `json:"formats,omitempty"`
	Interstitial Aplicable `json:"interstitial,omitempty"`
	Push         Aplicable `json:"push,omitempty"`
	// Objects restricts DSP Detect to an impression shape. Empty means any shape.
	// Tokens: banner, video, native, interstitial, none.
	Objects []string `json:"objects,omitempty"`
}

func (*Condition) Matches

func (c *Condition) Matches(format *types.Format, isIntr, isPush bool) bool

type Detection

type Detection struct {
	FormatCodes     []string
	Interstitial    bool
	Push            bool
	NoRequestObject bool
	Rule            *RuleItem
}

Detection is the inverted match: partner Ext → format codes and flags.

type MapResponse

type MapResponse struct {
	Assets []MapResponseAsset `json:"assets,omitempty"`
	// contains filtered or unexported fields
}

MapResponse defines how native response assets are mapped to content fields.

func (*MapResponse) HasAssets

func (mr *MapResponse) HasAssets() bool

HasAssets returns true if the MapResponse has any assets defined.

func (*MapResponse) Mapping

func (mr *MapResponse) Mapping(data map[string]any, fnk func(string, any) error) error

Mapping iterates over all assets, resolves each asset's Field path inside data using pre-split segments, and calls fnk with the asset and the resolved value (nil when the path does not exist or leads through a non-map node). Segment splitting is done once on the first call; subsequent calls are allocation-free for the path traversal itself. Iteration stops on the first non-nil error returned by fnk.

func (*MapResponse) Write

func (mr *MapResponse) Write(dst map[string]any, get func(string) any) error

Write is the inverse of Mapping: for each asset it calls get(name) and writes the value into dst at Field (slash-separated path). Nil values are skipped. Intermediate path nodes are created as nested maps.

type MapResponseAsset

type MapResponseAsset struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Field string `json:"field"`
	// contains filtered or unexported fields
}

MapResponseAsset maps an OpenRTB native asset ID to a named content field. Field supports nested paths separated by "/" (e.g. "images/main/url"). The parsed path segments are cached on first use to avoid repeated allocations.

type Meta

type Meta struct {
	Title       string               `json:"title,omitempty"`
	Description string               `json:"description,omitempty"`
	Version     string               `json:"version,omitempty"`
	ModifiedAt  time.Time            `json:"modified_at,omitempty"`
	Docs        []info.Documentation `json:"docs,omitempty"`
}

Meta holds descriptive metadata for an RTBRules set. Fields are informational and may be exposed via API.

type RTBRuler

type RTBRuler interface {
	IsFormatSupport(format *types.Format) bool
	IsInterstitialSupport(format *types.Format) bool
	IsPushSupport(format *types.Format) bool
	HasMappingRules() bool
	NoRequestObject(format *types.Format, isIntr, isPush bool) bool
	ApplyRules(format *types.Format, isIntr, isPush bool, fn func(rule *RuleItem) error) error
	AdjustImpression(target TargetImpression, imp *adtype.Impression, format *types.Format) error
	Detect(sig RequestSignal) *Detection
}

type RTBRules

type RTBRules struct {
	Meta                Meta        `json:"meta,omitempty"`
	Formats             []string    `json:"formats,omitempty"`
	InterstitialFormats []string    `json:"interstitial_formats,omitempty"`
	PushFormats         []string    `json:"push_formats,omitempty"`
	SSPRules            []*RuleItem `json:"ssp_rules,omitempty"`
	DSPRules            []*RuleItem `json:"dsp_rules,omitempty"`
}

RTBRules defines a set of rules for handling OpenRTB requests. Interstitial and push are considered supported when their respective format lists are explicitly non-empty.

func (*RTBRules) AdjustImpression

func (r *RTBRules) AdjustImpression(target TargetImpression, imp *adtype.Impression, format *types.Format) error

AdjustImpression applies the first matching rule's configuration to the target impression, if any rule matches the given format and impression type.

func (*RTBRules) ApplyRules

func (r *RTBRules) ApplyRules(format *types.Format, isIntr, isPush bool, fn func(rule *RuleItem) error) error

ApplyRules iterates over all rules, applying the provided function to each rule that matches the given format and impression type.

func (*RTBRules) Detect

func (r *RTBRules) Detect(sig RequestSignal) *Detection

Detect returns the first DSPRules entry whose Config.Ext is a subset of the incoming impression Ext and whose Objects, when set, match the impression shape. FormatCodes come from RuleItem.Formats. An empty Ext does not filter, so that rule matches any signal that passes the interstitial and object checks.

Interstitial Exclude + instl skips the rule. Push and Interstitial Include are outputs. reset "instl" forces Interstitial false after that calculation. No match returns nil.

func (*RTBRules) HasMappingRules

func (r *RTBRules) HasMappingRules() bool

HasMappingRules checks if there are any mapping rules defined in the RTBRules configuration.

func (*RTBRules) IsFormatSupport

func (r *RTBRules) IsFormatSupport(format *types.Format) bool

IsFormatSupport returns true when the format codename is listed in Formats. An empty Formats list or a "*" entry means no restriction — all formats are accepted.

func (*RTBRules) IsInterstitialSupport

func (r *RTBRules) IsInterstitialSupport(format *types.Format) bool

IsInterstitialSupport returns true when InterstitialFormats is non-empty and contains the given format codename.

func (*RTBRules) IsPushSupport

func (r *RTBRules) IsPushSupport(format *types.Format) bool

IsPushSupport returns true when PushFormats is non-empty and contains the given format codename.

func (*RTBRules) NoRequestObject

func (r *RTBRules) NoRequestObject(format *types.Format, isIntr, isPush bool) bool

NoRequestObject returns true if the first matching rule instructs the builder to omit the native request object from the bid request.

type RequestSignal

type RequestSignal struct {
	Ext                            map[string]any
	HasBanner, HasNative, HasVideo bool
	Instl                          bool
}

RequestSignal is the inbound OpenRTB impression shape used to invert format→Ext rules (DSP ingress).

type ResponseSpec

type ResponseSpec struct {
	Render string `json:"render,omitempty"`
}

ResponseSpec chooses how a matched DSP rule is written into the bid.

type RuleConfig

type RuleConfig struct {
	Ext             map[string]any `json:"ext,omitempty"`
	NoRequestObject bool           `json:"no_request_object,omitempty"`
}

RuleConfig holds extra parameters passed to the ad exchange for a matched rule.

type RuleItem

type RuleItem struct {
	Condition   Condition     `json:"condition"`
	Formats     []string      `json:"formats,omitempty"`
	Config      RuleConfig    `json:"config"`
	MapResponse *MapResponse  `json:"map_response,omitempty"`
	Response    *ResponseSpec `json:"response,omitempty"`
	// Reset names parameters cleared after the rule matches. Known token: "instl".
	Reset []string `json:"reset,omitempty"`
}

RuleItem represents a single rule in the RTBRules set, consisting of a condition, configuration, and optional response mapping. Formats is the DSP result: allowed ad format codes after condition matches. SSP matching still uses Condition.Formats.

type TargetImpression

type TargetImpression interface {
	SetExt(ext map[string]any)
}

Jump to

Keyboard shortcuts

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