forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbid.go
166 lines (142 loc) · 5.92 KB
/
bid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package openrtb_ext
import (
"encoding/json"
"fmt"
)
// ExtBid defines the contract for bidresponse.seatbid.bid[i].ext
type ExtBid struct {
Prebid *ExtBidPrebid `json:"prebid,omitempty"`
}
// ExtBidPrebid defines the contract for bidresponse.seatbid.bid[i].ext.prebid
// DealPriority represents priority of deal bid. If its non deal bid then value will be 0
// DealTierSatisfied true represents corresponding bid has satisfied the deal tier
type ExtBidPrebid struct {
Cache *ExtBidPrebidCache `json:"cache,omitempty"`
DealPriority int `json:"dealpriority,omitempty"`
DealTierSatisfied bool `json:"dealtiersatisfied,omitempty"`
Meta *ExtBidPrebidMeta `json:"meta,omitempty"`
Targeting map[string]string `json:"targeting,omitempty"`
Type BidType `json:"type"`
Video *ExtBidPrebidVideo `json:"video,omitempty"`
Events *ExtBidPrebidEvents `json:"events,omitempty"`
BidId string `json:"bidid,omitempty"`
}
// ExtBidPrebidCache defines the contract for bidresponse.seatbid.bid[i].ext.prebid.cache
type ExtBidPrebidCache struct {
Key string `json:"key"`
Url string `json:"url"`
Bids *ExtBidPrebidCacheBids `json:"bids,omitempty"`
}
type ExtBidPrebidCacheBids struct {
Url string `json:"url"`
CacheId string `json:"cacheId"`
}
// ExtBidPrebidMeta defines the contract for bidresponse.seatbid.bid[i].ext.prebid.meta
type ExtBidPrebidMeta struct {
AdvertiserDomains []string `json:"advertiserDomains,omitempty"`
AdvertiserID int `json:"advertiserId,omitempty"`
AdvertiserName string `json:"advertiserName,omitempty"`
AgencyID int `json:"agencyId,omitempty"`
AgencyName string `json:"agencyName,omitempty"`
BrandID int `json:"brandId,omitempty"`
BrandName string `json:"brandName,omitempty"`
DemandSource string `json:"demandSource,omitempty"`
DChain json.RawMessage `json:"dchain,omitempty"`
MediaType string `json:"mediaType,omitempty"`
NetworkID int `json:"networkId,omitempty"`
NetworkName string `json:"networkName,omitempty"`
PrimaryCategoryID string `json:"primaryCatId,omitempty"`
SecondaryCategoryIDs []string `json:"secondaryCatIds,omitempty"`
}
// ExtBidPrebidVideo defines the contract for bidresponse.seatbid.bid[i].ext.prebid.video
type ExtBidPrebidVideo struct {
Duration int `json:"duration"`
PrimaryCategory string `json:"primary_category"`
}
// ExtBidPrebidEvents defines the contract for bidresponse.seatbid.bid[i].ext.prebid.events
type ExtBidPrebidEvents struct {
Win string `json:"win,omitempty"`
Imp string `json:"imp,omitempty"`
}
// BidType describes the allowed values for bidresponse.seatbid.bid[i].ext.prebid.type
type BidType string
const (
BidTypeBanner BidType = "banner"
BidTypeVideo BidType = "video"
BidTypeAudio BidType = "audio"
BidTypeNative BidType = "native"
)
func BidTypes() []BidType {
return []BidType{
BidTypeBanner,
BidTypeVideo,
BidTypeAudio,
BidTypeNative,
}
}
func ParseBidType(bidType string) (BidType, error) {
switch bidType {
case "banner":
return BidTypeBanner, nil
case "video":
return BidTypeVideo, nil
case "audio":
return BidTypeAudio, nil
case "native":
return BidTypeNative, nil
default:
return "", fmt.Errorf("invalid BidType: %s", bidType)
}
}
// TargetingKeys are used throughout Prebid as keys which can be used in an ad server like DFP.
// Clients set the values we assign on the request to the ad server, where they can be substituted like macros into
// Creatives.
//
// Removing one of these, or changing the semantics of what we store there, will probably break the
// line item setups for many publishers.
//
// These are especially important to Prebid Mobile. It's much more cumbersome for a Mobile App to update code
// than it is for a website. As a result, they rely heavily on these targeting keys so that any changes can
// be made on Prebid Server and the Ad Server's line items.
type TargetingKey string
const (
HbpbConstantKey TargetingKey = "hb_pb"
// HbEnvKey exists to support the Prebid Universal Creative. If it exists, the only legal value is mobile-app.
// It will exist only if the incoming bidRequest defined request.app instead of request.site.
HbEnvKey TargetingKey = "hb_env"
// HbCacheHost and HbCachePath exist to supply cache host and path as targeting parameters
HbConstantCacheHostKey TargetingKey = "hb_cache_host"
HbConstantCachePathKey TargetingKey = "hb_cache_path"
// HbBidderConstantKey is the name of the Bidder. For example, "appnexus" or "rubicon".
HbBidderConstantKey TargetingKey = "hb_bidder"
HbSizeConstantKey TargetingKey = "hb_size"
HbDealIDConstantKey TargetingKey = "hb_deal"
// HbFormatKey is the format of the bid. For example, "video", "banner"
HbFormatKey TargetingKey = "hb_format"
// HbCacheKey and HbVastCacheKey store UUIDs which can be used to fetch things from prebid cache.
// Callers should *never* assume that either of these exist, since the call to the cache may always fail.
//
// HbVastCacheKey's UUID will fetch the entire bid JSON, while HbVastCacheKey will fetch just the VAST XML.
// HbVastCacheKey will only ever exist for Video bids.
HbCacheKey TargetingKey = "hb_cache_id"
HbVastCacheKey TargetingKey = "hb_uuid"
// This is not a key, but values used by the HbEnvKey
HbEnvKeyApp string = "mobile-app"
HbCategoryDurationKey TargetingKey = "hb_pb_cat_dur"
)
func (key TargetingKey) BidderKey(bidder BidderName, maxLength int) string {
s := string(key) + "_" + string(bidder)
if maxLength != 0 {
return s[:min(len(s), maxLength)]
}
return s
}
func min(x, y int) int {
if x < y {
return x
}
return y
}
const (
StoredRequestAttributes = "storedrequestattributes"
)