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