pbs

package
v0.0.0-...-1e4272c Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const COOKIE_NAME = "uids"
View Source
const DEFAULT_PRECISION = 2
View Source
const DEFAULT_TTL = 14 * 24 * time.Hour

DEFAULT_TTL is the default amount of time which a cookie is considered valid.

View Source
const MAX_BIDDERS = 8
View Source
const RECAPTCHA_URL = "https://www.google.com/recaptcha/api/siteverify"

Recaptcha code from https://github.com/haisum/recaptcha/blob/master/recaptcha.go

Variables

This section is empty.

Functions

func GetPriceBucketString

func GetPriceBucketString(cpm float64) map[string]string

func RoundUp

func RoundUp(input float64, places int) (newVal float64)

Types

type AdUnit

type AdUnit struct {
	Code       string           `json:"code"`
	TopFrame   int8             `json:"is_top_frame"`
	Sizes      []openrtb.Format `json:"sizes"`
	Bids       []Bids           `json:"bids"`
	ConfigID   string           `json:"config_id"`
	MediaTypes []string         `json:"media_types"`
	Instl      int8             `json:"instl"`
	Video      PBSVideo         `json:"video"`
}

type BidderDebug

type BidderDebug struct {
	RequestURI   string `json:"request_uri,omitempty"`
	RequestBody  string `json:"request_body,omitempty"`
	ResponseBody string `json:"response_body,omitempty"`
	StatusCode   int    `json:"status_code,omitempty"`
}

type Bids

type Bids struct {
	BidderCode string          `json:"bidder"`
	BidID      string          `json:"bid_id"`
	Params     json.RawMessage `json:"params"`
}

func ConfigGet

func ConfigGet(cache cache.Cache, id string) ([]Bids, error)

type ConfigCache

type ConfigCache interface {
	LoadConfig(string) ([]Bids, error)
}

type HostCookieSettings

type HostCookieSettings struct {
	Domain     string
	Family     string
	CookieName string
	OptOutURL  string
	OptInURL   string
}

type MediaType

type MediaType byte
const (
	MEDIA_TYPE_BANNER MediaType = iota
	MEDIA_TYPE_VIDEO
)

func ParseMediaType

func ParseMediaType(s string) (MediaType, error)

func ParseMediaTypes

func ParseMediaTypes(types []string) []MediaType

type PBSAdUnit

type PBSAdUnit struct {
	Sizes      []openrtb.Format
	TopFrame   int8
	Code       string
	BidID      string
	Params     json.RawMessage
	Video      PBSVideo
	MediaTypes []MediaType
	Instl      int8
}

type PBSBid

type PBSBid struct {
	// BidID identifies the Bid Request within the Ad Unit which this Bid targets. It should match one of
	// the values inside PBSRequest.AdUnits[i].Bids[j].BidID.
	BidID string `json:"bid_id"`
	// AdUnitCode identifies the AdUnit which this Bid targets.
	// It should match one of PBSRequest.AdUnits[i].Code, where "i" matches the AdUnit used in
	// as BidID.
	AdUnitCode string `json:"code"`
	// Creative_id uniquely identifies the creative being served. It is not used by prebid-server, but
	// it helps publishers and bidders identify and communicate about malicious or inappropriate ads.
	// This project simply passes it along with the bid.
	Creative_id string `json:"creative_id,omitempty"`
	// CreativeMediaType shows whether the creative is a video or banner.
	CreativeMediaType string `json:"media_type,omitempty"`
	// BidderCode is the PBSBidder.BidderCode of the PBSBidder who made this bid.
	BidderCode string `json:"bidder"`
	// BidHash is the hash of the bidder's unique bid identifier for blockchain. It should not be sent to browser.
	BidHash string `json:"-"`
	// Price is the cpm, in US Dollars, which the bidder is willing to pay if this bid is chosen.
	// TODO: Add support for other currencies someday.
	Price float64 `json:"price"`
	// NURL is a URL which returns ad markup, and should be called if the bid wins.
	// If NURL and Adm are both defined, then Adm takes precedence.
	NURL string `json:"nurl,omitempty"`
	// Adm is the ad markup which should be used to deliver the ad, if this bid is chosen.
	// If NURL and Adm are both defined, then Adm takes precedence.
	Adm string `json:"adm,omitempty"`
	// Width is the intended width which Adm should be shown, in pixels.
	Width uint64 `json:"width,omitempty"`
	// Height is the intended width which Adm should be shown, in pixels.
	Height uint64 `json:"height,omitempty"`
	// DealId is not used by prebid-server, but may be used by buyers and sellers who make special
	// deals with each other. We simply pass this information along with the bid.
	DealId string `json:"deal_id,omitempty"`
	// CacheId is an ID in prebid-cache which can be used to fetch this ad's content.
	// This supports prebid-mobile, which requires that the content be available from a URL.
	CacheID string `json:"cache_id,omitempty"`
	// ResponseTime is the number of milliseconds it took for the adapter to return a bid.
	ResponseTime      int               `json:"response_time_ms,omitempty"`
	AdServerTargeting map[string]string `json:"ad_server_targeting,omitempty"`
}

PBSBid is a bid from the auction. These are produced by Adapters, and target a particular Ad Unit.

This JSON format is a contract with both Prebid.js and Prebid-mobile. All changes *must* be backwards compatible, since clients cannot be forced to update their code.

type PBSBidSlice

type PBSBidSlice []*PBSBid

PBSBidSlice attaches the methods of sort.Interface to []PBSBid, ordering them by price. If two prices are equal, then the response time will be used as a tiebreaker. For more information, see https://golang.org/pkg/sort/#Interface

func (PBSBidSlice) Len

func (bids PBSBidSlice) Len() int

func (PBSBidSlice) Less

func (bids PBSBidSlice) Less(i, j int) bool

func (PBSBidSlice) Swap

func (bids PBSBidSlice) Swap(i, j int)

type PBSBidder

type PBSBidder struct {
	BidderCode   string         `json:"bidder"`
	AdUnitCode   string         `json:"ad_unit,omitempty"` // for index to dedup responses
	ResponseTime int            `json:"response_time_ms,omitempty"`
	NumBids      int            `json:"num_bids,omitempty"`
	Error        string         `json:"error,omitempty"`
	NoCookie     bool           `json:"no_cookie,omitempty"`
	NoBid        bool           `json:"no_bid,omitempty"`
	UsersyncInfo *UsersyncInfo  `json:"usersync,omitempty"`
	Debug        []*BidderDebug `json:"debug,omitempty"`

	AdUnits []PBSAdUnit `json:"-"`
}

func (*PBSBidder) LookupAdUnit

func (bidder *PBSBidder) LookupAdUnit(Code string) (unit *PBSAdUnit)

func (*PBSBidder) LookupBidID

func (bidder *PBSBidder) LookupBidID(Code string) string

type PBSCookie

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

PBSCookie is the cookie used in Prebid Server.

To get an instance of this from a request, use ParsePBSCookieFromRequest. To write an instance onto a response, use SetCookieOnResponse.

func NewPBSCookie

func NewPBSCookie() *PBSCookie

NewPBSCookie returns an empty PBSCookie

func ParsePBSCookie

func ParsePBSCookie(cookie *http.Cookie) *PBSCookie

ParsePBSCookie parses the UserSync cookie from a raw HTTP cookie.

func ParsePBSCookieFromRequest

func ParsePBSCookieFromRequest(r *http.Request) *PBSCookie

ParsePBSCookieFromRequest parses the UserSyncMap from an HTTP Request.

func (*PBSCookie) AllowSyncs

func (cookie *PBSCookie) AllowSyncs() bool

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

func (*PBSCookie) GetUID

func (cookie *PBSCookie) GetUID(familyName string) (string, bool, bool)

GetUID Gets this user's ID for the given family. The first returned value is the user's ID. The second returned value is true if we had a value stored, and false if we didn't. The third returned value is true if that value is "active", and false if it's expired.

If no value was stored, then the "isActive" return value will be false.

func (*PBSCookie) HasLiveSync

func (cookie *PBSCookie) HasLiveSync(familyName string) bool

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

func (*PBSCookie) LiveSyncCount

func (cookie *PBSCookie) LiveSyncCount() int

LiveSyncCount returns the number of families which have active UIDs for this user.

func (*PBSCookie) MarshalJSON

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

func (*PBSCookie) SetCookieOnResponse

func (cookie *PBSCookie) SetCookieOnResponse(w http.ResponseWriter, domain string)

SetCookieOnResponse is a shortcut for "ToHTTPCookie(); cookie.setDomain(domain); setCookie(w, cookie)"

func (*PBSCookie) SetPreference

func (cookie *PBSCookie) SetPreference(allow bool)

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

func (*PBSCookie) ToHTTPCookie

func (cookie *PBSCookie) ToHTTPCookie() *http.Cookie

Gets an HTTP cookie containing all the data from this UserSyncMap. This is a snapshot--not a live view.

func (*PBSCookie) TrySync

func (cookie *PBSCookie) TrySync(familyName string, uid string) error

TrySync tries to set the UID for some family name. It returns an error if the set didn't happen.

func (*PBSCookie) UnmarshalJSON

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

UnmarshalJSON holds some transition code.

"Legacy" cookies had UIDs *without* expiration dates, and recognized "0" as a legitimate UID for audienceNetwork. "Current" cookies always include UIDs with expiration dates, and never allow "0" for audienceNetwork.

This Unmarshal method interprets both data formats, and does some conversions on legacy data to make it current. If you're seeing this message after March 2018, it's safe to assume that all the legacy cookies have been updated and remove the legacy logic.

func (*PBSCookie) Unsync

func (cookie *PBSCookie) Unsync(familyName string)

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

type PBSRequest

type PBSRequest struct {
	AccountID     string          `json:"account_id"`
	Tid           string          `json:"tid"`
	CacheMarkup   int8            `json:"cache_markup"`
	SortBids      int8            `json:"sort_bids"`
	MaxKeyLength  int8            `json:"max_key_length"`
	Secure        int8            `json:"secure"`
	TimeoutMillis int64           `json:"timeout_millis"`
	AdUnits       []AdUnit        `json:"ad_units"`
	IsDebug       bool            `json:"is_debug"`
	App           *openrtb.App    `json:"app"`
	Device        *openrtb.Device `json:"device"`
	PBSUser       json.RawMessage `json:"user"`
	SDK           *SDK            `json:"sdk"`

	// internal
	Bidders []*PBSBidder  `json:"-"`
	User    *openrtb.User `json:"-"`
	Cookie  *PBSCookie    `json:"-"`
	Url     string        `json:"-"`
	Domain  string        `json:"-"`
	Start   time.Time
}

func ParsePBSRequest

func ParsePBSRequest(r *http.Request, cache cache.Cache, hostCookieSettings *HostCookieSettings) (*PBSRequest, error)

func (PBSRequest) Elapsed

func (req PBSRequest) Elapsed() int

func (PBSRequest) String

func (p PBSRequest) String() string

type PBSResponse

type PBSResponse struct {
	TID          string       `json:"tid,omitempty"`
	Status       string       `json:"status,omitempty"`
	BidderStatus []*PBSBidder `json:"bidder_status,omitempty"`
	Bids         PBSBidSlice  `json:"bids,omitempty"`
	BUrl         string       `json:"burl,omitempty"`
}

type PBSVideo

type PBSVideo struct {
	//Content MIME types supported. Popular MIME types may include “video/x-ms-wmv” for Windows Media and “video/x-flv” for Flash Video.
	Mimes []string `json:"mimes,omitempty"`

	//Minimum video ad duration in seconds.
	Minduration int64 `json:"minduration,omitempty"`

	// Maximum video ad duration in seconds.
	Maxduration int64 `json:"maxduration,omitempty"`

	//Indicates the start delay in seconds for pre-roll, mid-roll, or post-roll ad placements.
	Startdelay int64 `json:"startdelay,omitempty"`

	// Indicates if the player will allow the video to be skipped ( 0 = no, 1 = yes).
	Skippable int `json:"skippable,omitempty"`

	// Playback method code Description
	// 1 - Initiates on Page Load with Sound On
	// 2 - Initiates on Page Load with Sound Off by Default
	// 3 - Initiates on Click with Sound On
	// 4 - Initiates on Mouse-Over with Sound On
	// 5 - Initiates on Entering Viewport with Sound On
	// 6 - Initiates on Entering Viewport with Sound Off by Default
	PlaybackMethod int8 `json:"playback_method,omitempty"`

	//protocols as specified in ORTB 5.8
	// 1 VAST 1.0
	// 2 VAST 2.0
	// 3 VAST 3.0
	// 4 VAST 1.0 Wrapper
	// 5 VAST 2.0 Wrapper
	// 6 VAST 3.0 Wrapper
	// 7 VAST 4.0
	// 8 VAST 4.0 Wrapper
	// 9 DAAST 1.0
	// 10 DAAST 1.0 Wrapper
	Protocols []int8 `json:"protocols,omitempty"`
}

Structure for holding video-specific information

type SDK

type SDK struct {
	Version  string `json:"version"`
	Source   string `json:"source"`
	Platform string `json:"platform"`
}

type UserSyncDeps

type UserSyncDeps struct {
	ExternalUrl        string
	RecaptchaSecret    string
	OptOutUrl          string
	OptInUrl           string
	HostCookieSettings *HostCookieSettings
	Metrics            *pbsmetrics.Metrics
}

func (*UserSyncDeps) GetUIDs

func (deps *UserSyncDeps) GetUIDs(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*UserSyncDeps) OptOut

func (deps *UserSyncDeps) OptOut(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*UserSyncDeps) SetUID

func (deps *UserSyncDeps) SetUID(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*UserSyncDeps) VerifyRecaptcha

func (deps *UserSyncDeps) VerifyRecaptcha(response string) error

type UsersyncInfo

type UsersyncInfo struct {
	URL         string `json:"url,omitempty"`
	Type        string `json:"type,omitempty"`
	SupportCORS bool   `json:"supportCORS,omitempty"`
}

Jump to

Keyboard shortcuts

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