Skip to content

Commit c3578dd

Browse files
committed
Draft implmentation of an OpenRTB 2.1 request parser
0 parents  commit c3578dd

File tree

3 files changed

+706
-0
lines changed

3 files changed

+706
-0
lines changed

openrtb.go

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
package openrtb
2+
3+
const (
4+
VERSION = "2.1"
5+
6+
AD_POS_UNKNOWN = 0
7+
AD_POS_ABOVE_FOLD = 1
8+
AD_POS_BELOW_FOLD = 3
9+
AD_POS_HEADER = 4
10+
AD_POS_FOOTER = 5
11+
AD_POS_SIDEBAR = 6
12+
AD_POS_FULLSCREEN = 7
13+
14+
BANNER_TYPE_XHTML_TEXT = 1
15+
BANNER_TYPE_XHTML = 2
16+
BANNER_TYPE_JS = 3
17+
BANNER_TYPE_FRAME = 4
18+
19+
CONN_TYPE_UNKNOWN = 0
20+
CONN_TYPE_ETHERNET = 1
21+
CONN_TYPE_WIFI = 2
22+
CONN_TYPE_CELL = 3
23+
CONN_TYPE_CELL_2G = 4
24+
CONN_TYPE_CELL_3G = 5
25+
CONN_TYPE_CELL_4G = 6
26+
27+
LOCATION_TYPE_GPS = 1
28+
LOCATION_TYPE_IP = 2
29+
LOCATION_TYPE_USER = 3
30+
31+
DEVICE_TYPE_UNKNOWN = 0
32+
DEVICE_TYPE_MOBILE = 1
33+
DEVICE_TYPE_PC = 2
34+
DEVICE_TYPE_TV = 3
35+
36+
VIDEO_LINEARITY_LINEAR = 1
37+
VIDEO_LINEARITY_NON_LINEAR = 2
38+
39+
VIDEO_PLAYBACK_AUTO_SOUND_ON = 1
40+
VIDEO_PLAYBACK_AUTO_SOUND_OFF = 2
41+
VIDEO_PLAYBACK_CLICK_TO_PLAY = 3
42+
VIDEO_PLAYBACK_MOUSE_OVER = 4
43+
44+
VIDEO_START_DELAY_PRE_ROLL = 0
45+
VIDEO_START_DELAY_MID_ROLL = -1
46+
VIDEO_START_DELAY_POST_ROLL = -2
47+
48+
VIDEO_QUALITY_UNKNOWN = 0
49+
VIDEO_QUALITY_PROFESSIONAL = 1
50+
VIDEO_QUALITY_PROSUMER = 2
51+
VIDEO_QUALITY_UGC = 3
52+
)
53+
54+
// The top-level bid request object contains a globally unique bid request or auction ID. This "id"
55+
// attribute is required as is at least one "imp" (i.e., impression) object. Other attributes are
56+
// optional since an exchange may establish default values.
57+
type Request struct {
58+
Id *string // Unique ID of the bid request
59+
Imp []Impression
60+
Site *Site
61+
App *App
62+
Device *Device
63+
User *User
64+
At *int // Auction type, Default: 2 ("1": first price auction, "2": then second price auction)
65+
Tmax *int // Maximum amount of time in milliseconds to submit a bid
66+
Wseat []string // Array of buyer seats allowed to bid on this auction
67+
Allimps *int // Flag to indicate whether exchange can verify that all impressions offered represent all of the impressions available in context, Default: 0
68+
Cur []string // Array of allowed currencies
69+
Bcat []string // Blocked Advertiser Categories.
70+
Badv []string // Array of strings of blocked toplevel domains of advertisers
71+
Pmp *Pmp
72+
Ext Extensions
73+
}
74+
75+
// The "imp" object describes the ad position or impression being auctioned. A single bid request
76+
// can include multiple "imp" objects, a use case for which might be an exchange that supports
77+
// selling all ad positions on a given page as a bundle. Each "imp" object has a required ID so that
78+
// bids can reference them individually. An exchange can also conduct private auctions by
79+
// restricting involvement to specific subsets of seats within bidders.
80+
type Impression struct {
81+
Id *string // A unique identifier for this impression
82+
Banner *Banner
83+
Video *Video
84+
Displaymanager *string // Name of ad mediation partner, SDK technology, etc
85+
Displaymanagerver *string // Version of the above
86+
Instl *int // Interstitial, Default: 0 ("1": Interstitial, "0": Something else)
87+
Tagid *string // Identifier for specific ad placement or ad tag
88+
Bidfloor *float32 // Bid floor for this impression in CPM
89+
Bidfloorcur *string // Currency of bid floor
90+
Iframebuster []string // Array of names for supportediframe busters.
91+
Ext Extensions
92+
}
93+
94+
// The "banner" object must be included directly in the impression object if the impression offered
95+
// for auction is display or rich media, or it may be optionally embedded in the video object to
96+
// describe the companion banners available for the linear or non-linear video ad. The banner
97+
// object may include a unique identifier; this can be useful if these IDs can be leveraged in the
98+
// VAST response to dictate placement of the companion creatives when multiple companion ad
99+
// opportunities of the same size are available on a page.
100+
type Banner struct {
101+
W *int // Width
102+
H *int // Height
103+
Id *string // A unique identifier
104+
Pos *int // Ad Position
105+
Btype []int // Blocked creative types
106+
Battr []int // Blocked creative attributes
107+
Mimes []string // Whitelist of content MIME types supported
108+
Topframe *int // Default: 0 ("1": Delivered in top frame, "0": Elsewhere)
109+
Expdir []int // Specify properties for an expandable ad
110+
Api []int // List of supported API frameworks
111+
Ext Extensions
112+
}
113+
114+
// The "video" object must be included directly in the impression object if the impression offered
115+
// for auction is an in-stream video ad opportunity.
116+
type Video struct {
117+
Mimes []string // Content MIME types supported.
118+
Linearity *int // Indicates whether the ad impression is linear or non-linear
119+
Minduration *int // Minimum video ad duration in seconds
120+
Maxduration *int // Maximum video ad duration in seconds
121+
Protocol *int // Video bid response protocols
122+
W *int // Width of the player in pixels
123+
H *int // Height of the player in pixels
124+
Startdelay *int // Indicates the start delay in seconds
125+
Sequence *int // Default: 1
126+
Battr []int // Blocked creative attributes
127+
Maxextended *int // Maximum extended video ad duration
128+
Minbitrate *int // Minimum bit rate in Kbps
129+
Maxbitrate *int // Maximum bit rate in Kbps
130+
Boxingallowed *int // If exchange publisher has rules preventing letter boxing
131+
Playbackmethod []int // List of allowed playback methods
132+
Delivery []int // List of supported delivery methods
133+
Pos *int // Ad Position
134+
Companionad []Banner
135+
Api []int // List of supported API frameworks
136+
Companiontype []int
137+
Ext Extensions
138+
}
139+
140+
// A site object should be included if the ad supported content is part of a website (as opposed to
141+
// an application). A bid request must not contain both a site object and an app object.
142+
type Site struct {
143+
Id *string // Site ID on the exchange
144+
Name *string // Site name
145+
Domain *string
146+
Cat []string // Array of IAB content categories
147+
Sectioncat []string // Array of IAB content categories for subsection
148+
Pagecat []string // Array of IAB content categories for page
149+
Page *string // URL of the page
150+
Privacypolicy *int // Default: 1 ("1": site has a privacy policy)
151+
Ref *string // Referrer URL
152+
Search *string // Search string that caused naviation
153+
Publisher *Publisher
154+
// Content Content
155+
Keywords []string
156+
Ext Extensions
157+
}
158+
159+
// An "app" object should be included if the ad supported content is part of a mobile application
160+
// (as opposed to a mobile website). A bid request must not contain both an "app" object and a
161+
// "site" object.
162+
type App struct {
163+
Id *string // App ID on the exchange
164+
Name *string // App name
165+
Domain *string
166+
Cat []string // Array of IAB content categories
167+
Sectioncat []string // Array of IAB content categories for subsection
168+
Pagecat []string // Array of IAB content categories for page
169+
Ver *string // App version
170+
Bundle *string // App bundle or package name
171+
Privacypolicy *int // Default: 1 ("1": site has a privacy policy)
172+
Paid *int // "1": Paid, "2": Free
173+
Publisher *Publisher
174+
// Content Content
175+
Keywords []string
176+
Storeurl *string // App store URL for an installed app
177+
Ext Extensions
178+
}
179+
180+
// This object may be useful in the situation where syndicated content contains impressions and
181+
// does not necessarily match the publisher’s general content. The exchange might or might not
182+
// have knowledge of the page where the content is running, as a result of the syndication
183+
// method. (For example, video impressions embedded in an iframe on an unknown web property
184+
// or device.)
185+
// type Content struct {
186+
// }
187+
188+
// Abstract third-party
189+
type ThirdParty struct {
190+
Id *string
191+
Name *string
192+
Cat []string // Array of IAB content categories
193+
Domain *string
194+
Ext Extensions
195+
}
196+
197+
// The publisher object itself and all of its parameters are optional, so default values are not
198+
// provided. If an optional parameter is not specified, it should be considered unknown.
199+
type Publisher ThirdParty
200+
201+
// The producer is useful when content where the ad is shown is syndicated, and may appear on a
202+
// completely different publisher. The producer object itself and all of its parameters are optional,
203+
// so default values are not provided. If an optional parameter is not specified, it should be
204+
// considered unknown.
205+
type Producer ThirdParty
206+
207+
// The "device" object provides information pertaining to the device including its hardware,
208+
// platform, location, and carrier. This device can refer to a mobile handset, a desktop computer,
209+
// set top box or other digital device.
210+
type Device struct {
211+
Dnt *int // "1": Do not track
212+
Ua *string // User agent
213+
Ip *string // IPv4
214+
Geo *Geo
215+
Didsha1 *string // SHA1 hashed device ID
216+
Didmd5 *string // MD5 hashed device ID
217+
Dpidsha1 *string // SHA1 hashed platform device ID
218+
Dpidmd5 *string // MD5 hashed platform device ID
219+
Ipv6 *string // IPv6
220+
Carrier *string // Carrier or ISP derived from the IP address
221+
Language *string // Browser language
222+
Make *string // Device make
223+
Model *string // Device model
224+
Os *string // Device OS
225+
Osv *string // Device OS version
226+
Js *int // Javascript status ("0": Disabled, "1": Enabled)
227+
Connectiontype *int
228+
Devicetype *int
229+
Flashver *string // Flash version
230+
Ext map[string]string
231+
}
232+
233+
// Note that the Geo Object may appear in one or both the Device Object and the User Object.
234+
// This is intentional, since the information may be derived from either a device-oriented source
235+
// (such as IP geo lookup), or by user registration information (for example provided to a publisher
236+
// through a user registration).
237+
type Geo struct {
238+
Lat *float32 // Latitude from -90 to 90
239+
Lon *float32 // Longitude from -180 to 180
240+
Country *string // Country using ISO 3166-1 Alpha 3
241+
Region *string // Region using ISO 3166-2
242+
Regionfips104 *string // Region of a country using fips 10-4
243+
Metro *string
244+
City *string
245+
Zip *string
246+
Type *int // Indicate the source of the geo data
247+
Ext Extensions
248+
}
249+
250+
// The "user" object contains information known or derived about the human user of the device.
251+
// Note that the user ID is an exchange artifact (refer to the "device" object for hardware or
252+
// platform derived IDs) and may be subject to rotation policies. However, this user ID must be
253+
// stable long enough to serve reasonably as the basis for frequency capping.
254+
type User struct {
255+
Id *string // Unique consumer ID of this user on the exchange
256+
Buyeruid *string // Buyer's user ID
257+
Yob *int // Year-of-birth
258+
Gender *string // Gender ("M": male, "F" female, "O" Other)
259+
Keywords *string
260+
Customdata *string
261+
Geo *Geo
262+
Data []Data
263+
Ext Extensions
264+
}
265+
266+
// The data and segment objects together allow data about the user to be passed to bidders in the
267+
// bid request. This data may be from multiple sources (e.g., the exchange itself, third party
268+
// providers) as specified by the data object ID field. A bid request can mix data objects from
269+
// multiple providers.
270+
type Data struct {
271+
Id *string
272+
Name *string
273+
Segment []Segment
274+
Ext Extensions
275+
}
276+
277+
// The data and segment objects together allow data about the user to be passed to bidders in the
278+
// bid request. Segment objects convey specific units of information from the provider identified
279+
// in the parent data object.
280+
type Segment struct {
281+
Id *string
282+
Name *string
283+
Value *string
284+
Ext Extensions
285+
}
286+
287+
// Private Marketplace Object
288+
type Pmp struct {
289+
Private *int
290+
Deals []Deal
291+
Ext Extensions
292+
}
293+
294+
// Private Marketplace Deal
295+
type Deal struct {
296+
Id *string // Unique deal ID
297+
At *int // Auction type, Default: 2 ("1": first price auction, "2": then second price auction)
298+
Seats []string // List of seat IDs attached to this deal
299+
Type *int // Deal indicator ("1": Eplicit Deal, "2": Trading Agreement Deal)
300+
Bidfloor *float32
301+
Ext Extensions
302+
}
303+
304+
// General Extensions
305+
type Extensions map[string]string

0 commit comments

Comments
 (0)